diff --git a/src/engine/workPool.cpp b/src/engine/workPool.cpp index 8c187adc6..b3610f74c 100644 --- a/src/engine/workPool.cpp +++ b/src/engine/workPool.cpp @@ -21,6 +21,8 @@ #include "../ta-log.h" #include +#include + void* _workThread(void* inst) { ((DivWorkThread*)inst)->run(); return NULL; @@ -29,6 +31,7 @@ void* _workThread(void* inst) { void DivWorkThread::run() { std::unique_lock unique(selfLock); DivPendingTask task; + bool setFuckingPromise=false; logV("running work thread"); @@ -37,7 +40,10 @@ void DivWorkThread::run() { if (tasks.empty()) { lock.unlock(); isBusy=false; - parent->notify.notify_one(); + if (setFuckingPromise) { + parent->notify.set_value(); + setFuckingPromise=false; + } if (terminate) { break; } @@ -50,10 +56,13 @@ void DivWorkThread::run() { task.func(task.funcArg); - if (--parent->busyCount<0) { + int busyCount=--parent->busyCount; + if (busyCount<0) { logE("oh no PROBLEM..."); } - parent->notify.notify_one(); + if (busyCount==0) { + setFuckingPromise=true; + } } } } @@ -119,7 +128,14 @@ bool DivWorkPool::busy() { void DivWorkPool::wait() { if (!threaded) return; - std::unique_lock unique(selfLock); + //std::unique_lock unique(selfLock); + + if (busyCount==0) { + logV("nothing to do"); + return; + } + + std::future future=notify.get_future(); // start running for (unsigned int i=0; i0) { - if (notify.wait_for(unique,std::chrono::milliseconds(30))==std::cv_status::timeout) { - logW("DivWorkPool: wait() timed out!"); - } - } + logV("waiting on future"); + //SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,"Error","waiting on future.",NULL); + future.wait(); + //SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,"Error","waited - reset promise.",NULL); + + notify=std::promise(); + //SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,"Error","YES",NULL); pos=0; } diff --git a/src/engine/workPool.h b/src/engine/workPool.h index f47711353..aab8a1ea2 100644 --- a/src/engine/workPool.h +++ b/src/engine/workPool.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "fixedQueue.h" @@ -75,7 +76,7 @@ class DivWorkPool { unsigned int pos; DivWorkThread* workThreads; public: - std::condition_variable notify; + std::promise notify; std::atomic busyCount; /** @@ -98,4 +99,4 @@ class DivWorkPool { ~DivWorkPool(); }; -#endif \ No newline at end of file +#endif