diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 76f02fb683..9651aaafbd 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -407,6 +407,8 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager) OMW::Engine::~Engine() { + mWorkQueue->stop(); + mEnvironment.cleanup(); delete mScriptContext; diff --git a/components/sceneutil/workqueue.cpp b/components/sceneutil/workqueue.cpp index 3f8ed8aaf2..3c1df80ac4 100644 --- a/components/sceneutil/workqueue.cpp +++ b/components/sceneutil/workqueue.cpp @@ -33,14 +33,25 @@ bool WorkItem::isDone() const return mDone; } -WorkQueue::WorkQueue(int workerThreads) +WorkQueue::WorkQueue(std::size_t workerThreads) : mIsReleased(false) { - for (int i=0; i(*this)); + start(workerThreads); } WorkQueue::~WorkQueue() +{ + stop(); +} + +void WorkQueue::start(std::size_t workerThreads) +{ + while (mThreads.size() < workerThreads) + mThreads.emplace_back(std::make_unique(*this)); + mIsReleased = false; +} + +void WorkQueue::stop() { { std::unique_lock lock(mMutex); diff --git a/components/sceneutil/workqueue.hpp b/components/sceneutil/workqueue.hpp index 5b51c59e59..6eb6a36a3e 100644 --- a/components/sceneutil/workqueue.hpp +++ b/components/sceneutil/workqueue.hpp @@ -44,9 +44,13 @@ namespace SceneUtil class WorkQueue : public osg::Referenced { public: - WorkQueue(int numWorkerThreads=1); + WorkQueue(std::size_t workerThreads); ~WorkQueue(); + void start(std::size_t workerThreads); + + void stop(); + /// Add a new work item to the back of the queue. /// @par The work item's waitTillDone() method may be used by the caller to wait until the work is complete. /// @param front If true, add item to the front of the queue. If false (default), add to the back.