nx_cond.nx
buildroot/runtime/nx_cond.nx
about
nx_cond.nx -- condition variable on top of nx_mutex + futex.
Condition variables let a thread block until another thread
signals "the condition you were waiting on is now true". The
classic producer/consumer pattern:
producer: consumer:
mutex.lock mutex.lock
queue.push(item) while queue.empty:
cond.signal cond.wait(mutex) # atomic unlock+sleep
mutex.unlock item = queue.pop
mutex.unlock
Implementation uses Linux futex with a sequence counter. Each
nx_cond_wait reads the current seq, drops the mutex, blocks on
futex(seq), then reacquires the mutex on wakeup. signal/broadcast
bump seq + futex_wake.
Pairs with nx_mutex (the lock you must hold when calling wait /
signal) + nx_atom (eventual SMP correctness).
dependencies 2 imports · 0 importers
imports: syscalls.nxnx_mutex.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 37 | struct NxCond |
consts
| 31 | const NX_SYS_FUTEX_2: i64 = 98 |
| 33 | const NX_FUTEX_WAIT_2: i64 = 0 |
| 34 | const NX_FUTEX_WAKE_2: i64 = 1 |
| 35 | const NX_FUTEX_PRIVATE_2: i64 = 128 |
| 41 | const NX_COND_BYTES: i64 = 8 |
functions
| 43 | func nx_cond_new() -> *NxCond called by 1: main |
| 52 | func nx_cond_wait(c: *NxCond, m: *NxMutex) -> i64 |
| 64 | func nx_cond_signal(c: *NxCond) -> i64 called by 1: main |
| 71 | func nx_cond_broadcast(c: *NxCond) -> i64 called by 1: main |
| 79 | func main() -> i64 |