Skip to content

Commit 38b0f1b

Browse files
committed
Implement condvar using futex requeue in OpenBSD
1 parent 7943238 commit 38b0f1b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ pub fn futex_wake_all(futex: &AtomicU32) {
202202
}
203203
}
204204

205+
/// Wakes one waiter on `futex` and requeue the remaining waiters to `futex2`.
206+
#[cfg(target_os = "openbsd")]
207+
pub fn futex_requeue(futex: &AtomicU32, futex2: &AtomicU32) {
208+
use crate::ptr::null;
209+
unsafe {
210+
libc::futex(
211+
futex as *const AtomicU32 as *mut u32,
212+
libc::FUTEX_REQUEUE,
213+
1,
214+
null::<libc::timespec>().with_addr(i32::MAX as usize),
215+
futex2 as *const AtomicU32 as *mut u32,
216+
);
217+
}
218+
}
219+
205220
#[cfg(target_os = "dragonfly")]
206221
pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool {
207222
// A timeout of 0 means infinite.

library/std/src/sys/sync/condvar/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
cfg_if::cfg_if! {
2-
if #[cfg(any(target_os = "linux", target_os = "android"))] {
2+
if #[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))] {
33
mod futex_requeue;
44
pub use futex_requeue::Condvar;
55
} else if #[cfg(any(
66
all(target_os = "windows", not(target_vendor="win7")),
77
target_os = "freebsd",
8-
target_os = "openbsd",
98
target_os = "dragonfly",
109
target_os = "fuchsia",
1110
all(target_family = "wasm", target_feature = "atomics"),

0 commit comments

Comments
 (0)