blob: d04815b070e8178e8b288ea9a6650f8887e6d59b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#ifndef ENGINE_SHARED_JOBS_H
#define ENGINE_SHARED_JOBS_H
typedef int (*JOBFUNC)(void *pData);
class CJobPool;
class CJob
{
friend class CJobPool;
CJobPool *m_pPool;
CJob *m_pPrev;
CJob *m_pNext;
volatile int m_Status;
volatile int m_Result;
JOBFUNC m_pfnFunc;
void *m_pFuncData;
public:
CJob()
{
m_Status = STATE_DONE;
m_pFuncData = 0;
}
enum
{
STATE_PENDING=0,
STATE_RUNNING,
STATE_DONE
};
int Status() const { return m_Status; }
};
class CJobPool
{
LOCK m_Lock;
CJob *m_pFirstJob;
CJob *m_pLastJob;
static void WorkerThread(void *pUser);
public:
CJobPool();
int Init(int NumThreads);
int Add(CJob *pJob, JOBFUNC pfnFunc, void *pData);
};
#endif
|