From 4f2ad301f77a669780b2e0142116065e5bd11621 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 27 Aug 2024 12:02:48 -0700 Subject: [PATCH] Update to rustix 0.38.35 and the new futex API. (#13) --- Cargo.toml | 3 +-- src/lib.rs | 6 +++--- src/wait_wake.rs | 56 ++++++++++++++---------------------------------- 3 files changed, 20 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ffca143..5293467 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ include = ["src", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md"] rust-version = "1.70" [dependencies] -rustix = { version = "0.38.34", default-features = false, features = ["thread", "time"] } +rustix = { version = "0.38.35", default-features = false, features = ["thread", "time"] } lock_api = { version = "0.4.7", default-features = false, optional = true } # Special dependencies used in rustc-dep-of-std mode. @@ -38,4 +38,3 @@ rustc-dep-of-std = [ [package.metadata.docs.rs] features = ["atomic_usize"] -rustdoc-args = ["--cfg", "doc_cfg"] diff --git a/src/lib.rs b/src/lib.rs index aaf358b..956ee88 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ #![doc = include_str!("../README.md")] #![no_std] -#![cfg_attr(doc_cfg, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] // Re-export this so that our users can use the same version we do. #[cfg(feature = "lock_api")] @@ -29,11 +29,11 @@ pub type MappedRwLockReadGuard<'a, T> = lock_api::MappedRwLockReadGuard<'a, RawR pub type MappedRwLockWriteGuard<'a, T> = lock_api::MappedRwLockWriteGuard<'a, RawRwLock, T>; #[cfg(feature = "lock_api")] #[cfg(feature = "atomic_usize")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "atomic_usize")))] +#[cfg_attr(docsrs, doc(cfg(feature = "atomic_usize")))] pub type ReentrantMutex = lock_api::ReentrantMutex; #[cfg(feature = "lock_api")] #[cfg(feature = "atomic_usize")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "atomic_usize")))] +#[cfg_attr(docsrs, doc(cfg(feature = "atomic_usize")))] pub type ReentrantMutexGuard<'a, G, T> = lock_api::ReentrantMutexGuard<'a, RawMutex, G, T>; // Export the once types. diff --git a/src/wait_wake.rs b/src/wait_wake.rs index d88cfab..e9af022 100644 --- a/src/wait_wake.rs +++ b/src/wait_wake.rs @@ -2,9 +2,10 @@ //! library/std/src/sys/pal/unix/futex.rs at revision //! b58f647d5488dce73bba517907c44af2c2a618c4. +use core::num::NonZeroU32; use core::sync::atomic::AtomicU32; use core::time::Duration; -use rustix::thread::{FutexFlags, FutexOperation}; +use rustix::thread::futex; use rustix::time::{ClockId, Timespec}; /// Wait for a futex_wake operation to wake us. @@ -36,7 +37,6 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option) - /// This allows callers that don't need the timeout to pass `None` and avoid /// statically depending on `clock_gettime`. pub fn futex_wait_timespec(futex: &AtomicU32, expected: u32, timespec: Option) -> bool { - use core::ptr::{null, null_mut}; use core::sync::atomic::Ordering::Relaxed; loop { @@ -45,19 +45,18 @@ pub fn futex_wait_timespec(futex: &AtomicU32, expected: u32, timespec: Option return false, @@ -72,36 +71,13 @@ pub fn futex_wait_timespec(futex: &AtomicU32, expected: u32, timespec: Option bool { - use core::ptr::{null, null_mut}; - unsafe { - match rustix::thread::futex( - futex.as_ptr(), - FutexOperation::Wake, - FutexFlags::PRIVATE, - 1, - null(), - null_mut(), - 0, - ) { - Err(_) | Ok(0) => false, - _ => true, - } + match futex::wake(futex, futex::Flags::PRIVATE, 1) { + Err(_) | Ok(0) => false, + _ => true, } } /// Wake up all threads that are waiting on futex_wait on this futex. pub fn futex_wake_all(futex: &AtomicU32) { - use core::ptr::{null, null_mut}; - unsafe { - rustix::thread::futex( - futex.as_ptr(), - FutexOperation::Wake, - FutexFlags::PRIVATE, - i32::MAX as u32, - null(), - null_mut(), - 0, - ) - .ok(); - } + futex::wake(futex, futex::Flags::PRIVATE, i32::MAX as u32).ok(); }