Browse Source

cmTaskMgr.h : Initial working version.

master
kpl 11 years ago
parent
commit
9b9b49bf3c
1 changed files with 28 additions and 9 deletions
  1. 28
    9
      cmTaskMgr.h

+ 28
- 9
cmTaskMgr.h View File

12
     kInvalidArgTmRC,
12
     kInvalidArgTmRC,
13
     kOpFailTmRC,
13
     kOpFailTmRC,
14
     kQueueFailTmRC,
14
     kQueueFailTmRC,
15
+    kAssertFailTmRC,
15
     kTestFailTmRC
16
     kTestFailTmRC
16
   };
17
   };
17
 
18
 
25
   {
26
   {
26
     kInvalidTmId,
27
     kInvalidTmId,
27
     kQueuedTmId,       // The task is waiting in the queue.
28
     kQueuedTmId,       // The task is waiting in the queue.
28
-    kQueuedPausedTmId, // The task is waiting in the queue but is deferred.
29
     kStartedTmId,      // The task is running.
29
     kStartedTmId,      // The task is running.
30
+    kPausedTmId,       // The task is paused.
30
     kCompletedTmId,    // The task successfully completed.
31
     kCompletedTmId,    // The task successfully completed.
31
     kKilledTmId        // The task was killed by the client.
32
     kKilledTmId        // The task was killed by the client.
32
   } cmStatusTmId_t;
33
   } cmStatusTmId_t;
40
 
41
 
41
   typedef enum 
42
   typedef enum 
42
   { 
43
   { 
44
+    kNoneTmId,
43
     kStartTmId, 
45
     kStartTmId, 
44
     kPauseTmId, 
46
     kPauseTmId, 
45
     kKillTmId 
47
     kKillTmId 
62
 
64
 
63
   typedef struct cmTaskMgrFuncArg_str
65
   typedef struct cmTaskMgrFuncArg_str
64
   {
66
   {
67
+    void*               reserved; 
65
     void*               arg;           // 'funcArg' provided by cmTaskMgrCall();
68
     void*               arg;           // 'funcArg' provided by cmTaskMgrCall();
66
     unsigned            argByteCnt;    // 'funcArgByteCnt' provided by cmTaskMgrCall()
69
     unsigned            argByteCnt;    // 'funcArgByteCnt' provided by cmTaskMgrCall()
67
     unsigned            instId;        // Task instance id.
70
     unsigned            instId;        // Task instance id.
68
     cmTaskMgrStatusCb_t statusCb;      // Status update function provided by cmTaskMgrCreate().
71
     cmTaskMgrStatusCb_t statusCb;      // Status update function provided by cmTaskMgrCreate().
69
     void*               statusCbArg;   // Status update function arg. provided by cmTaskMgrCreate().
72
     void*               statusCbArg;   // Status update function arg. provided by cmTaskMgrCreate().
70
     unsigned            progCnt;       // Maximum expected value of cmTaskMgrStatusArg_t.prog during execution of this task instance.
73
     unsigned            progCnt;       // Maximum expected value of cmTaskMgrStatusArg_t.prog during execution of this task instance.
71
-    cmTaskMgrCtlId_t*   cmdIdPtr;      // Command id used to inform the running task that it should pause or exit.
72
     unsigned            pauseSleepMs;  // Length of time to sleep if the task receives a pause command.
74
     unsigned            pauseSleepMs;  // Length of time to sleep if the task receives a pause command.
73
   } cmTaskMgrFuncArg_t;
75
   } cmTaskMgrFuncArg_t;
74
 
76
 
83
     unsigned             queueByteCnt,
85
     unsigned             queueByteCnt,
84
     unsigned             pauseSleepMs );
86
     unsigned             pauseSleepMs );
85
 
87
 
88
+  // Calling cmTaskMgrDestroy() will send a 'kill' control message
89
+  // to any existing worker threads.  The threads will shutdown
90
+  // gracefully but the task they were computing will not be completed.
86
   cmTmRC_t cmTaskMgrDestroy( cmTaskMgrH_t* hp );
91
   cmTmRC_t cmTaskMgrDestroy( cmTaskMgrH_t* hp );
87
 
92
 
93
+  // Return true if the task manager handle is valid.
88
   bool     cmTaskMgrIsValid(   cmTaskMgrH_t h );
94
   bool     cmTaskMgrIsValid(   cmTaskMgrH_t h );
89
 
95
 
90
   // Called by the client to give the task mgr an opportunity to execute
96
   // Called by the client to give the task mgr an opportunity to execute
95
   cmTmRC_t cmTaskMgrOnIdle( cmTaskMgrH_t h );
