CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
mptask.h
Go to the documentation of this file.
1
41
42#pragma once
43// This header file is auto-generated!
44// Do not make changes to this file or they will be overwritten.
45// clang-format off
46#include <cx/obj.h>
47#include <cx/struct.h>
48#include "complextask.h"
49
50CX_C_BEGIN
51
52typedef struct TaskQueue TaskQueue;
53typedef struct TaskQueue_WeakRef TaskQueue_WeakRef;
54typedef struct TQWorker TQWorker;
55typedef struct TQWorker_WeakRef TQWorker_WeakRef;
56typedef struct ComplexTask ComplexTask;
57typedef struct ComplexTask_WeakRef ComplexTask_WeakRef;
58typedef struct ComplexTask ComplexTask;
59typedef struct ComplexTask_WeakRef ComplexTask_WeakRef;
60typedef struct TRGate TRGate;
61typedef struct TRGate_WeakRef TRGate_WeakRef;
62typedef struct ComplexTaskQueue ComplexTaskQueue;
63typedef struct ComplexTaskQueue_WeakRef ComplexTaskQueue_WeakRef;
64typedef struct TaskControl TaskControl;
66typedef struct MultiphaseTask_WeakRef MultiphaseTask_WeakRef;
68saDeclarePtr(MultiphaseTask_WeakRef);
69#define _sti_MultiphaseTask _sti_object
70#define SType_MultiphaseTask MultiphaseTask*
71#define STStorageType_MultiphaseTask MultiphaseTask*
72#define STypeArg_MultiphaseTask(type, val) stgeneric(object, (ObjInst*)objInstCheckClass(MultiphaseTask, val))
73#define STypeArgPtr_MultiphaseTask(type, val) (stgeneric*)objInstCheckClassPtr(MultiphaseTask, val)
74#define STypeCheckedArg_MultiphaseTask(type, val) stType(type), stArg(type, val)
75#define STypeCheckedPtrArg_MultiphaseTask(type, val) stType(type), stArgPtr(type, val)
76
87typedef uint32 (*MPTPhaseFunc)(void *self, TaskQueue* tq, TQWorker* worker, TaskControl *tcon);
93#define mptaskAddPhases(self, parr) mptask_addPhases(self, sizeof(parr) / sizeof((parr)[0]), (parr), false)
98#define mptaskAddFailPhases(self, parr) mptask_addPhases(self, sizeof(parr) / sizeof((parr)[0]), (parr), true)
99
100typedef struct MultiphaseTask_ClassIf {
101 ObjIface* _implements;
102 ObjIface* _parent;
103 size_t _size;
104
105 uint32 (*run)(_In_ void* self, _In_ TaskQueue* tq, _In_ TQWorker* worker, _Inout_ TaskControl* tcon);
106 void (*runCancelled)(_In_ void* self, _In_ TaskQueue* tq, _In_ TQWorker* worker);
107 bool (*cancel)(_In_ void* self);
108 bool (*reset)(_In_ void* self);
109 bool (*wait)(_In_ void* self, int64 timeout);
110 intptr (*cmp)(_In_ void* self, void* other, uint32 flags);
111 uint32 (*hash)(_In_ void* self, uint32 flags);
112 uint32 (*finish)(_In_ void* self, uint32 result, TaskControl* tcon);
113} MultiphaseTask_ClassIf;
114extern MultiphaseTask_ClassIf MultiphaseTask_ClassIf_tmpl;
115
117typedef struct MultiphaseTask {
118 union {
119 MultiphaseTask_ClassIf* _;
120 void* _is_MultiphaseTask;
121 void* _is_ComplexTask;
122 void* _is_Task;
123 void* _is_BasicTask;
124 void* _is_ObjInst;
125 };
126 ObjClassInfo* _clsinfo;
127 atomic(uintptr) _ref;
128 atomic(ptr) _weakref;
129
130 atomic(uint32) state;
134 void* logctx;
135 string name;
136 int64 last;
137 cchain oncomplete;
138 int64 nextrun;
140 Weak(ComplexTaskQueue)* lastq;
141 sa_TaskRequires _requires;
142 uint16 flags;
143 uint16 _intflags;
144 atomic(uint32) _advcount;
145 sa_MPTPhaseFunc phases;
146 sa_MPTPhaseFunc failphases;
147 uint32 _phase;
148 bool _fail;
150extern ObjClassInfo MultiphaseTask_clsinfo;
151#define MultiphaseTask(inst) objInstCheckClass(MultiphaseTask, inst)
152#define MultiphaseTaskNone ((MultiphaseTask*)NULL)
153
154typedef struct MultiphaseTask_WeakRef {
155 union {
156 ObjInst* _inst;
157 void* _is_MultiphaseTask_WeakRef;
158 void* _is_ComplexTask_WeakRef;
159 void* _is_Task_WeakRef;
160 void* _is_BasicTask_WeakRef;
161 void* _is_ObjInst_WeakRef;
162 };
163 atomic(uintptr) _ref;
164 RWLock _lock;
165} MultiphaseTask_WeakRef;
166#define MultiphaseTask_WeakRef(inst) objWeakRefCheckClass(MultiphaseTask, inst)
167
168void MultiphaseTask__addPhases(_In_ MultiphaseTask* self, int32 num, MPTPhaseFunc parr[], bool fail);
176#define mptask_addPhases(self, num, parr, fail) MultiphaseTask__addPhases(MultiphaseTask(self), num, parr, fail)
177
183#define mptaskRequireTask(self, dep, failok) ComplexTask_requireTask(ComplexTask(self), Task(dep), failok)
184
191#define mptaskRequireTaskTimeout(self, dep, failok, timeout) ComplexTask_requireTaskTimeout(ComplexTask(self), Task(dep), failok, timeout)
192
197#define mptaskRequireResource(self, res) ComplexTask_requireResource(ComplexTask(self), TaskResource(res))
198
204#define mptaskRequireResourceTimeout(self, res, timeout) ComplexTask_requireResourceTimeout(ComplexTask(self), TaskResource(res), timeout)
205
210#define mptaskRequireGate(self, gate) ComplexTask_requireGate(ComplexTask(self), TRGate(gate))
211
217#define mptaskRequireGateTimeout(self, gate, timeout) ComplexTask_requireGateTimeout(ComplexTask(self), TRGate(gate), timeout)
218
223#define mptaskRequire(self, req) ComplexTask_require(ComplexTask(self), TaskRequires(req))
224
229#define mptaskAdvance(self) ComplexTask_advance(ComplexTask(self))
230
237#define mptaskCheckRequires(self, updateProgress, expires) ComplexTask_checkRequires(ComplexTask(self), updateProgress, expires)
238
242#define mptaskCancelRequires(self) ComplexTask_cancelRequires(ComplexTask(self))
243
249#define mptaskAcquireRequires(self, acquired) ComplexTask_acquireRequires(ComplexTask(self), acquired)
250
256#define mptaskReleaseRequires(self, resources) ComplexTask_releaseRequires(ComplexTask(self), resources)
257
258// bool mptask_setState(MultiphaseTask* self, uint32 newstate);
259#define mptask_setState(self, newstate) BasicTask__setState(BasicTask(self), newstate)
260
261// uint32 mptaskRun(MultiphaseTask* self, TaskQueue* tq, TQWorker* worker, TaskControl* tcon);
262#define mptaskRun(self, tq, worker, tcon) (self)->_->run(MultiphaseTask(self), TaskQueue(tq), TQWorker(worker), tcon)
268#define mptaskRunCancelled(self, tq, worker) (self)->_->runCancelled(MultiphaseTask(self), TaskQueue(tq), TQWorker(worker))
269// bool mptaskCancel(MultiphaseTask* self);
270#define mptaskCancel(self) (self)->_->cancel(MultiphaseTask(self))
271// bool mptaskReset(MultiphaseTask* self);
272#define mptaskReset(self) (self)->_->reset(MultiphaseTask(self))
278#define mptaskWait(self, timeout) (self)->_->wait(MultiphaseTask(self), timeout)
279// intptr mptaskCmp(MultiphaseTask* self, MultiphaseTask* other, uint32 flags);
280#define mptaskCmp(self, other, flags) (self)->_->cmp(MultiphaseTask(self), other, flags)
281// uint32 mptaskHash(MultiphaseTask* self, uint32 flags);
282#define mptaskHash(self, flags) (self)->_->hash(MultiphaseTask(self), flags)
290#define mptaskFinish(self, result, tcon) (self)->_->finish(MultiphaseTask(self), result, tcon)
291
292CX_C_END
Complex task with dependencies, scheduling, and resource management.
#define saDeclare(name)
Definition sarray.h:93
#define saDeclarePtr(name)
Definition sarray.h:100
MultiphaseTaskFlagsEnum
Flags controlling MultiphaseTask behavior.
Definition mptask.h:78
uint32(* MPTPhaseFunc)(void *self, TaskQueue *tq, TQWorker *worker, TaskControl *tcon)
Definition mptask.h:87
@ MPTASK_Greedy
Execute all phases immediately without yielding to other tasks.
Definition mptask.h:79
CX Struct System - Introspectable, serializable POD structures in C.
CX Object System - Object-oriented programming in C.
Complex task with dependencies, scheduling, and resource management.
Multiphase task with internal state machine for sequential execution phases.
Definition mptask.h:117
void * logctx
Definition mptask.h:134
cchain oncomplete
Functions called when task completes (success or failure)
Definition mptask.h:137
sa_TaskRequires _requires
List of requirements (dependencies, resources, gates)
Definition mptask.h:141
bool _fail
True if currently executing fail phases.
Definition mptask.h:148
string name
Task name shown in monitor output.
Definition mptask.h:135
int64 lastprogress
Timestamp of last progress change.
Definition mptask.h:139
atomic(uint32) state
uint16 _intflags
Internal flags reserved for scheduler use.
Definition mptask.h:143
sa_MPTPhaseFunc phases
Normal execution phases.
Definition mptask.h:145
atomic(uint32) _advcount
Number of times task has been advanced.
int64 last
Last time this task was moved between queues and/or run.
Definition mptask.h:136
uint32 _phase
Current phase index.
Definition mptask.h:147
uint16 flags
Task behavior flags (ComplexTaskFlagsEnum)
Definition mptask.h:142
int64 nextrun
Next scheduled run time.
Definition mptask.h:138
Weak(ComplexTaskQueue) *lastq
Last queue this task ran on before being deferred.
sa_MPTPhaseFunc failphases
Failure handling phases.
Definition mptask.h:146
One-time event gate for task synchronization.