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 "taskresource.h"
34#include <cx/thread/mutex.h>
35
36typedef struct ComplexTask ComplexTask;
37typedef struct ComplexTask_WeakRef ComplexTask_WeakRef;
38typedef struct ComplexTask ComplexTask;
39typedef struct ComplexTask_WeakRef ComplexTask_WeakRef;
40typedef struct TRMutex TRMutex;
41typedef struct TRMutex_WeakRef TRMutex_WeakRef;
42saDeclarePtr(TRMutex);
43saDeclarePtr(TRMutex_WeakRef);
44
45typedef struct TRMutex_ClassIf {
46 ObjIface* _implements;
47 ObjIface* _parent;
48 size_t _size;
49
50 bool (*registerTask)(_In_ void* self, ComplexTask* task);
51 bool (*canAcquire)(_In_ void* self, ComplexTask* task);
52 bool (*tryAcquire)(_In_ void* self, ComplexTask* task);
53 void (*release)(_In_ void* self, ComplexTask* task);
54 void (*wakeup)(_In_ void* self);
55} TRMutex_ClassIf;
56extern TRMutex_ClassIf TRMutex_ClassIf_tmpl;
57
61typedef struct TRMutex {
62 union {
63 TRMutex_ClassIf* _;
64 void* _is_TRMutex;
65 void* _is_TaskResource;
66 void* _is_ObjInst;
67 };
68 ObjClassInfo* _clsinfo;
69 atomic(uintptr) _ref;
70 atomic(ptr) _weakref;
71
72 Mutex mtx;
73 Mutex _wlmtx;
74 hashtable _waitlist;
75} TRMutex;
76extern ObjClassInfo TRMutex_clsinfo;
77#define TRMutex(inst) ((TRMutex*)(unused_noeval((inst) && &((inst)->_is_TRMutex)), (inst)))
78#define TRMutexNone ((TRMutex*)NULL)
79
80typedef struct TRMutex_WeakRef {
81 union {
82 ObjInst* _inst;
83 void* _is_TRMutex_WeakRef;
84 void* _is_TaskResource_WeakRef;
85 void* _is_ObjInst_WeakRef;
86 };
87 atomic(uintptr) _ref;
88 RWLock _lock;
89} TRMutex_WeakRef;
90#define TRMutex_WeakRef(inst) ((TRMutex_WeakRef*)(unused_noeval((inst) && &((inst)->_is_TRMutex_WeakRef)), (inst)))
91
92_objfactory_guaranteed TRMutex* TRMutex_create();
97#define trmutexCreate() TRMutex_create()
98
99// bool trmutexRegisterTask(TRMutex* self, ComplexTask* task);
100#define trmutexRegisterTask(self, task) (self)->_->registerTask(TRMutex(self), ComplexTask(task))
101// bool trmutexCanAcquire(TRMutex* self, ComplexTask* task);
102#define trmutexCanAcquire(self, task) (self)->_->canAcquire(TRMutex(self), ComplexTask(task))
103// bool trmutexTryAcquire(TRMutex* self, ComplexTask* task);
104#define trmutexTryAcquire(self, task) (self)->_->tryAcquire(TRMutex(self), ComplexTask(task))
105// void trmutexRelease(TRMutex* self, ComplexTask* task);
106#define trmutexRelease(self, task) (self)->_->release(TRMutex(self), ComplexTask(task))
111#define trmutexWakeup(self) (self)->_->wakeup(TRMutex(self))
112
#define saDeclarePtr(name)
Definition sarray.h:98
#define _objfactory_guaranteed
Definition objimpl.h:104
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.