CoWork::FinLock

git-svn-id: svn://ultimatepp.org/upp/trunk@9386 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2016-01-09 19:15:41 +00:00
parent 519f78e79b
commit 514b3ea206
2 changed files with 19 additions and 3 deletions

View file

@ -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++];

View file

@ -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();