CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
tqueue.cxh
1#include <cx/taskqueue/taskqueue_shared.h>
2#include <cx/thread/event.h>
3#include <cx/thread/thread.h>
4#include <cx/thread/prqueue.h>
5
6class TQRunner;
7class TQManager;
8class TQMonitor;
9class TQWorker;
10
11class BasicTask;
12
13typedef enum TaskQueueStateEnum {
14 TQState_Init,
15 TQState_Starting,
16 TQState_Running,
17 TQState_Stopping,
18 TQState_Shutdown,
19} TaskQueueStateEnum;
20
21class TaskQueue {
22 string name;
23 atomic:uint32 state;
24
25 object:TQRunner runner;
26 object:TQManager manager;
27 object:TQMonitor monitor;
28
29 [noinit] Event workev; // signaled when there is work to be done
30
31 PrQueue runq; // tasks that are ready to be picked up by workers
32 PrQueue doneq; // tasks that are either deferred or finished
33
34 int64 gcinterval; // how often to run a garbage collection cycle on a queue
35 uint32 flags;
36
37 int64 _lastgc; // timestamp of last GC cycle
38 int _gccycle; // which GC cycle ran last
39
40 bool start(); // start the queue, begin running tasks
41 bool stop(int64 timeout); // stop the queue
42
43 bool add([in] BasicTask *btask); // add a task to the queue to run immediately
44
45 int64 tick(); // run one more more tasks -- only valid in manual mode
46
47 bool _processDone(); // internal function for manager to tell the queue to process its doneq
48 int64 _processExtra(bool taskscompleted); // internal function for any additional processing that the queue needs to do in the manager thread
49 bool _queueMaint(); // internal function that the manager should call to perform any queue maintenance
50
51 bool _runTask([inout] BasicTask **pbtask, [in] TQWorker *worker); // internal function workers should call to actually run a task and process the results
52 void _clear(); // deletes all tasks in queue, for internal use only
53
54 factory create(strref name, uint32 flags, int64 gcinterval, [in] TQRunner *runner, [in] TQManager *manager, [in] [opt] TQMonitor *monitor);
55 init();
56}