Cross-platform mutexes, rwlocks, atomic helpers and a tiny bar/ack primitive.
- Arguments:
- microseconds to sleep.
- Does:
- sleeps with
usleep()on POSIX. - uses millisecond-granularity
Sleep()on Windows.
- sleeps with
- Returns:
- no return value.
- Arguments:
- mutex object.
- Does:
- initializes a recursive mutex / critical section and controls it.
- operations are skipped when
bEnabled == XFALSE.
- Returns:
- no return value.
- Failure behavior:
- initialization, destroy, lock and unlock errors print to
stderrand terminate the process.
- initialization, destroy, lock and unlock errors print to
- Arguments:
- rwlock object.
- Does:
- initializes, locks, unlocks and destroys a read/write lock.
- Windows tracks whether the held lock is exclusive so unlock can release the correct SRW mode.
- Returns:
- no return value.
- Failure behavior:
- underlying OS failures print to
stderrand terminate the process.
- underlying OS failures print to
- Arguments:
- bar/ack state object.
- Does:
- set bar and clear ack, set ack, or clear both flags.
- Returns:
- no return value.
- Arguments:
- bar/ack state object.
- Does:
- reads the atomic flag.
- Returns:
XSTDOKwhen the flag is set.XSTDNONotherwise.
- Arguments:
- bar/ack state object.
- optional sleep interval between polls.
- Does:
- busy-waits until ack becomes set.
- Returns:
- approximate waited microseconds.
- These primitives are designed for internal runtime code, not for failure-tolerant library boundaries.
- On Windows,
xusleep()rounds sub-millisecond waits up to at least1 ms.