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