Przeglądaj źródła

cmTaskMgr.h : Initial working version.

master
kpl 10 lat temu
rodzic
commit
9b9b49bf3c
1 zmienionych plików z 28 dodań i 9 usunięć
  1. 28
    9
      cmTaskMgr.h

+ 28
- 9
cmTaskMgr.h Wyświetl plik

@@ -12,6 +12,7 @@ extern "C" {
12 12
     kInvalidArgTmRC,
13 13
     kOpFailTmRC,
14 14
     kQueueFailTmRC,
15
+    kAssertFailTmRC,
15 16
     kTestFailTmRC
16 17
   };
17 18
 
@@ -25,8 +26,8 @@ extern "C" {
25 26
   {
26 27
     kInvalidTmId,
27 28
     kQueuedTmId,       // The task is waiting in the queue.
28
-    kQueuedPausedTmId, // The task is waiting in the queue but is deferred.
29 29
     kStartedTmId,      // The task is running.
30
+    kPausedTmId,       // The task is paused.
30 31
     kCompletedTmId,    // The task successfully completed.
31 32
     kKilledTmId        // The task was killed by the client.
32 33
   } cmStatusTmId_t;
@@ -40,6 +41,7 @@ extern "C" {
40 41
 
41 42
   typedef enum 
42 43
   { 
44
+    kNoneTmId,
43 45
     kStartTmId, 
44 46
     kPauseTmId, 
45 47
     kKillTmId 
@@ -62,13 +64,13 @@ extern "C" {
62 64
 
63 65
   typedef struct cmTaskMgrFuncArg_str
64 66
   {
67
+    void*               reserved; 
65 68
     void*               arg;           // 'funcArg' provided by cmTaskMgrCall();
66 69
     unsigned            argByteCnt;    // 'funcArgByteCnt' provided by cmTaskMgrCall()
67 70
     unsigned            instId;        // Task instance id.
68 71
     cmTaskMgrStatusCb_t statusCb;      // Status update function provided by cmTaskMgrCreate().
69 72
     void*               statusCbArg;   // Status update function arg. provided by cmTaskMgrCreate().
70 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 74
     unsigned            pauseSleepMs;  // Length of time to sleep if the task receives a pause command.
73 75
   } cmTaskMgrFuncArg_t;
74 76
 
@@ -83,8 +85,12 @@ extern "C" {
83 85
     unsigned             queueByteCnt,
84 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 91
   cmTmRC_t cmTaskMgrDestroy( cmTaskMgrH_t* hp );
87 92
 
93
+  // Return true if the task manager handle is valid.
88 94
   bool     cmTaskMgrIsValid(   cmTaskMgrH_t h );
89 95
 
90 96
   // Called by the client to give the task mgr an opportunity to execute
@@ -95,13 +101,19 @@ extern "C" {
95 101
   cmTmRC_t cmTaskMgrOnIdle( cmTaskMgrH_t h );
96 102
 
97 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 109
   bool     cmTaskMgrIsEnabled( cmTaskMgrH_t h );
99 110
   cmTmRC_t cmTaskMgrEnable(    cmTaskMgrH_t h, bool enableFl );
100 111
 
101 112
   // Install a task function and associate it with a label and unique id.
102 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 117
   cmTmRC_t cmTaskMgrCall( 
106 118
     cmTaskMgrH_t h, 
107 119
     unsigned     taskId, 
@@ -109,18 +121,25 @@ extern "C" {
109 121
     unsigned     progCnt, 
110 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 127
   cmTmRC_t cmTaskMgrTaskCtl( cmTaskMgrH_t h, unsigned instId, cmTaskMgrCtlId_t ctlId );
116 128
 
117 129
   // Get the status of a task.
118 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 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 144
   cmTmRC_t cmTaskMgrTest(cmCtx_t* ctx);
126 145
 

Ładowanie…
Anuluj
Zapisz