about summary refs log tree commit diff
path: root/src/engine/shared/jobs.h
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2010-05-29 07:25:38 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2010-05-29 07:25:38 +0000
commit72c06a258940696093f255fb1061beb58e1cdd0b (patch)
tree36b9a7712eec2d4f07837eab9c38ef1c5af85319 /src/engine/shared/jobs.h
parente56feb597bc743677633432f77513b02907fd169 (diff)
downloadzcatch-72c06a258940696093f255fb1061beb58e1cdd0b.tar.gz
zcatch-72c06a258940696093f255fb1061beb58e1cdd0b.zip
copied refactor to trunk
Diffstat (limited to 'src/engine/shared/jobs.h')
-rw-r--r--src/engine/shared/jobs.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/engine/shared/jobs.h b/src/engine/shared/jobs.h
new file mode 100644
index 00000000..d04815b0
--- /dev/null
+++ b/src/engine/shared/jobs.h
@@ -0,0 +1,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