diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2022-05-03 09:08:38 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2022-05-03 12:26:17 +0200 |
| commit | 7b7d1d6c4835d4e84517cc825aacb817d6435696 (patch) | |
| tree | 0208f4a2da770cecbb84447f3e08599b6f6acb82 | |
| parent | 1b9c7e6f1a0283c2374760efcac55aad96d10ac6 (diff) | |
| download | rust-7b7d1d6c4835d4e84517cc825aacb817d6435696.tar.gz rust-7b7d1d6c4835d4e84517cc825aacb817d6435696.zip | |
Don't use futexes on netbsd.
The latest NetBSD release doesn't include the futex syscall yet.
| -rw-r--r-- | library/std/src/sys/unix/futex.rs | 46 | ||||
| -rw-r--r-- | library/std/src/sys/unix/locks/mod.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/unix/thread_parker.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys_common/thread_parker/mod.rs | 1 |
4 files changed, 5 insertions, 44 deletions
diff --git a/library/std/src/sys/unix/futex.rs b/library/std/src/sys/unix/futex.rs index fd046bdf19d..f91367da89c 100644 --- a/library/std/src/sys/unix/futex.rs +++ b/library/std/src/sys/unix/futex.rs @@ -4,27 +4,18 @@ all(target_os = "emscripten", target_feature = "atomics"), target_os = "freebsd", target_os = "openbsd", - target_os = "netbsd", target_os = "dragonfly", ))] use crate::sync::atomic::AtomicU32; use crate::time::Duration; -#[cfg(target_os = "netbsd")] -pub const SYS___futex: i32 = 166; - /// Wait for a futex_wake operation to wake us. /// /// Returns directly if the futex doesn't hold the expected value. /// /// Returns false on timeout, and true in all other cases. -#[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "freebsd", - target_os = "netbsd" -))] +#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))] pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool { use super::time::Timespec; use crate::ptr::null; @@ -65,19 +56,6 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) - crate::ptr::invalid_mut(umtx_timeout_size), umtx_timeout_ptr as *mut _, ) - } else if #[cfg(target_os = "netbsd")] { - // Netbsd's futex syscall takes addr2 and val2 as separate arguments. - // (Both are unused for FUTEX_WAIT[_BITSET].) - libc::syscall( - SYS___futex, - futex as *const AtomicU32, - libc::FUTEX_WAIT_BITSET | libc::FUTEX_PRIVATE_FLAG, - expected, - timespec.as_ref().map_or(null(), |t| &t.t as *const libc::timespec), - null::<u32>(), // addr2: This argument is unused for FUTEX_WAIT_BITSET. - 0, // val2: This argument is unused for FUTEX_WAIT_BITSET. - !0u32, // val3 / bitmask: A full bitmask, to make it behave like a regular FUTEX_WAIT. - ) } else { libc::syscall( libc::SYS_futex, @@ -106,34 +84,20 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) - /// or false if no thread was waiting on this futex. /// /// On some platforms, this always returns false. -#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))] +#[cfg(any(target_os = "linux", target_os = "android"))] pub fn futex_wake(futex: &AtomicU32) -> bool { let ptr = futex as *const AtomicU32; let op = libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG; - unsafe { - cfg_if::cfg_if! { - if #[cfg(target_os = "netbsd")] { - libc::syscall(SYS___futex, ptr, op, 1) > 0 - } else { - libc::syscall(libc::SYS_futex, ptr, op, 1) > 0 - } - } - } + unsafe { libc::syscall(libc::SYS_futex, ptr, op, 1) > 0 } } /// Wake up all threads that are waiting on futex_wait on this futex. -#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))] +#[cfg(any(target_os = "linux", target_os = "android"))] pub fn futex_wake_all(futex: &AtomicU32) { let ptr = futex as *const AtomicU32; let op = libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG; unsafe { - cfg_if::cfg_if! { - if #[cfg(target_os = "netbsd")] { - libc::syscall(SYS___futex, ptr, op, i32::MAX); - } else { - libc::syscall(libc::SYS_futex, ptr, op, i32::MAX); - } - } + libc::syscall(libc::SYS_futex, ptr, op, i32::MAX); } } diff --git a/library/std/src/sys/unix/locks/mod.rs b/library/std/src/sys/unix/locks/mod.rs index 27d007a1051..04c5c489fc9 100644 --- a/library/std/src/sys/unix/locks/mod.rs +++ b/library/std/src/sys/unix/locks/mod.rs @@ -5,7 +5,6 @@ cfg_if::cfg_if! { all(target_os = "emscripten", target_feature = "atomics"), target_os = "freebsd", target_os = "openbsd", - target_os = "netbsd", target_os = "dragonfly", ))] { mod futex; diff --git a/library/std/src/sys/unix/thread_parker.rs b/library/std/src/sys/unix/thread_parker.rs index 0da132337de..cf37c01598b 100644 --- a/library/std/src/sys/unix/thread_parker.rs +++ b/library/std/src/sys/unix/thread_parker.rs @@ -6,7 +6,6 @@ all(target_os = "emscripten", target_feature = "atomics"), target_os = "freebsd", target_os = "openbsd", - target_os = "netbsd", target_os = "dragonfly", )))] diff --git a/library/std/src/sys_common/thread_parker/mod.rs b/library/std/src/sys_common/thread_parker/mod.rs index 5305f1f2dee..c789a388e05 100644 --- a/library/std/src/sys_common/thread_parker/mod.rs +++ b/library/std/src/sys_common/thread_parker/mod.rs @@ -5,7 +5,6 @@ cfg_if::cfg_if! { all(target_arch = "wasm32", target_feature = "atomics"), target_os = "freebsd", target_os = "openbsd", - target_os = "netbsd", target_os = "dragonfly", ))] { mod futex; |
