1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/// Wait on a futex.
///
/// - `uaddr`: Address of the futex to wait on
/// - `val`: Value of `uaddr`
/// - `mask`: bitmask
/// - `flags`: `FUTEX2` flags
/// - `timeout`: Optional absolute timeout
/// - `clockid`: Clock to be used for the timeout, realtime or monotonic
///
/// Identical to the traditional `FUTEX_WAIT_BITSET` op, except it is part of the
/// futex2 familiy of calls.
pub unsafe fn futex_wait(
uaddr: *const core::ffi::c_void,
val: usize,
mask: usize,
flags: u32,
timeout: Option<×pec_t>,
clockid: clockid_t,
) -> Result<(), Errno> {
let uaddr = uaddr as usize;
let flags = flags as usize;
let timeout_ptr = timeout.map_or(core::ptr::null::<timespec_t>() as usize, |timeout| {
core::ptr::from_ref(timeout) as usize
});
let clockid = clockid as usize;
unsafe {
syscall6(
SYS_FUTEX_WAIT,
uaddr,
val,
mask,
flags,
timeout_ptr,
clockid,
)
.map(drop)
}
}