ultimatepp/uppdev/CoreTopics/CoWork.h
cxl 3cd394812c Merge continued
git-svn-id: svn://ultimatepp.org/upp/trunk@10263 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2016-10-04 08:34:39 +00:00

54 lines
886 B
C++

#ifdef _MULTITHREADED
class CoWork : NoCopy {
typedef StaticCriticalSection Lock;
struct MJob : Moveable<MJob> {
Callback cb;
CoWork *work;
};
struct Pool {
Vector<MJob> jobs;
int waiting_threads;
Array<Thread> threads;
CriticalSection lock;
Semaphore waitforjob;
Pool();
~Pool();
static bool DoJob();
static void ThreadRun(int tno);
};
friend struct Pool;
static Pool& pool();
Semaphore waitforfinish;
int todo;
public:
void Do(Callback cb);
CoWork& operator&(Callback cb) { Do(cb); return *this; }
void Finish();
CoWork();
~CoWork();
static void Quit();
};
#else
class CoWork : NoCopy {
public:
void Do(Callback cb) { cb(); }
CoWork& operator&(Callback cb) { cb(); return *this; }
void Finish() {}
};
#endif