diff --git a/README.md b/README.md index 3592c5e..f8ce26c 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ Linux futex-based implementations of [`Mutex`], [`RwLock`], [`Condvar`], [`Once`], and [`OnceLock`], as well as [`RawMutex`], [`RawRwLock`], and -[`RawCondvar`], derived from the futex code in std, factored out to -a standalone `no_std` crate using [`rustix`] to do the futex and [`lock_api`] -to provide most of the public API. +[`RawCondvar`], derived from the futex code in std, factored out to a +standalone `no_std` crate using [`rustix`] to do the futex and [`lock_api`] to +provide most of the public `Mutex` and `RwLock` API. `lock_api` does not support poisoning, so support for poisoning is omitted. @@ -29,11 +29,11 @@ these `AtomicU32`s are not documented, except that all these types' [`Mutex`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/type.Mutex.html [`RwLock`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/type.RwLock.html -[`Condvar`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/type.Condvar.html -[`Once`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/type.Once.html -[`OnceLock`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/type.OnceLock.html -[`RawMutex`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/type.RawMutex.html -[`RawRwLock`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/type.RawRwLock.html +[`Condvar`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/struct.Condvar.html +[`Once`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/struct.Once.html +[`OnceLock`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/struct.OnceLock.html +[`RawMutex`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/struct.RawMutex.html +[`RawRwLock`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/struct.RawRwLock.html [`RawCondvar`]: https://docs.rs/rustix-futex-sync/latest/rustix_futex_sync/type.RawCondvar.html [`rustix`]: https://github.com/bytecodealliance/rustix#readme [`lock_api`]: https://crates.io/crates/lock_api diff --git a/src/futex_condvar.rs b/src/futex_condvar.rs index 6b61679..328e717 100644 --- a/src/futex_condvar.rs +++ b/src/futex_condvar.rs @@ -8,8 +8,6 @@ use core::time::Duration; use super::RawMutex; use lock_api::RawMutex as _; -pub type MovableCondvar = Condvar; - #[repr(transparent)] pub struct Condvar { // The value of this atomic is simply incremented on every notification. diff --git a/src/futex_mutex.rs b/src/futex_mutex.rs index 81afa1d..2b2b9e4 100644 --- a/src/futex_mutex.rs +++ b/src/futex_mutex.rs @@ -8,8 +8,6 @@ use core::sync::atomic::{ }; use super::wait_wake::{futex_wait_timespec, futex_wake}; -pub type MovableMutex = Mutex; - #[repr(transparent)] pub struct Mutex { /// 0: unlocked diff --git a/src/futex_rwlock.rs b/src/futex_rwlock.rs index d3030a1..7645ae1 100644 --- a/src/futex_rwlock.rs +++ b/src/futex_rwlock.rs @@ -8,8 +8,6 @@ use core::sync::atomic::{ }; use super::wait_wake::{futex_wait_timespec, futex_wake, futex_wake_all}; -pub type MovableRwLock = RwLock; - #[repr(C)] pub struct RwLock { // The state consists of a 30-bit reader counter, a 'readers waiting' flag, and a 'writers waiting' flag. diff --git a/src/lib.rs b/src/lib.rs index d28e5f6..46d13c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,6 @@ // Re-export this so that our users can use the same version we do. pub use lock_api; -pub type RawCondvar = futex_condvar::MovableCondvar; - // Export convenient `Mutex` and `RwLock` types. pub type Mutex = lock_api::Mutex; pub type RwLock = lock_api::RwLock; @@ -27,9 +25,8 @@ pub use once_lock::OnceLock; // Export the condvar types. pub use condvar::{Condvar, WaitTimeoutResult}; -// The following is derived from Rust's -// library/std/src/sys/unix/locks/mod.rs at revision -// 6fd7e9010db6be7605241c39eab7c5078ee2d5bd. +// Export the raw condvar types. +pub type RawCondvar = futex_condvar::Condvar; // std's implementation code. mod condvar; @@ -41,10 +38,6 @@ mod once; mod once_lock; mod wait_wake; -// Use the raw lock types from std's implementation. -use futex_mutex::MovableMutex; -use futex_rwlock::MovableRwLock; - /// An implementation of [`lock_api::RawMutex`]. /// /// All of this `RawMutex`'s methods are in its implementation of @@ -55,7 +48,7 @@ use futex_rwlock::MovableRwLock; /// use rustix_futex_sync::lock_api::RawMutex as _; /// ``` #[repr(transparent)] -pub struct RawMutex(MovableMutex); +pub struct RawMutex(futex_mutex::Mutex); /// An implementation of [`lock_api::RawRwLock`]. /// @@ -67,23 +60,26 @@ pub struct RawMutex(MovableMutex); /// use rustix_futex_sync::lock_api::RawRwLock as _; /// ``` #[repr(C)] -pub struct RawRwLock(MovableRwLock); +pub struct RawRwLock(futex_rwlock::RwLock); // Implement the raw lock traits for our wrappers. unsafe impl lock_api::RawMutex for RawMutex { type GuardMarker = lock_api::GuardNoSend; - const INIT: Self = Self(MovableMutex::new()); + const INIT: Self = Self(futex_mutex::Mutex::new()); + #[inline] fn lock(&self) { self.0.lock() } + #[inline] fn try_lock(&self) -> bool { self.0.try_lock() } + #[inline] unsafe fn unlock(&self) { self.0.unlock() } @@ -92,28 +88,34 @@ unsafe impl lock_api::RawMutex for RawMutex { unsafe impl lock_api::RawRwLock for RawRwLock { type GuardMarker = lock_api::GuardNoSend; - const INIT: Self = Self(MovableRwLock::new()); + const INIT: Self = Self(futex_rwlock::RwLock::new()); + #[inline] fn lock_shared(&self) { self.0.read() } + #[inline] fn try_lock_shared(&self) -> bool { self.0.try_read() } + #[inline] unsafe fn unlock_shared(&self) { self.0.read_unlock() } + #[inline] fn lock_exclusive(&self) { self.0.write() } + #[inline] fn try_lock_exclusive(&self) -> bool { self.0.try_write() } + #[inline] unsafe fn unlock_exclusive(&self) { self.0.write_unlock() } diff --git a/tests/repr.rs b/tests/repr.rs index dcef223..c4307d3 100644 --- a/tests/repr.rs +++ b/tests/repr.rs @@ -1,5 +1,6 @@ -/// rustix_futex_sync documents some details of the representation of some of -/// its public types. +//! rustix_futex_sync documents some details of the representation of some of +//! its public types. + use core::mem::{align_of, size_of, transmute}; use rustix_futex_sync::lock_api::{RawMutex as _, RawRwLock as _}; use rustix_futex_sync::{Condvar, Once, RawCondvar, RawMutex, RawRwLock};