CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
trmutex.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 TRMutex TRMutex;
44typedef struct TRMutex_WeakRef TRMutex_WeakRef;
45saDeclarePtr(TRMutex);
46saDeclarePtr(TRMutex_WeakRef);
47#define _sti_TRMutex _sti_object
48#define SType_TRMutex TRMutex*
49#define STStorageType_TRMutex TRMutex*
50#define STypeArg_TRMutex(type, val) stgeneric(object, (ObjInst*)objInstCheckClass(TRMutex, val))
51#define STypeArgPtr_TRMutex(type, val) (stgeneric*)objInstCheckClassPtr(TRMutex, val)
52#define STypeCheckedArg_TRMutex(type, val) stType(type), stArg(type, val)
53#define STypeCheckedPtrArg_TRMutex(type, val) stType(type), stArgPtr(type, val)
54
55typedef struct TRMutex_ClassIf {
56 ObjIface* _implements;
57 ObjIface* _parent;
58 size_t _size;
59
60 bool (*registerTask)(_In_ void* self, ComplexTask* task);
61 bool (*canAcquire)(_In_ void* self, ComplexTask* task);
62 bool (*tryAcquire)(_In_ void* self, ComplexTask* task);
63 void (*release)(_In_ void* self, ComplexTask* task);
64 void (*wakeup)(_In_ void* self);
65} TRMutex_ClassIf;
66extern TRMutex_ClassIf TRMutex_ClassIf_tmpl;
67
71typedef struct TRMutex {
72 union {
73 TRMutex_ClassIf* _;
74 void* _is_TRMutex;
75 void* _is_TaskResource;
76 void* _is_ObjInst;
77 };
78 ObjClassInfo* _clsinfo;
79 atomic(uintptr) _ref;
80 atomic(ptr) _weakref;
81
82 Mutex mtx;
83 Mutex _wlmtx;
84 hashtable _waitlist;
85} TRMutex;
86extern ObjClassInfo TRMutex_clsinfo;
87#define TRMutex(inst) objInstCheckClass(TRMutex, inst)
88#define TRMutexNone ((TRMutex*)NULL)
89
90typedef struct TRMutex_WeakRef {
91 union {
92 ObjInst* _inst;
93 void* _is_TRMutex_WeakRef;
94 void* _is_TaskResource_WeakRef;
95 void* _is_ObjInst_WeakRef;
96 };
97 atomic(uintptr) _ref;
98 RWLock _lock;
99} TRMutex_WeakRef;
100#define TRMutex_WeakRef(inst) objWeakRefCheckClass(TRMutex, inst)
101
102_objfactory_guaranteed TRMutex* TRMutex_create();
107#define trmutexCreate() TRMutex_create()
108
109// bool trmutexRegisterTask(TRMutex* self, ComplexTask* task);
110#define trmutexRegisterTask(self, task) (self)->_->registerTask(TRMutex(self), ComplexTask(task))
111// bool trmutexCanAcquire(TRMutex* self, ComplexTask* task);
112#define trmutexCanAcquire(self, task) (self)->_->canAcquire(TRMutex(self), ComplexTask(task))
113// bool trmutexTryAcquire(TRMutex* self, ComplexTask* task);
114#define trmutexTryAcquire(self, task) (self)->_->tryAcquire(TRMutex(self), ComplexTask(task))
115// void trmutexRelease(TRMutex* self, ComplexTask* task);
116#define trmutexRelease(self, task) (self)->_->release(TRMutex(self), ComplexTask(task))
121#define trmutexWakeup(self) (self)->_->wakeup(TRMutex(self))
122
123CX_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
Abstract base class for shared resources.