CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1
37
38#pragma once
39
40#include <cx/cx.h>
41#include "aspin.h"
42#include "futex.h"
43
44CX_C_BEGIN
45
46typedef struct UIEvent UIEvent;
47
53typedef struct Event {
54 Futex ftx;
55 atomic(int32) waiters;
56 AdaptiveSpin aspin;
57 UIEvent* uiev;
59
65
97typedef struct SharedEvent {
99 atomic(uintptr) ref;
101
102void _eventInit(_Out_ Event* e, uint32 flags);
103
117#define eventInit(e, ...) _eventInit(e, opt_flags(__VA_ARGS__))
118
125#define eventSignal(e) eventSignalMany(e, 1)
126
134bool eventSignalMany(_Inout_ Event* e, int32 count);
135
142bool eventSignalAll(_Inout_ Event* e);
143
154bool eventWaitTimeout(_Inout_ Event* e, uint64 timeout);
155
160_meta_inline void eventWait(_Inout_ Event* e)
161{
163}
164
172bool eventSignalLock(_Inout_ Event* e);
173
180bool eventReset(_Inout_ Event* e);
181
187void eventDestroy(_Pre_valid_ _Post_invalid_ Event* e);
188
195_Ret_valid_ SharedEvent* sheventCreate(uint32 flags);
196
204
210_At_(*pev, _Pre_maybenull_ _Post_null_) void sheventRelease(_Inout_ SharedEvent** pev);
211
212CX_C_END
213
215// end of thread_event group
bool eventWaitTimeout(Event *e, uint64 timeout)
SharedEvent * sheventCreate(uint32 flags)
bool eventReset(Event *e)
bool eventSignalAll(Event *e)
void eventWait(Event *e)
Definition event.h:160
void sheventRelease(SharedEvent **pev)
bool eventSignalLock(Event *e)
void eventDestroy(Event *e)
EVENTINITFUNC_FLAGS
Event initialization flags.
Definition event.h:61
SharedEvent * sheventAcquire(SharedEvent *ev)
bool eventSignalMany(Event *e, int32 count)
@ EV_UIEvent
May be woken up early by platform-specific UI events.
Definition event.h:63
@ EV_Spin
Use adaptive spinning instead of going straight to kernel wait.
Definition event.h:62
#define timeForever
Maximum representable time value (approximately year 294,276 CE)
Definition time.h:13
Definition event.h:53
AdaptiveSpin aspin
Adaptive spin state (disabled by default)
Definition event.h:56
atomic(int32) waiters
Number of threads currently waiting.
UIEvent * uiev
Platform-specific UI event integration (optional)
Definition event.h:57
Futex ftx
Futex for kernel-level synchronization.
Definition event.h:54
Event ev
Underlying event.
Definition event.h:98
atomic(uintptr) ref
Reference count.