CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
condvar.h
1#pragma once
2
3#include <cx/cx.h>
4#include "futex.h"
5#include "aspin.h"
6#include "mutex.h"
7
8// Condition variable: A cross between an event and a mutex
9
10enum CONDVAR_Flags {
11 CONDVAR_NoSpin = 1, // do not use adaptive spin, use kernel futex only
12};
13
14typedef struct CondVar {
15 Futex seq;
16 atomic(uint32) lastseq;
17 AdaptiveSpin aspin;
18} CondVar;
19
20void _cvarInit(_Out_ CondVar *cv, uint32 flags);
21#define cvarInit(cv, ...) _cvarInit(cv, opt_flags(__VA_ARGS__))
22
23void cvarDestroy(_Inout_ CondVar *cv);
24
25_Requires_lock_held_(*m)
26bool cvarWaitTimeout(_Inout_ CondVar *cv, _Inout_ Mutex *m, int64 timeout);
27_Requires_lock_held_(*m)
28_meta_inline bool cvarWait(_Inout_ CondVar *cv, _Inout_ Mutex *m)
29{
30 return cvarWaitTimeout(cv, m, timeForever);
31}
32bool cvarSignal(_Inout_ CondVar *cv);
33bool cvarBroadcast(_Inout_ CondVar *cv);
#define timeForever
Maximum representable time value (approximately year 294,276 CE)
Definition time.h:13
Mutex synchronization primitive.
Definition mutex.h:60