CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
trfifo.h
Go to the documentation of this file.
1
27
28#pragma once
29// This header file is auto-generated!
30// Do not make changes to this file or they will be overwritten.
31// clang-format off
32#include <cx/obj.h>
33#include <cx/struct.h>
34#include "taskresource.h"
35#include <cx/thread/mutex.h>
36
37CX_C_BEGIN
38
39typedef struct ComplexTask ComplexTask;
40typedef struct ComplexTask_WeakRef ComplexTask_WeakRef;
41typedef struct ComplexTask ComplexTask;
42typedef struct ComplexTask_WeakRef ComplexTask_WeakRef;
43typedef struct TRFifoNode TRFifoNode;
44typedef struct TRFifo TRFifo;
45typedef struct TRFifo_WeakRef TRFifo_WeakRef;
47saDeclarePtr(TRFifo_WeakRef);
48#define _sti_TRFifo _sti_object
49#define SType_TRFifo TRFifo*
50#define STStorageType_TRFifo TRFifo*
51#define STypeArg_TRFifo(type, val) stgeneric(object, (ObjInst*)objInstCheckClass(TRFifo, val))
52#define STypeArgPtr_TRFifo(type, val) (stgeneric*)objInstCheckClassPtr(TRFifo, val)
53#define STypeCheckedArg_TRFifo(type, val) stType(type), stArg(type, val)
54#define STypeCheckedPtrArg_TRFifo(type, val) stType(type), stArgPtr(type, val)
55
56typedef struct TRFifoNode {
57 TRFifoNode *next;
58 ComplexTask *task;
59} TRFifoNode;
60
61typedef struct TRFifo_ClassIf {
62 ObjIface* _implements;
63 ObjIface* _parent;
64 size_t _size;
65
66 bool (*registerTask)(_In_ void* self, ComplexTask* task);
67 bool (*canAcquire)(_In_ void* self, ComplexTask* task);
68 bool (*tryAcquire)(_In_ void* self, ComplexTask* task);
69 void (*release)(_In_ void* self, ComplexTask* task);
70} TRFifo_ClassIf;
71extern TRFifo_ClassIf TRFifo_ClassIf_tmpl;
72
74typedef struct TRFifo {
75 union {
76 TRFifo_ClassIf* _;
77 void* _is_TRFifo;
78 void* _is_TaskResource;
79 void* _is_ObjInst;
80 };
81 ObjClassInfo* _clsinfo;
82 atomic(uintptr) _ref;
83 atomic(ptr) _weakref;
84
85 Mutex _fifomtx;
87 TRFifoNode* head;
88 TRFifoNode* tail;
89} TRFifo;
90extern ObjClassInfo TRFifo_clsinfo;
91#define TRFifo(inst) objInstCheckClass(TRFifo, inst)
92#define TRFifoNone ((TRFifo*)NULL)
93
94typedef struct TRFifo_WeakRef {
95 union {
96 ObjInst* _inst;
97 void* _is_TRFifo_WeakRef;
98 void* _is_TaskResource_WeakRef;
99 void* _is_ObjInst_WeakRef;
100 };
101 atomic(uintptr) _ref;
102 RWLock _lock;
103} TRFifo_WeakRef;
104#define TRFifo_WeakRef(inst) objWeakRefCheckClass(TRFifo, inst)
105
106_objfactory_guaranteed TRFifo* TRFifo_create();
111#define trfifoCreate() TRFifo_create()
112
113// bool trfifoRegisterTask(TRFifo* self, ComplexTask* task);
114#define trfifoRegisterTask(self, task) (self)->_->registerTask(TRFifo(self), ComplexTask(task))
115// bool trfifoCanAcquire(TRFifo* self, ComplexTask* task);
116#define trfifoCanAcquire(self, task) (self)->_->canAcquire(TRFifo(self), ComplexTask(task))
117// bool trfifoTryAcquire(TRFifo* self, ComplexTask* task);
118#define trfifoTryAcquire(self, task) (self)->_->tryAcquire(TRFifo(self), ComplexTask(task))
119// void trfifoRelease(TRFifo* self, ComplexTask* task);
120#define trfifoRelease(self, task) (self)->_->release(TRFifo(self), ComplexTask(task))
121
122CX_C_END
#define saDeclarePtr(name)
Definition sarray.h:100
#define _objfactory_guaranteed
Definition objimpl.h:106
CX Struct System - Introspectable, serializable POD structures in C.
Mutex synchronization primitive.
CX Object System - Object-oriented programming in C.
Complex task with dependencies, scheduling, and resource management.
Definition mutex.h:60
Strictly ordered FIFO resource for serialized task execution.
Definition trfifo.h:74
TRFifoNode * head
Head of wait queue.
Definition trfifo.h:87
TRFifoNode * tail
Tail of wait queue.
Definition trfifo.h:88
ComplexTask * cur
Currently running task.
Definition trfifo.h:86
Abstract base class for shared resources.