mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -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 LLOG(x) // DLOG(x)
|
||||||
#define LDUMP(x) // DDUMP(x)
|
#define LDUMP(x) // DDUMP(x)
|
||||||
|
|
||||||
#define LHITCOUNT(x) // RHITCOUNT(x)
|
#define LHITCOUNT(x) RHITCOUNT(x)
|
||||||
|
|
||||||
CoWork::Pool& CoWork::pool()
|
CoWork::Pool& CoWork::pool()
|
||||||
{
|
{
|
||||||
|
|
@ -37,6 +37,14 @@ CoWork::Pool::~Pool()
|
||||||
LLOG("Quit ended");
|
LLOG("Quit ended");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thread__ bool CoWork::Pool::finlock;
|
||||||
|
|
||||||
|
void CoWork::FinLock()
|
||||||
|
{
|
||||||
|
Pool::finlock = true;
|
||||||
|
pool().lock.Enter();
|
||||||
|
}
|
||||||
|
|
||||||
bool CoWork::Pool::DoJob()
|
bool CoWork::Pool::DoJob()
|
||||||
{
|
{
|
||||||
Pool& p = pool();
|
Pool& p = pool();
|
||||||
|
|
@ -45,6 +53,7 @@ bool CoWork::Pool::DoJob()
|
||||||
LLOG("Quit thread");
|
LLOG("Quit thread");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
finlock = false;
|
||||||
#ifdef CPP_11
|
#ifdef CPP_11
|
||||||
std::function<void ()> fn = std::move(job.fn);
|
std::function<void ()> fn = std::move(job.fn);
|
||||||
if(fn) {
|
if(fn) {
|
||||||
|
|
@ -60,6 +69,7 @@ bool CoWork::Pool::DoJob()
|
||||||
p.lock.Leave();
|
p.lock.Leave();
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
if(!finlock)
|
||||||
p.lock.Enter();
|
p.lock.Enter();
|
||||||
if(--job.work->todo == 0) {
|
if(--job.work->todo == 0) {
|
||||||
LLOG("Releasing waitforfinish of (CoWork " << FormatIntHex(job.work) << ")");
|
LLOG("Releasing waitforfinish of (CoWork " << FormatIntHex(job.work) << ")");
|
||||||
|
|
@ -114,6 +124,8 @@ void CoWork::Do(const Callback *cb, void *)
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
(*cb)();
|
(*cb)();
|
||||||
|
if(Pool::finlock)
|
||||||
|
p.lock.Leave();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MJob& job = p.jobs[p.scheduled++];
|
MJob& job = p.jobs[p.scheduled++];
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,14 @@ class CoWork : NoCopy {
|
||||||
int waiting_threads;
|
int waiting_threads;
|
||||||
Array<Thread> threads;
|
Array<Thread> threads;
|
||||||
|
|
||||||
CriticalSection lock;
|
Mutex lock;
|
||||||
Semaphore waitforjob;
|
Semaphore waitforjob;
|
||||||
|
|
||||||
Pool();
|
Pool();
|
||||||
~Pool();
|
~Pool();
|
||||||
|
|
||||||
|
static thread__ bool finlock;
|
||||||
|
|
||||||
static bool DoJob();
|
static bool DoJob();
|
||||||
static void ThreadRun(int tno);
|
static void ThreadRun(int tno);
|
||||||
};
|
};
|
||||||
|
|
@ -53,6 +55,8 @@ public:
|
||||||
CoWork& operator&(const std::function<void ()>& lambda) { Do(NULL, &lambda); return *this; }
|
CoWork& operator&(const std::function<void ()>& lambda) { Do(NULL, &lambda); return *this; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void FinLock();
|
||||||
|
|
||||||
void Finish();
|
void Finish();
|
||||||
|
|
||||||
bool IsFinished();
|
bool IsFinished();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue