rustix_futex_sync/
raw_mutex.rs

1use crate::lock_api;
2
3/// An implementation of [`lock_api::RawMutex`].
4///
5/// All of this `RawMutex`'s methods are in its implementation of
6/// [`lock_api::RawMutex`]. To import that trait without conflicting
7/// with this `RawMutex` type, use:
8///
9/// ```
10/// use rustix_futex_sync::lock_api::RawMutex as _;
11/// ```
12#[repr(transparent)]
13pub struct RawMutex<const SHM: bool>(crate::futex_mutex::Mutex<SHM>);
14
15unsafe impl<const SHM: bool> lock_api::RawMutex for RawMutex<SHM> {
16    type GuardMarker = lock_api::GuardNoSend;
17
18    const INIT: Self = Self(crate::futex_mutex::Mutex::new());
19
20    #[inline]
21    fn lock(&self) {
22        self.0.lock()
23    }
24
25    #[inline]
26    fn try_lock(&self) -> bool {
27        self.0.try_lock()
28    }
29
30    #[inline]
31    unsafe fn unlock(&self) {
32        self.0.unlock()
33    }
34}