34#include <cx/utils/macros.h>
51void _semaInit(_Out_
Semaphore* sema, int32 count, uint32 flags);
61#define semaInit(sema, count, ...) _semaInit(sema, count, opt_flags(__VA_ARGS__))
89 int32 curcount = atomicLoad(int32, &sema->ftx.val, Relaxed);
90 bool ret = (curcount > 0 &&
91 atomicCompareExchange(int32,
99 aspinRecordUncontended(&sema->aspin);
122 atomicFetchAdd(int32, &sema->ftx.val, count, Release);
123 futexWakeMany(&sema->ftx, count);
bool semaTryDec(Semaphore *sema)
bool semaInc(Semaphore *sema, int32 count)
bool semaDec(Semaphore *sema)
bool semaTryDecTimeout(Semaphore *sema, int64 timeout)
bool semaDestroy(Semaphore *sema)
SEMA_Flags
Semaphore initialization flags.
@ SEMA_NoSpin
Disable adaptive spinning, use kernel futex immediately.
#define timeForever
Maximum representable time value (approximately year 294,276 CE)
Counting semaphore synchronization primitive.
AdaptiveSpin aspin
Adaptive spin state.
Futex ftx
Futex holding the current count.
Time manipulation and conversion functions.