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 "basictask.h"
26#include <cx/closure.h>
27
28typedef struct TaskQueue TaskQueue;
29typedef struct TaskQueue_WeakRef TaskQueue_WeakRef;
30typedef struct TQWorker TQWorker;
31typedef struct TQWorker_WeakRef TQWorker_WeakRef;
32typedef struct TaskControl TaskControl;
33typedef struct Task Task;
34typedef struct Task_WeakRef Task_WeakRef;
36saDeclarePtr(Task_WeakRef);
37
38typedef struct Task_ClassIf {
39 ObjIface* _implements;
40 ObjIface* _parent;
41 size_t _size;
42
43 uint32 (*run)(_In_ void* self, _In_ TaskQueue* tq, _In_ TQWorker* worker, _Inout_ TaskControl* tcon);
44 void (*runCancelled)(_In_ void* self, _In_ TaskQueue* tq, _In_ TQWorker* worker);
45 bool (*cancel)(_In_ void* self);
46 bool (*reset)(_In_ void* self);
47 bool (*wait)(_In_ void* self, int64 timeout);
48} Task_ClassIf;
49extern Task_ClassIf Task_ClassIf_tmpl;
50
52typedef struct Task {
53 union {
54 Task_ClassIf* _;
55 void* _is_Task;
56 void* _is_BasicTask;
57 void* _is_ObjInst;
58 };
59 ObjClassInfo* _clsinfo;
60 atomic(uintptr) _ref;
61 atomic(ptr) _weakref;
62
63 atomic(uint32) state;
64 string name;
65 int64 last;
66 cchain oncomplete;
67} Task;
68extern ObjClassInfo Task_clsinfo;
69#define Task(inst) ((Task*)(unused_noeval((inst) && &((inst)->_is_Task)), (inst)))
70#define TaskNone ((Task*)NULL)
71
72typedef struct Task_WeakRef {
73 union {
74 ObjInst* _inst;
75 void* _is_Task_WeakRef;
76 void* _is_BasicTask_WeakRef;
77 void* _is_ObjInst_WeakRef;
78 };
79 atomic(uintptr) _ref;
80 RWLock _lock;
81} Task_WeakRef;
82#define Task_WeakRef(inst) ((Task_WeakRef*)(unused_noeval((inst) && &((inst)->_is_Task_WeakRef)), (inst)))
83
84// bool ftask_setState(Task* self, uint32 newstate);
85#define ftask_setState(self, newstate) BasicTask__setState(BasicTask(self), newstate)
86
98#define ftaskRun(self, tq, worker, tcon) (self)->_->run(Task(self), TaskQueue(tq), TQWorker(worker), tcon)
104#define ftaskRunCancelled(self, tq, worker) (self)->_->runCancelled(Task(self), TaskQueue(tq), TQWorker(worker))
109#define ftaskCancel(self) (self)->_->cancel(Task(self))
110// bool ftaskReset(Task* self);
111#define ftaskReset(self) (self)->_->reset(Task(self))
117#define ftaskWait(self, timeout) (self)->_->wait(Task(self), timeout)
118
Bare minimum task object (base class)
#define saDeclarePtr(name)
Definition sarray.h:98
Closures and callback chains aggregated header.
CX Object System - Object-oriented programming in C.
Task with name, timing information, and completion callbacks.
Definition task.h:52
string name
Task name shown in monitor output.
Definition task.h:64
cchain oncomplete
Functions called when task completes (success or failure)
Definition task.h:66
int64 last
Last time this task was moved between queues and/or run.
Definition task.h:65
atomic(uint32) state
Current task state and flags.