ultimatepp/uppsrc/Core/CoWork.h
cxl ec99680986 Draw, CtrlCore: Resolved MT issues
git-svn-id: svn://ultimatepp.org/upp/trunk@5551 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2012-11-15 20:50:44 +00:00

55 lines
882 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();
bool IsFinished();
CoWork();
~CoWork();
};
#else
class CoWork : NoCopy {
public:
void Do(Callback cb) { cb(); }
CoWork& operator&(Callback cb) { cb(); return *this; }
void Finish() {}
bool IsFinished() { return true; }
};
#endif