CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
task.h
Go to the documentation of this file.
1
19
20#pragma once
21// This header file is auto-generated!
22// Do not make changes to this file or they will be overwritten.
23// clang-format off
24#include <cx/obj.h>
25#include <cx/struct.h>
26#include "basictask.h"
27#include <cx/closure.h>
28
29CX_C_BEGIN
30
31typedef struct TaskQueue TaskQueue;
32typedef struct TaskQueue_WeakRef TaskQueue_WeakRef;
33typedef struct TQWorker TQWorker;
34typedef struct TQWorker_WeakRef TQWorker_WeakRef;
35typedef struct TaskControl TaskControl;
36typedef struct Task Task;
37typedef struct Task_WeakRef Task_WeakRef;
39saDeclarePtr(Task_WeakRef);
40#define _sti_Task _sti_object
41#define SType_Task Task*
42#define STStorageType_Task Task*
43#define STypeArg_Task(type, val) stgeneric(object, (ObjInst*)objInstCheckClass(Task, val))
44#define STypeArgPtr_Task(type, val) (stgeneric*)objInstCheckClassPtr(Task, val)
45#define STypeCheckedArg_Task(type, val) stType(type), stArg(type, val)
46#define STypeCheckedPtrArg_Task(type, val) stType(type), stArgPtr(type, val)
47
48typedef struct Task_ClassIf {
49 ObjIface* _implements;
50 ObjIface* _parent;
51 size_t _size;
52
53 uint32 (*run)(_In_ void* self, _In_ TaskQueue* tq, _In_ TQWorker* worker, _Inout_ TaskControl* tcon);
54 void (*runCancelled)(_In_ void* self, _In_ TaskQueue* tq, _In_ TQWorker* worker);
55 bool (*cancel)(_In_ void* self);
56 bool (*reset)(_In_ void* self);
57 bool (*wait)(_In_ void* self, int64 timeout);
58} Task_ClassIf;
59extern Task_ClassIf Task_ClassIf_tmpl;
60
62typedef struct Task {
63 union {
64 Task_ClassIf* _;
65 void* _is_Task;
66 void* _is_BasicTask;
67 void* _is_ObjInst;
68 };
69 ObjClassInfo* _clsinfo;
70 atomic(uintptr) _ref;
71 atomic(ptr) _weakref;
72
73 atomic(uint32) state;
77 void* logctx;
78 string name;
79 int64 last;
80 cchain oncomplete;
81} Task;
82extern ObjClassInfo Task_clsinfo;
83#define Task(inst) objInstCheckClass(Task, inst)
84#define TaskNone ((Task*)NULL)
85
86typedef struct Task_WeakRef {
87 union {
88 ObjInst* _inst;
89 void* _is_Task_WeakRef;
90 void* _is_BasicTask_WeakRef;
91 void* _is_ObjInst_WeakRef;
92 };
93 atomic(uintptr) _ref;
94 RWLock _lock;
95} Task_WeakRef;
96#define Task_WeakRef(inst) objWeakRefCheckClass(Task, inst)
97
98// bool ftask_setState(Task* self, uint32 newstate);
99#define ftask_setState(self, newstate) BasicTask__setState(BasicTask(self), newstate)
100
112#define ftaskRun(self, tq, worker, tcon) (self)->_->run(Task(self), TaskQueue(tq), TQWorker(worker), tcon)
118#define ftaskRunCancelled(self, tq, worker) (self)->_->runCancelled(Task(self), TaskQueue(tq), TQWorker(worker))
123#define ftaskCancel(self) (self)->_->cancel(Task(self))
124// bool ftaskReset(Task* self);
125#define ftaskReset(self) (self)->_->reset(Task(self))
131#define ftaskWait(self, timeout) (self)->_->wait(Task(self), timeout)
132
133CX_C_END
Bare minimum task object (base class)
#define saDeclarePtr(name)
Definition sarray.h:100
Closures and callback chains aggregated header.
CX Struct System - Introspectable, serializable POD structures in C.
CX Object System - Object-oriented programming in C.
Task with name, timing information, and completion callbacks.
Definition task.h:62
void * logctx
Definition task.h:77
string name
Task name shown in monitor output.
Definition task.h:78
cchain oncomplete
Functions called when task completes (success or failure)
Definition task.h:80
int64 last
Last time this task was moved between queues and/or run.
Definition task.h:79
atomic(uint32) state