101
   cmTmRC_t cmTaskMgrOnIdle( cmTaskMgrH_t h );
96
 
102
 
97
   // Pause/unpause the task mgr.
103
   // Pause/unpause the task mgr.
104
+  // This function pauses/unpauses each worker thread and then the master thread.
105
+  // If waitFl is set then the function will not return until each of
106
+  // the threads has entered the requested state. If 'waitFl' is false
107
+  // The function will wait for the worker threads to pause but will
108
+  // only signal the master thread to pause before returning.
98
   bool     cmTaskMgrIsEnabled( cmTaskMgrH_t h );
109
   bool     cmTaskMgrIsEnabled( cmTaskMgrH_t h );
99
   cmTmRC_t cmTaskMgrEnable(    cmTaskMgrH_t h, bool enableFl );
110
   cmTmRC_t cmTaskMgrEnable(    cmTaskMgrH_t h, bool enableFl );
100
 
111
 
101
   // Install a task function and associate it with a label and unique id.
112
   // Install a task function and associate it with a label and unique id.
102
   cmTmRC_t cmTaskMgrInstall( cmTaskMgrH_t h, unsigned taskId, const cmChar_t* label, cmTaskMgrFunc_t func ); 
113
   cmTmRC_t cmTaskMgrInstall( cmTaskMgrH_t h, unsigned taskId, const cmChar_t* label, cmTaskMgrFunc_t func ); 
103
 
114
 
104
-  // Queue a task.
115
+  // Queue a new task instance.
116
+  // The 'queued' status callback occurs from inside this call.
105
   cmTmRC_t cmTaskMgrCall( 
117
   cmTmRC_t cmTaskMgrCall( 
106
     cmTaskMgrH_t h, 
118
     cmTaskMgrH_t h, 
107
     unsigned     taskId, 
119
     unsigned     taskId, 
109
     unsigned     progCnt, 
121
     unsigned     progCnt, 
110
     unsigned*    retInstIdPtr ); 
122
     unsigned*    retInstIdPtr ); 
111
 
123
 
112
-  // Start,pause, or kill a task.  
113
-  // If a queued task is paused then it will remain at the front of the queue
114
-  // and tasks behdind it in the queue will be executed.
124
+  // Start,pause, or kill a task instance.  
125
+  // If a queued task is paused then it will remain at the front
126
+  // of the queue and tasks behdind it in the queue will be executed.
115
   cmTmRC_t cmTaskMgrTaskCtl( cmTaskMgrH_t h, unsigned instId, cmTaskMgrCtlId_t ctlId );
127
   cmTmRC_t cmTaskMgrTaskCtl( cmTaskMgrH_t h, unsigned instId, cmTaskMgrCtlId_t ctlId );
116
 
128
 
117
   // Get the status of a task.
129
   // Get the status of a task.
118
   cmStatusTmId_t cmTaskMgrStatus( cmTaskMgrH_t h, unsigned instId );
130
   cmStatusTmId_t cmTaskMgrStatus( cmTaskMgrH_t h, unsigned instId );
119
 
131
 
120
-  
121
-  const void* cmTaskMgrResult( cmTaskMgrH_t h, unsigned instId );
132
+  // 
133
+  const void* cmTaskMgrResult(          cmTaskMgrH_t h, unsigned instId );
122
   unsigned    cmTaskMgrResultByteCount( cmTaskMgrH_t h, unsigned instId );
134
   unsigned    cmTaskMgrResultByteCount( cmTaskMgrH_t h, unsigned instId );
123
-  cmTmRC_t    cmTaskMgrResultDelete(    cmTaskMgrH_t h, unsigned instId );
135
+  cmTmRC_t    cmTaskMgrInstDelete(      cmTaskMgrH_t h, unsigned instId );
136
+
137
+
138
+  // -----------------------------------------------------------------------------------
139
+  // Worker thread helper functions.
140
+  cmTaskMgrCtlId_t cmTaskMgrHandleCommand( cmTaskMgrFuncArg_t* a );
141
+  cmTaskMgrCtlId_t cmTaskMgrSendStatus( cmTaskMgrFuncArg_t* a, cmStatusTmId_t statusId );
142
+  cmTaskMgrCtlId_t cmTaskMgrSendProgress( cmTaskMgrFuncArg_t* a, unsigned prog );
124
 
143
 
125
   cmTmRC_t cmTaskMgrTest(cmCtx_t* ctx);
144
   cmTmRC_t cmTaskMgrTest(cmCtx_t* ctx);
126
 
145
 

Loading…
Cancel
Save