libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmTaskMgr.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef cmTaskMgr_h
  2. #define cmTaskMgr_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. enum
  7. {
  8. kOkTmRC,
  9. kThreadFailTmRC,
  10. kInvalidArgTmRC,
  11. kOpFailTmRC,
  12. kQueueFailTmRC,
  13. kTestFailTmRC
  14. };
  15. typedef cmRC_t cmTmRC_t;
  16. typedef cmHandle_t cmTaskMgrH_t;
  17. extern cmTaskMgrH_t cmTaskMgrNullHangle;
  18. typedef enum
  19. {
  20. kInvalidTmId,
  21. kQueuedTmId, // The task is waiting in the queue.
  22. kQueuedPausedTmId, // The task is waiting in the queue but is deferred.
  23. kStartedTmId, // The task is running.
  24. kCompletedTmId, // The task successfully completed.
  25. kKilledTmId // The task was killed by the client.
  26. } cmStatusTmId_t;
  27. typedef enum
  28. {
  29. kStatusTmId, // Task status updates. These are automatically sent by the system when the task instance changes state.
  30. kProgTmId, // Task progress update. The user function should increment the 'prog' toward 'progCnt'.
  31. kErrorTmId //
  32. } cmSelTmId_t;
  33. typedef enum
  34. {
  35. kStartTmId,
  36. kPauseTmId,
  37. kKillTmId
  38. } cmTaskMgrCtlId_t;
  39. typedef struct cmTaskMgrStatusArg_str
  40. {
  41. void* arg;
  42. unsigned instId;
  43. cmSelTmId_t selId;
  44. cmStatusTmId_t statusId;
  45. unsigned prog;
  46. const cmChar_t* msg;
  47. void* result;
  48. unsigned resultByteCnt;
  49. } cmTaskMgrStatusArg_t;
  50. typedef void (*cmTaskMgrStatusCb_t)( const cmTaskMgrStatusArg_t* status );
  51. typedef struct cmTaskMgrFuncArg_str
  52. {
  53. void* arg; // 'funcArg' provided by cmTaskMgrCall();
  54. unsigned argByteCnt; // 'funcArgByteCnt' provided by cmTaskMgrCall()
  55. unsigned instId; // Task instance id.
  56. cmTaskMgrStatusCb_t statusCb; // Status update function provided by cmTaskMgrCreate().
  57. void* statusCbArg; // Status update function arg. provided by cmTaskMgrCreate().
  58. unsigned progCnt; // Maximum expected value of cmTaskMgrStatusArg_t.prog during execution of this task instance.
  59. cmTaskMgrCtlId_t* cmdIdPtr; // Command id used to inform the running task that it should pause or exit.
  60. unsigned pauseSleepMs; // Length of time to sleep if the task receives a pause command.
  61. } cmTaskMgrFuncArg_t;
  62. typedef void (*cmTaskMgrFunc_t)(cmTaskMgrFuncArg_t* arg );
  63. cmTmRC_t cmTaskMgrCreate(
  64. cmCtx_t* ctx,
  65. cmTaskMgrH_t* hp,
  66. cmTaskMgrStatusCb_t statusCb,
  67. void* statusCbArg,
  68. unsigned threadCnt,
  69. unsigned queueByteCnt,
  70. unsigned pauseSleepMs );
  71. cmTmRC_t cmTaskMgrDestroy( cmTaskMgrH_t* hp );
  72. bool cmTaskMgrIsValid( cmTaskMgrH_t h );
  73. // Called by the client to give the task mgr an opportunity to execute
  74. // period functions from within the client thread. Note that 'statusCb()'
  75. // (as passed to cmTaskMgrCreate()) is only called within this function
  76. // This guarantees that all communication with the client occurs in the
  77. // clients thread.
  78. cmTmRC_t cmTaskMgrOnIdle( cmTaskMgrH_t h );
  79. // Pause/unpause the task mgr.
  80. bool cmTaskMgrIsEnabled( cmTaskMgrH_t h );
  81. cmTmRC_t cmTaskMgrEnable( cmTaskMgrH_t h, bool enableFl );
  82. // Install a task function and associate it with a label and unique id.
  83. cmTmRC_t cmTaskMgrInstall( cmTaskMgrH_t h, unsigned taskId, const cmChar_t* label, cmTaskMgrFunc_t func );
  84. // Queue a task.
  85. cmTmRC_t cmTaskMgrCall(
  86. cmTaskMgrH_t h,
  87. unsigned taskId,
  88. void* funcArg,
  89. unsigned progCnt,
  90. unsigned* retInstIdPtr );
  91. // Start,pause, or kill a task.
  92. // If a queued task is paused then it will remain at the front of the queue
  93. // and tasks behdind it in the queue will be executed.
  94. cmTmRC_t cmTaskMgrTaskCtl( cmTaskMgrH_t h, unsigned instId, cmTaskMgrCtlId_t ctlId );
  95. // Get the status of a task.
  96. cmStatusTmId_t cmTaskMgrStatus( cmTaskMgrH_t h, unsigned instId );
  97. const void* cmTaskMgrResult( cmTaskMgrH_t h, unsigned instId );
  98. unsigned cmTaskMgrResultByteCount( cmTaskMgrH_t h, unsigned instId );
  99. cmTmRC_t cmTaskMgrResultDelete( cmTaskMgrH_t h, unsigned instId );
  100. cmTmRC_t cmTaskMgrTest(cmCtx_t* ctx);
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #endif