Loading libs/renderengine/threaded/RenderEngineThreaded.cpp +19 −11 Original line number Diff line number Diff line Loading @@ -48,11 +48,8 @@ RenderEngineThreaded::RenderEngineThreaded(CreateInstanceFactory factory, Render } RenderEngineThreaded::~RenderEngineThreaded() { { std::lock_guard lock(mThreadMutex); mRunning = false; mCondition.notify_one(); } if (mThread.joinable()) { mThread.join(); Loading @@ -71,21 +68,32 @@ void RenderEngineThreaded::threadMain(CreateInstanceFactory factory) NO_THREAD_S mRenderEngine = factory(); std::unique_lock<std::mutex> lock(mThreadMutex); pthread_setname_np(pthread_self(), mThreadName); { std::unique_lock<std::mutex> lock(mInitializedMutex); std::scoped_lock lock(mInitializedMutex); mIsInitialized = true; } mInitializedCondition.notify_all(); while (mRunning) { const auto getNextTask = [this]() -> std::optional<Work> { std::scoped_lock lock(mThreadMutex); if (!mFunctionCalls.empty()) { auto task = mFunctionCalls.front(); Work task = mFunctionCalls.front(); mFunctionCalls.pop(); task(*mRenderEngine); return std::make_optional<Work>(task); } return std::nullopt; }; const auto task = getNextTask(); if (task) { (*task)(*mRenderEngine); } std::unique_lock<std::mutex> lock(mThreadMutex); mCondition.wait(lock, [this]() REQUIRES(mThreadMutex) { return !mRunning || !mFunctionCalls.empty(); }); Loading libs/renderengine/threaded/RenderEngineThreaded.h +4 −3 Original line number Diff line number Diff line Loading @@ -82,9 +82,10 @@ private: // Protects the creation and destruction of mThread. mutable std::mutex mThreadMutex; std::thread mThread GUARDED_BY(mThreadMutex); bool mRunning GUARDED_BY(mThreadMutex) = true; mutable std::queue<std::function<void(renderengine::RenderEngine& instance)>> mFunctionCalls GUARDED_BY(mThreadMutex); std::atomic<bool> mRunning = true; using Work = std::function<void(renderengine::RenderEngine&)>; mutable std::queue<Work> mFunctionCalls GUARDED_BY(mThreadMutex); mutable std::condition_variable mCondition; // Used to allow select thread safe methods to be accessed without requiring the Loading Loading
libs/renderengine/threaded/RenderEngineThreaded.cpp +19 −11 Original line number Diff line number Diff line Loading @@ -48,11 +48,8 @@ RenderEngineThreaded::RenderEngineThreaded(CreateInstanceFactory factory, Render } RenderEngineThreaded::~RenderEngineThreaded() { { std::lock_guard lock(mThreadMutex); mRunning = false; mCondition.notify_one(); } if (mThread.joinable()) { mThread.join(); Loading @@ -71,21 +68,32 @@ void RenderEngineThreaded::threadMain(CreateInstanceFactory factory) NO_THREAD_S mRenderEngine = factory(); std::unique_lock<std::mutex> lock(mThreadMutex); pthread_setname_np(pthread_self(), mThreadName); { std::unique_lock<std::mutex> lock(mInitializedMutex); std::scoped_lock lock(mInitializedMutex); mIsInitialized = true; } mInitializedCondition.notify_all(); while (mRunning) { const auto getNextTask = [this]() -> std::optional<Work> { std::scoped_lock lock(mThreadMutex); if (!mFunctionCalls.empty()) { auto task = mFunctionCalls.front(); Work task = mFunctionCalls.front(); mFunctionCalls.pop(); task(*mRenderEngine); return std::make_optional<Work>(task); } return std::nullopt; }; const auto task = getNextTask(); if (task) { (*task)(*mRenderEngine); } std::unique_lock<std::mutex> lock(mThreadMutex); mCondition.wait(lock, [this]() REQUIRES(mThreadMutex) { return !mRunning || !mFunctionCalls.empty(); }); Loading
libs/renderengine/threaded/RenderEngineThreaded.h +4 −3 Original line number Diff line number Diff line Loading @@ -82,9 +82,10 @@ private: // Protects the creation and destruction of mThread. mutable std::mutex mThreadMutex; std::thread mThread GUARDED_BY(mThreadMutex); bool mRunning GUARDED_BY(mThreadMutex) = true; mutable std::queue<std::function<void(renderengine::RenderEngine& instance)>> mFunctionCalls GUARDED_BY(mThreadMutex); std::atomic<bool> mRunning = true; using Work = std::function<void(renderengine::RenderEngine&)>; mutable std::queue<Work> mFunctionCalls GUARDED_BY(mThreadMutex); mutable std::condition_variable mCondition; // Used to allow select thread safe methods to be accessed without requiring the Loading