mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-07 10:34:54 -06:00
Core: CoWork now using ConditionVariable instead of semaphore
git-svn-id: svn://ultimatepp.org/upp/trunk@10062 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
af54f87cf3
commit
873f05e966
3 changed files with 15 additions and 14 deletions
|
|
@ -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<void ()>&& 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();
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ public:
|
|||
int waiting_threads;
|
||||
Array<Thread> 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<BiVector<Function<void ()>>> step;
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue