CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
tqueue.h
1#pragma once
2// This header file is auto-generated!
3// Do not make changes to this file or they will be overwritten.
4// clang-format off
5#include <cx/obj.h>
7#include <cx/thread/event.h>
8#include <cx/thread/thread.h>
9#include <cx/thread/prqueue.h>
10
11typedef struct TQRunner TQRunner;
12typedef struct TQRunner_WeakRef TQRunner_WeakRef;
13typedef struct TQManager TQManager;
14typedef struct TQManager_WeakRef TQManager_WeakRef;
15typedef struct TQMonitor TQMonitor;
16typedef struct TQMonitor_WeakRef TQMonitor_WeakRef;
17typedef struct TQWorker TQWorker;
18typedef struct TQWorker_WeakRef TQWorker_WeakRef;
19typedef struct BasicTask BasicTask;
20typedef struct BasicTask_WeakRef BasicTask_WeakRef;
21typedef struct TaskQueue TaskQueue;
22typedef struct TaskQueue_WeakRef TaskQueue_WeakRef;
23saDeclarePtr(TaskQueue);
24saDeclarePtr(TaskQueue_WeakRef);
25
26typedef enum TaskQueueStateEnum {
27 TQState_Init,
28 TQState_Starting,
29 TQState_Running,
30 TQState_Stopping,
31 TQState_Shutdown,
32} TaskQueueStateEnum;
33
34typedef struct TaskQueue_ClassIf {
35 ObjIface* _implements;
36 ObjIface* _parent;
37 size_t _size;
38
39 // start the queue, begin running tasks
40 bool (*start)(_In_ void* self);
41 // stop the queue
42 bool (*stop)(_In_ void* self, int64 timeout);
43 // add a task to the queue to run immediately
44 bool (*add)(_In_ void* self, _In_ BasicTask* btask);
45 // run one more more tasks -- only valid in manual mode
46 int64 (*tick)(_In_ void* self);
47 // internal function for manager to tell the queue to process its doneq
48 bool (*_processDone)(_In_ void* self);
49 // internal function for any additional processing that the queue needs to do in the manager thread
50 int64 (*_processExtra)(_In_ void* self, bool taskscompleted);
51 // internal function that the manager should call to perform any queue maintenance
52 bool (*_queueMaint)(_In_ void* self);
53 // internal function workers should call to actually run a task and process the results
54 bool (*_runTask)(_In_ void* self, _Inout_ BasicTask** pbtask, _In_ TQWorker* worker);
55 // deletes all tasks in queue, for internal use only
56 void (*_clear)(_In_ void* self);
57} TaskQueue_ClassIf;
58extern TaskQueue_ClassIf TaskQueue_ClassIf_tmpl;
59
60typedef struct TaskQueue {
61 union {
62 TaskQueue_ClassIf* _;
63 void* _is_TaskQueue;
64 void* _is_ObjInst;
65 };
66 ObjClassInfo* _clsinfo;
67 atomic(uintptr) _ref;
68 atomic(ptr) _weakref;
69
70 string name;
71 atomic(uint32) state;
72 TQRunner* runner;
73 TQManager* manager;
74 TQMonitor* monitor;
75 Event workev; // signaled when there is work to be done
76 PrQueue runq; // tasks that are ready to be picked up by workers
77 PrQueue doneq; // tasks that are either deferred or finished
78 int64 gcinterval; // how often to run a garbage collection cycle on a queue
79 uint32 flags;
80 int64 _lastgc; // timestamp of last GC cycle
81 int _gccycle; // which GC cycle ran last
82} TaskQueue;
83extern ObjClassInfo TaskQueue_clsinfo;
84#define TaskQueue(inst) ((TaskQueue*)(unused_noeval((inst) && &((inst)->_is_TaskQueue)), (inst)))
85#define TaskQueueNone ((TaskQueue*)NULL)
86
87typedef struct TaskQueue_WeakRef {
88 union {
89 ObjInst* _inst;
90 void* _is_TaskQueue_WeakRef;
91 void* _is_ObjInst_WeakRef;
92 };
93 atomic(uintptr) _ref;
94 RWLock _lock;
95} TaskQueue_WeakRef;
96#define TaskQueue_WeakRef(inst) ((TaskQueue_WeakRef*)(unused_noeval((inst) && &((inst)->_is_TaskQueue_WeakRef)), (inst)))
97
98_objfactory_guaranteed TaskQueue* TaskQueue_create(_In_opt_ strref name, uint32 flags, int64 gcinterval, _In_ TQRunner* runner, _In_ TQManager* manager, _In_opt_ TQMonitor* monitor);
99// TaskQueue* taskqueueCreate(strref name, uint32 flags, int64 gcinterval, TQRunner* runner, TQManager* manager, TQMonitor* monitor);
100#define taskqueueCreate(name, flags, gcinterval, runner, manager, monitor) TaskQueue_create(name, flags, gcinterval, TQRunner(runner), TQManager(manager), TQMonitor(monitor))
101
102// bool taskqueueStart(TaskQueue* self);
103//
104// start the queue, begin running tasks
105#define taskqueueStart(self) (self)->_->start(TaskQueue(self))
106// bool taskqueueStop(TaskQueue* self, int64 timeout);
107//
108// stop the queue
109#define taskqueueStop(self, timeout) (self)->_->stop(TaskQueue(self), timeout)
110// bool taskqueueAdd(TaskQueue* self, BasicTask* btask);
111//
112// add a task to the queue to run immediately
113#define taskqueueAdd(self, btask) (self)->_->add(TaskQueue(self), BasicTask(btask))
114// int64 taskqueueTick(TaskQueue* self);
115//
116// run one more more tasks -- only valid in manual mode
117#define taskqueueTick(self) (self)->_->tick(TaskQueue(self))
118// bool taskqueue_processDone(TaskQueue* self);
119//
120// internal function for manager to tell the queue to process its doneq
121#define taskqueue_processDone(self) (self)->_->_processDone(TaskQueue(self))
122// int64 taskqueue_processExtra(TaskQueue* self, bool taskscompleted);
123//
124// internal function for any additional processing that the queue needs to do in the manager thread
125#define taskqueue_processExtra(self, taskscompleted) (self)->_->_processExtra(TaskQueue(self), taskscompleted)
126// bool taskqueue_queueMaint(TaskQueue* self);
127//
128// internal function that the manager should call to perform any queue maintenance
129#define taskqueue_queueMaint(self) (self)->_->_queueMaint(TaskQueue(self))
130// bool taskqueue_runTask(TaskQueue* self, BasicTask** pbtask, TQWorker* worker);
131//
132// internal function workers should call to actually run a task and process the results
133#define taskqueue_runTask(self, pbtask, worker) (self)->_->_runTask(TaskQueue(self), pbtask, TQWorker(worker))
134// void taskqueue_clear(TaskQueue* self);
135//
136// deletes all tasks in queue, for internal use only
137#define taskqueue_clear(self) (self)->_->_clear(TaskQueue(self))
138
Event synchronization primitive.
#define saDeclarePtr(name)
Definition sarray.h:98
#define _objfactory_guaranteed
Definition objimpl.h:104
CX Object System - Object-oriented programming in C.
Bare minimum task object with state tracking and run method.
Definition basictask.h:59
Definition event.h:53
Shared types and configuration structures for the task queue system.
Thread creation and management.