CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
tqcomplex.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>
7#include "tqueue.h"
9
10CX_C_BEGIN
11
12typedef struct TQRunner TQRunner;
13typedef struct TQRunner_WeakRef TQRunner_WeakRef;
14typedef struct TQManager TQManager;
15typedef struct TQManager_WeakRef TQManager_WeakRef;
16typedef struct TQMonitor TQMonitor;
17typedef struct TQMonitor_WeakRef TQMonitor_WeakRef;
18typedef struct TQWorker TQWorker;
19typedef struct TQWorker_WeakRef TQWorker_WeakRef;
20typedef struct BasicTask BasicTask;
21typedef struct BasicTask_WeakRef BasicTask_WeakRef;
22typedef struct TaskQueue TaskQueue;
23typedef struct TaskQueue_WeakRef TaskQueue_WeakRef;
24typedef struct TQWorker TQWorker;
25typedef struct TQWorker_WeakRef TQWorker_WeakRef;
26typedef struct ComplexTask ComplexTask;
27typedef struct ComplexTask_WeakRef ComplexTask_WeakRef;
28typedef struct ComplexTask ComplexTask;
29typedef struct ComplexTask_WeakRef ComplexTask_WeakRef;
30typedef struct TRGate TRGate;
31typedef struct TRGate_WeakRef TRGate_WeakRef;
32typedef struct ComplexTaskQueue ComplexTaskQueue;
33typedef struct ComplexTaskQueue_WeakRef ComplexTaskQueue_WeakRef;
34typedef struct TaskControl TaskControl;
35typedef struct ComplexTaskQueue ComplexTaskQueue;
36typedef struct ComplexTaskQueue_WeakRef ComplexTaskQueue_WeakRef;
37saDeclarePtr(ComplexTaskQueue);
38saDeclarePtr(ComplexTaskQueue_WeakRef);
39#define _sti_ComplexTaskQueue _sti_object
40#define SType_ComplexTaskQueue ComplexTaskQueue*
41#define STStorageType_ComplexTaskQueue ComplexTaskQueue*
42#define STypeArg_ComplexTaskQueue(type, val) stgeneric(object, (ObjInst*)objInstCheckClass(ComplexTaskQueue, val))
43#define STypeArgPtr_ComplexTaskQueue(type, val) (stgeneric*)objInstCheckClassPtr(ComplexTaskQueue, val)
44#define STypeCheckedArg_ComplexTaskQueue(type, val) stType(type), stArg(type, val)
45#define STypeCheckedPtrArg_ComplexTaskQueue(type, val) stType(type), stArgPtr(type, val)
46
47typedef struct ComplexTaskQueue_ClassIf {
48 ObjIface* _implements;
49 ObjIface* _parent;
50 size_t _size;
51
52 // start the queue, begin running tasks
53 bool (*start)(_In_ void* self);
54 // stop the queue
55 bool (*stop)(_In_ void* self, int64 timeout);
56 // add a task to the queue to run immediately
57 bool (*add)(_In_ void* self, _In_ BasicTask* btask);
58 // run one more more tasks -- only valid in manual mode
59 int64 (*tick)(_In_ void* self);
60 // internal function for manager to tell the queue to process its doneq
61 bool (*_processDone)(_In_ void* self);
62 // internal function for any additional processing that the queue needs to do in the manager thread
63 int64 (*_processExtra)(_In_ void* self, bool taskscompleted);
64 // internal function that the manager should call to perform any queue maintenance
65 bool (*_queueMaint)(_In_ void* self);
66 // internal function workers should call to actually run a task and process the results
67 bool (*_runTask)(_In_ void* self, _Inout_ BasicTask** pbtask, _In_ TQWorker* worker);
68 // deletes all tasks in queue, for internal use only
69 void (*_clear)(_In_ void* self);
70 // add a task scheduled to run a relative time in the future
71 bool (*schedule)(_In_ void* self, _In_ ComplexTask* task, int64 delay);
72 // add a task but defer it indefinitely
73 bool (*defer)(_In_ void* self, _In_ ComplexTask* task);
74 bool (*advance)(_In_ void* self, _In_ ComplexTask* task);
75} ComplexTaskQueue_ClassIf;
76extern ComplexTaskQueue_ClassIf ComplexTaskQueue_ClassIf_tmpl;
77
78typedef struct ComplexTaskQueue {
79 union {
80 ComplexTaskQueue_ClassIf* _;
81 void* _is_ComplexTaskQueue;
82 void* _is_TaskQueue;
83 void* _is_ObjInst;
84 };
85 ObjClassInfo* _clsinfo;
86 atomic(uintptr) _ref;
87 atomic(ptr) _weakref;
88
89 string name;
90 atomic(uint32) state;
91 TQRunner* runner;
92 TQManager* manager;
93 TQMonitor* monitor;
94 Event workev; // signaled when there is work to be done
95 PrQueue runq; // tasks that are ready to be picked up by workers
96 PrQueue doneq; // tasks that are either deferred or finished
97 int64 gcinterval; // how often to run a garbage collection cycle on a queue
98 uint32 flags;
99 int64 _lastgc; // timestamp of last GC cycle
100 int _gccycle; // which GC cycle ran last
101 PrQueue advanceq; // tasks that are being advanced out of the defer and/or schedule lists
102 sa_ComplexTask scheduled; // tasks that are scheduled to run at a later time, sorted by time
103 hashtable deferred; // tasks that are deferred indefinitely, to be held until they are advanced
104} ComplexTaskQueue;
105extern ObjClassInfo ComplexTaskQueue_clsinfo;
106#define ComplexTaskQueue(inst) objInstCheckClass(ComplexTaskQueue, inst)
107#define ComplexTaskQueueNone ((ComplexTaskQueue*)NULL)
108
109typedef struct ComplexTaskQueue_WeakRef {
110 union {
111 ObjInst* _inst;
112 void* _is_ComplexTaskQueue_WeakRef;
113 void* _is_TaskQueue_WeakRef;
114 void* _is_ObjInst_WeakRef;
115 };
116 atomic(uintptr) _ref;
117 RWLock _lock;
118} ComplexTaskQueue_WeakRef;
119#define ComplexTaskQueue_WeakRef(inst) objWeakRefCheckClass(ComplexTaskQueue, inst)
120
121_objfactory_guaranteed ComplexTaskQueue* ComplexTaskQueue_create(_In_opt_ strref name, uint32 flags, int64 gcinterval, _In_ TQRunner* runner, _In_ TQManager* manager, _In_opt_ TQMonitor* monitor);
122// ComplexTaskQueue* ctaskqueueCreate(strref name, uint32 flags, int64 gcinterval, TQRunner* runner, TQManager* manager, TQMonitor* monitor);
123#define ctaskqueueCreate(name, flags, gcinterval, runner, manager, monitor) ComplexTaskQueue_create(name, flags, gcinterval, TQRunner(runner), TQManager(manager), TQMonitor(monitor))
124
125// bool ctaskqueueStart(ComplexTaskQueue* self);
126//
127// start the queue, begin running tasks
128#define ctaskqueueStart(self) (self)->_->start(ComplexTaskQueue(self))
129// bool ctaskqueueStop(ComplexTaskQueue* self, int64 timeout);
130//
131// stop the queue
132#define ctaskqueueStop(self, timeout) (self)->_->stop(ComplexTaskQueue(self), timeout)
133// bool ctaskqueueAdd(ComplexTaskQueue* self, BasicTask* btask);
134//
135// add a task to the queue to run immediately
136#define ctaskqueueAdd(self, btask) (self)->_->add(ComplexTaskQueue(self), BasicTask(btask))
137// int64 ctaskqueueTick(ComplexTaskQueue* self);
138//
139// run one more more tasks -- only valid in manual mode
140#define ctaskqueueTick(self) (self)->_->tick(ComplexTaskQueue(self))
141// bool ctaskqueue_processDone(ComplexTaskQueue* self);
142//
143// internal function for manager to tell the queue to process its doneq
144#define ctaskqueue_processDone(self) (self)->_->_processDone(ComplexTaskQueue(self))
145// int64 ctaskqueue_processExtra(ComplexTaskQueue* self, bool taskscompleted);
146//
147// internal function for any additional processing that the queue needs to do in the manager thread
148#define ctaskqueue_processExtra(self, taskscompleted) (self)->_->_processExtra(ComplexTaskQueue(self), taskscompleted)
149// bool ctaskqueue_queueMaint(ComplexTaskQueue* self);
150//
151// internal function that the manager should call to perform any queue maintenance
152#define ctaskqueue_queueMaint(self) (self)->_->_queueMaint(ComplexTaskQueue(self))
153// bool ctaskqueue_runTask(ComplexTaskQueue* self, BasicTask** pbtask, TQWorker* worker);
154//
155// internal function workers should call to actually run a task and process the results
156#define ctaskqueue_runTask(self, pbtask, worker) (self)->_->_runTask(ComplexTaskQueue(self), pbtask, TQWorker(worker))
157// void ctaskqueue_clear(ComplexTaskQueue* self);
158//
159// deletes all tasks in queue, for internal use only
160#define ctaskqueue_clear(self) (self)->_->_clear(ComplexTaskQueue(self))
161// bool ctaskqueueSchedule(ComplexTaskQueue* self, ComplexTask* task, int64 delay);
162//
163// add a task scheduled to run a relative time in the future
164#define ctaskqueueSchedule(self, task, delay) (self)->_->schedule(ComplexTaskQueue(self), ComplexTask(task), delay)
165// bool ctaskqueueDefer(ComplexTaskQueue* self, ComplexTask* task);
166//
167// add a task but defer it indefinitely
168#define ctaskqueueDefer(self, task) (self)->_->defer(ComplexTaskQueue(self), ComplexTask(task))
169// bool ctaskqueueAdvance(ComplexTaskQueue* self, ComplexTask* task);
170#define ctaskqueueAdvance(self, task) (self)->_->advance(ComplexTaskQueue(self), ComplexTask(task))
171
172CX_C_END
Complex task with dependencies, scheduling, and resource management.
#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.
Bare minimum task object with state tracking and run method.
Definition basictask.h:69
Complex task with dependencies, scheduling, and resource management.
Definition event.h:53
One-time event gate for task synchronization.