From 00a2b42080e57508fb2639d40328174eb93eeafa Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 15 May 2016 15:19:52 -0400 Subject: [PATCH] Made thread-safe. --- Outputs/CRT/Internals/Shaders/Shader.cpp | 4 ++++ Outputs/CRT/Internals/Shaders/Shader.hpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Outputs/CRT/Internals/Shaders/Shader.cpp b/Outputs/CRT/Internals/Shaders/Shader.cpp index f4968b752..f0e2fbb26 100644 --- a/Outputs/CRT/Internals/Shaders/Shader.cpp +++ b/Outputs/CRT/Internals/Shaders/Shader.cpp @@ -291,14 +291,18 @@ void Shader::set_uniform_matrix(const std::string &name, GLint size, GLsizei cou void Shader::enqueue_function(std::function function) { + _function_mutex.lock(); _enqueued_functions.push_back(function); + _function_mutex.unlock(); } void Shader::flush_functions() { + _function_mutex.lock(); for(std::function function : _enqueued_functions) { function(); } _enqueued_functions.clear(); + _function_mutex.unlock(); } diff --git a/Outputs/CRT/Internals/Shaders/Shader.hpp b/Outputs/CRT/Internals/Shaders/Shader.hpp index ead7ce397..b28335032 100644 --- a/Outputs/CRT/Internals/Shaders/Shader.hpp +++ b/Outputs/CRT/Internals/Shaders/Shader.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace OpenGL { @@ -110,6 +111,7 @@ private: void flush_functions(); std::list> _enqueued_functions; + std::mutex _function_mutex; protected: void enqueue_function(std::function function);