LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
ManagedTask.h
1 #ifndef RHESUS_MANAGED_TASK_H_
2 #define RHESUS_MANAGED_TASK_H_
3 
4 #include <queue>
5 #include <string>
6 
7 #include <Task.h>
8 
9 #include "Mutex.h"
10 
11 namespace Rhesus
12 {
13 namespace Toolkit
14 {
15 namespace Tasks
16 {
17  class ManagedTask
18  {
19  public:
20  static void Finalize();
21 
22  ManagedTask(std::string name, FUNCPTR funptr);
23  ManagedTask(std::string name, FUNCPTR funptr, INT32 priority, UINT32 stackSize);
24  ~ManagedTask();
25 
26  bool Start(UINT32 arg0 = 0, UINT32 arg1 = 0, UINT32 arg2 = 0, UINT32 arg3 = 0, UINT32 arg4 = 0,
27  UINT32 arg5 = 0, UINT32 arg6 = 0, UINT32 arg7 = 0, UINT32 arg8 = 0);
28 
29  bool Stop();
30 
31  private:
32  static const int kInvalidTask;
33  static const int kMaxManagedTasks;
34  static bool s_isQueueInitialized;
35  static std::queue<int> s_availableIDs;
36  static Mutex s_idSync;
37  static ManagedTask** s_managedTasks;
38 
39  static INT32 releaseTask(ManagedTask* instance);
40  static INT32 registerTask(ManagedTask* instance); // ownership of task instance transferred to manager
41 
42  void intern_ctor(std::string name, FUNCPTR funptr, INT32 priority, UINT32 stackSize);
43 
44  static INT32 intern_func_wrapper(UINT32 arg0, UINT32 arg1, UINT32 arg2, UINT32 arg3, UINT32 arg4,
45  UINT32 arg5, UINT32 arg6, UINT32 arg7, UINT32 arg8, UINT32 arg9)
46  {
47  ManagedTask* inst = reinterpret_cast<ManagedTask*>(arg0);
48 
49  INT32 ret = inst->m_func(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
50 
51  return ret;
52  }
53 
54  void setIdentifier(int id);
55 
56  int m_identifier;
57  FUNCPTR m_func;
58  Task* m_task;
59 
60  ManagedTask(ManagedTask& copy)
61  {
62  m_task = copy.m_task;
63  copy.m_task = NULL;
64  m_identifier = copy.m_identifier;
65  copy.m_identifier = kInvalidTask;
66  }
67 
68  ManagedTask& operator=(const ManagedTask& a)
69  {
70  ManagedTask& cpy = const_cast<ManagedTask&>(a);
71 
72  m_task = cpy.m_task;
73  cpy.m_task = NULL;
74 
75  m_identifier = cpy.m_identifier;
76  cpy.m_identifier = kInvalidTask;
77 
78  return *this;
79  }
80  };
81 }
82 }
83 }
84 
85 #endif