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