diff --git a/uppsrc/Core/CoWork.cpp b/uppsrc/Core/CoWork.cpp index a832f9785..c6f5bf321 100644 --- a/uppsrc/Core/CoWork.cpp +++ b/uppsrc/Core/CoWork.cpp @@ -58,8 +58,7 @@ CoWork::Pool::~Pool() jobs[0].work = NULL; scheduled = 1; lock.Leave(); - for(int i = 0; i < threads.GetCount(); i++) - waitforjob.Release(); + waitforjob.Broadcast(); for(int i = 0; i < threads.GetCount(); i++) threads[i].Wait(); LLOG("Quit ended"); @@ -90,7 +89,7 @@ bool CoWork::Pool::DoJob() p.lock.Enter(); if(--work->todo == 0) { LLOG("Releasing waitforfinish of (CoWork " << FormatIntHex(work) << ")"); - work->waitforfinish.Release(); + work->waitforfinish.Signal(); } LLOG("DoJobA " << p.scheduled << ", todo: " << work->todo << " (CoWork " << FormatIntHex(work) << ")"); ASSERT(work->todo >= 0); @@ -107,11 +106,9 @@ void CoWork::Pool::ThreadRun(int tno) while(p.scheduled == 0) { LHITCOUNT("CoWork: Parking thread to Wait"); p.waiting_threads++; - p.lock.Leave(); LLOG("#" << tno << " Waiting for job"); - p.waitforjob.Wait(); + p.waitforjob.Wait(p.lock); LLOG("#" << tno << " Waiting ended"); - p.lock.Enter(); } LLOG("#" << tno << " Job acquired"); LHITCOUNT("CoWork: Running new job"); @@ -145,7 +142,7 @@ void CoWork::Do(Function&& fn) if(p.waiting_threads) { LLOG("Releasing thread waiting for job: " << p.waiting_threads); p.waiting_threads--; - p.waitforjob.Release(); + p.waitforjob.Signal(); } p.lock.Leave(); } @@ -191,10 +188,8 @@ void CoWork::Finish() { if(p.scheduled) Pool::DoJob(); else { - p.lock.Leave(); LLOG("WaitForFinish (CoWork " << FormatIntHex(this) << ")"); - waitforfinish.Wait(); - p.lock.Enter(); + waitforfinish.Wait(p.lock); } } p.lock.Leave(); diff --git a/uppsrc/Core/CoWork.h b/uppsrc/Core/CoWork.h index 5cb4d35ec..c199fdeeb 100644 --- a/uppsrc/Core/CoWork.h +++ b/uppsrc/Core/CoWork.h @@ -17,8 +17,8 @@ public: int waiting_threads; Array threads; - Mutex lock; - Semaphore waitforjob; + Mutex lock; + ConditionVariable waitforjob; Pool(int nthreads); ~Pool(); @@ -37,8 +37,8 @@ public: static thread_local bool is_worker; static thread_local Pool *pool; - Semaphore waitforfinish; - int todo; + ConditionVariable waitforfinish; + int todo; Mutex stepmutex; Array>> step; diff --git a/uppsrc/plugin/lz4/lz4.h b/uppsrc/plugin/lz4/lz4.h index c067c442e..190674583 100644 --- a/uppsrc/plugin/lz4/lz4.h +++ b/uppsrc/plugin/lz4/lz4.h @@ -24,6 +24,10 @@ class Lz4 { String header_data; String out; + + + bool co; + void TryHeader(); @@ -47,6 +51,8 @@ public: void Compress(); void Decompress(); + + void Co(bool b) { co = b; } bool IsError() const { return error; }