LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
TaskPool.h
1 #ifndef RHESUS_TASK_POOL_H_
2 #define RHESUS_TASK_POOL_H_
3 
4 #include <queue>
5 #include <vector>
6 
7 #include <Task.h> // TaskPool does not use ManagedTasks to make cleanup easier
8 #include "Mutex.h"
9 #include "CountingSemaphore.h"
10 
11 namespace Rhesus {
12 namespace Toolkit {
13 namespace Tasks {
19 class TaskPool {
20 public:
21  static void Start();
22  static void Start(INT32 numThreads);
23 
24  static void EnqueueTask(FUNCPTR ptr, UINT32 arg0 = 0, UINT32 arg1 = 0,
25  UINT32 arg2 = 0, UINT32 arg3 = 0, UINT32 arg4 = 0, UINT32 arg5 = 0,
26  UINT32 arg6 = 0, UINT32 arg7 = 0, UINT32 arg8 = 0);
27 
28  static void Stop();
29 
30 private:
31  struct taskStructure {
32 
33  FUNCPTR ptr;
34  UINT32 arg0;
35  UINT32 arg1;
36  UINT32 arg2;
37  UINT32 arg3;
38  UINT32 arg4;
39  UINT32 arg5;
40  UINT32 arg6;
41  UINT32 arg7;
42  UINT32 arg8;
43  };
44 
45  static INT32 WorkerTask();
46  static INT32 WorkerTemp(taskStructure* t, Task* thisTask);
47 
48  static std::queue<taskStructure> s_taskQ;
49  static Mutex s_taskQSyncObj;
50  static CountingSemaphore s_taskSignal;
51  static std::vector<Task*> s_tasks;
52  static std::vector<Task*> s_tempTasks;
53  static CountingSemaphore s_availableTasks;
54 };
55 
56 }
57 }
58 }
59 
60 #endif