rustix_futex_sync/
raw_rwlock.rs

1use crate::lock_api;
2
3/// An implementation of [`lock_api::RawRwLock`].
4///
5/// All of this `RawRwLock`'s methods are in its implementation of
6/// [`lock_api::RawRwLock`]. To import that trait without conflicting
7/// with this `RawRwLock` type, use:
8///
9/// ```
10/// use rustix_futex_sync::lock_api::RawRwLock as _;
11/// ```
12#[repr(C)]
13pub struct RawRwLock<const SHM: bool>(crate::futex_rwlock::RwLock<SHM>);
14
15unsafe impl<const SHM: bool> lock_api::RawRwLock for RawRwLock<SHM> {
16    type GuardMarker = lock_api::GuardNoSend;
17
18    const INIT: Self = Self(crate::futex_rwlock::RwLock::new());
19
20    #[inline]
21    fn lock_shared(&self) {
22        self.0.read()
23    }
24
25    #[inline]
26    fn try_lock_shared(&self) -> bool {
27        self.0.try_read()
28    }
29
30    #[inline]
31    unsafe fn unlock_shared(&self) {
32        self.0.read_unlock()
33    }
34
35    #[inline]
36    fn lock_exclusive(&self) {
37        self.0.write()
38    }
39
40    #[inline]
41    fn try_lock_exclusive(&self) -> bool {
42        self.0.try_write()
43    }
44
45    #[inline]
46    unsafe fn unlock_exclusive(&self) {
47        self.0.write_unlock()
48    }
49}