ddnet/src/engine/shared/jobs.h

55 lines
923 B
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#ifndef ENGINE_SHARED_JOBS_H
#define ENGINE_SHARED_JOBS_H
typedef int (*JOBFUNC)(void *pData);
class CJobPool;
class CJob
{
friend class CJobPool;
2010-05-29 07:25:38 +00:00
CJobPool *m_pPool;
CJob *m_pPrev;
CJob *m_pNext;
2010-05-29 07:25:38 +00:00
volatile int m_Status;
volatile int m_Result;
2010-05-29 07:25:38 +00:00
JOBFUNC m_pfnFunc;
void *m_pFuncData;
public:
CJob()
{
m_Status = STATE_DONE;
m_pFuncData = 0;
}
2010-05-29 07:25:38 +00:00
enum
{
STATE_PENDING=0,
STATE_RUNNING,
STATE_DONE
};
2010-05-29 07:25:38 +00:00
int Status() const { return m_Status; }
int Result() const {return m_Result; }
2010-05-29 07:25:38 +00:00
};
class CJobPool
{
LOCK m_Lock;
CJob *m_pFirstJob;
CJob *m_pLastJob;
2010-05-29 07:25:38 +00:00
static void WorkerThread(void *pUser);
2010-05-29 07:25:38 +00:00
public:
CJobPool();
2010-05-29 07:25:38 +00:00
int Init(int NumThreads);
int Add(CJob *pJob, JOBFUNC pfnFunc, void *pData);
};
#endif