1//! Linux `futex`.
2//!
3//! # Safety
4//!
5//! Futex is a very low-level mechanism for implementing concurrency
6//! primitives.
7#![allow(unsafe_code)]
8
9use crate::thread::Timespec;
10use crate::{backend, io};
11
12pub use backend::thread::futex::{FutexFlags, FutexOperation};
13
14/// `futex(uaddr, op, val, utime, uaddr2, val3)`
15///
16/// # References
17/// - [Linux `futex` system call]
18/// - [Linux `futex` feature]
19///
20/// # Safety
21///
22/// This is a very low-level feature for implementing synchronization
23/// primitives. See the references links above.
24///
25/// [Linux `futex` system call]: https://man7.org/linux/man-pages/man2/futex.2.html
26/// [Linux `futex` feature]: https://man7.org/linux/man-pages/man7/futex.7.html
27#[inline]
28pub unsafe fn futex(
29 uaddr: *mut u32,
30 op: FutexOperation,
31 flags: FutexFlags,
32 val: u32,
33 utime: *const Timespec,
34 uaddr2: *mut u32,
35 val3: u32,
36) -> io::Result<usize> {
37 backend::thread::syscalls::futex(uaddr, op, flags, val, utime, uaddr2, val3)
38}
39