Skip to content

Commit 7b7d1d6

Browse files
committed
Don't use futexes on netbsd.
The latest NetBSD release doesn't include the futex syscall yet.
1 parent 1b9c7e6 commit 7b7d1d6

File tree

4 files changed

+5
-44
lines changed

4 files changed

+5
-44
lines changed

library/std/src/sys/unix/futex.rs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,18 @@
44
all(target_os = "emscripten", target_feature = "atomics"),
55
target_os = "freebsd",
66
target_os = "openbsd",
7-
target_os = "netbsd",
87
target_os = "dragonfly",
98
))]
109

1110
use crate::sync::atomic::AtomicU32;
1211
use crate::time::Duration;
1312

14-
#[cfg(target_os = "netbsd")]
15-
pub const SYS___futex: i32 = 166;
16-
1713
/// Wait for a futex_wake operation to wake us.
1814
///
1915
/// Returns directly if the futex doesn't hold the expected value.
2016
///
2117
/// Returns false on timeout, and true in all other cases.
22-
#[cfg(any(
23-
target_os = "linux",
24-
target_os = "android",
25-
target_os = "freebsd",
26-
target_os = "netbsd"
27-
))]
18+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
2819
pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool {
2920
use super::time::Timespec;
3021
use crate::ptr::null;
@@ -65,19 +56,6 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -
6556
crate::ptr::invalid_mut(umtx_timeout_size),
6657
umtx_timeout_ptr as *mut _,
6758
)
68-
} else if #[cfg(target_os = "netbsd")] {
69-
// Netbsd's futex syscall takes addr2 and val2 as separate arguments.
70-
// (Both are unused for FUTEX_WAIT[_BITSET].)
71-
libc::syscall(
72-
SYS___futex,
73-
futex as *const AtomicU32,
74-
libc::FUTEX_WAIT_BITSET | libc::FUTEX_PRIVATE_FLAG,
75-
expected,
76-
timespec.as_ref().map_or(null(), |t| &t.t as *const libc::timespec),
77-
null::<u32>(), // addr2: This argument is unused for FUTEX_WAIT_BITSET.
78-
0, // val2: This argument is unused for FUTEX_WAIT_BITSET.
79-
!0u32, // val3 / bitmask: A full bitmask, to make it behave like a regular FUTEX_WAIT.
80-
)
8159
} else {
8260
libc::syscall(
8361
libc::SYS_futex,
@@ -106,34 +84,20 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -
10684
/// or false if no thread was waiting on this futex.
10785
///
10886
/// On some platforms, this always returns false.
109-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
87+
#[cfg(any(target_os = "linux", target_os = "android"))]
11088
pub fn futex_wake(futex: &AtomicU32) -> bool {
11189
let ptr = futex as *const AtomicU32;
11290
let op = libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG;
113-
unsafe {
114-
cfg_if::cfg_if! {
115-
if #[cfg(target_os = "netbsd")] {
116-
libc::syscall(SYS___futex, ptr, op, 1) > 0
117-
} else {
118-
libc::syscall(libc::SYS_futex, ptr, op, 1) > 0
119-
}
120-
}
121-
}
91+
unsafe { libc::syscall(libc::SYS_futex, ptr, op, 1) > 0 }
12292
}
12393

12494
/// Wake up all threads that are waiting on futex_wait on this futex.
125-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
95+
#[cfg(any(target_os = "linux", target_os = "android"))]
12696
pub fn futex_wake_all(futex: &AtomicU32) {
12797
let ptr = futex as *const AtomicU32;
12898
let op = libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG;
12999
unsafe {
130-
cfg_if::cfg_if! {
131-
if #[cfg(target_os = "netbsd")] {
132-
libc::syscall(SYS___futex, ptr, op, i32::MAX);
133-
} else {
134-
libc::syscall(libc::SYS_futex, ptr, op, i32::MAX);
135-
}
136-
}
100+
libc::syscall(libc::SYS_futex, ptr, op, i32::MAX);
137101
}
138102
}
139103

library/std/src/sys/unix/locks/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ cfg_if::cfg_if! {
55
all(target_os = "emscripten", target_feature = "atomics"),
66
target_os = "freebsd",
77
target_os = "openbsd",
8-
target_os = "netbsd",
98
target_os = "dragonfly",
109
))] {
1110
mod futex;

library/std/src/sys/unix/thread_parker.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
all(target_os = "emscripten", target_feature = "atomics"),
77
target_os = "freebsd",
88
target_os = "openbsd",
9-
target_os = "netbsd",
109
target_os = "dragonfly",
1110
)))]
1211

library/std/src/sys_common/thread_parker/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ cfg_if::cfg_if! {
55
all(target_arch = "wasm32", target_feature = "atomics"),
66
target_os = "freebsd",
77
target_os = "openbsd",
8-
target_os = "netbsd",
98
target_os = "dragonfly",
109
))] {
1110
mod futex;

0 commit comments

Comments
 (0)