mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 06:05:58 -06:00
CoWork::FinLock
git-svn-id: svn://ultimatepp.org/upp/trunk@9386 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
519f78e79b
commit
514b3ea206
2 changed files with 19 additions and 3 deletions
|
|
@ -7,7 +7,7 @@ NAMESPACE_UPP
|
|||
#define LLOG(x) // DLOG(x)
|
||||
#define LDUMP(x) // DDUMP(x)
|
||||
|
||||
#define LHITCOUNT(x) // RHITCOUNT(x)
|
||||
#define LHITCOUNT(x) RHITCOUNT(x)
|
||||
|
||||
CoWork::Pool& CoWork::pool()
|
||||
{
|
||||
|
|
@ -37,6 +37,14 @@ CoWork::Pool::~Pool()
|
|||
LLOG("Quit ended");
|
||||
}
|
||||
|
||||
thread__ bool CoWork::Pool::finlock;
|
||||
|
||||
void CoWork::FinLock()
|
||||
{
|
||||
Pool::finlock = true;
|
||||
pool().lock.Enter();
|
||||
}
|
||||
|
||||
bool CoWork::Pool::DoJob()
|
||||
{
|
||||
Pool& p = pool();
|
||||
|
|
@ -45,6 +53,7 @@ bool CoWork::Pool::DoJob()
|
|||
LLOG("Quit thread");
|
||||
return true;
|
||||
}
|
||||
finlock = false;
|
||||
#ifdef CPP_11
|
||||
std::function<void ()> fn = std::move(job.fn);
|
||||
if(fn) {
|
||||
|
|
@ -60,7 +69,8 @@ bool CoWork::Pool::DoJob()
|
|||
p.lock.Leave();
|
||||
cb();
|
||||
}
|
||||
p.lock.Enter();
|
||||
if(!finlock)
|
||||
p.lock.Enter();
|
||||
if(--job.work->todo == 0) {
|
||||
LLOG("Releasing waitforfinish of (CoWork " << FormatIntHex(job.work) << ")");
|
||||
job.work->waitforfinish.Release();
|
||||
|
|
@ -114,6 +124,8 @@ void CoWork::Do(const Callback *cb, void *)
|
|||
else
|
||||
#endif
|
||||
(*cb)();
|
||||
if(Pool::finlock)
|
||||
p.lock.Leave();
|
||||
return;
|
||||
}
|
||||
MJob& job = p.jobs[p.scheduled++];
|
||||
|
|
|
|||
|
|
@ -19,11 +19,13 @@ class CoWork : NoCopy {
|
|||
int waiting_threads;
|
||||
Array<Thread> threads;
|
||||
|
||||
CriticalSection lock;
|
||||
Mutex lock;
|
||||
Semaphore waitforjob;
|
||||
|
||||
Pool();
|
||||
~Pool();
|
||||
|
||||
static thread__ bool finlock;
|
||||
|
||||
static bool DoJob();
|
||||
static void ThreadRun(int tno);
|
||||
|
|
@ -53,6 +55,8 @@ public:
|
|||
CoWork& operator&(const std::function<void ()>& lambda) { Do(NULL, &lambda); return *this; }
|
||||
#endif
|
||||
|
||||
static void FinLock();
|
||||
|
||||
void Finish();
|
||||
|
||||
bool IsFinished();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue