Skip to content

Commit c4c6914

Browse files
committed
Always return false in futex_wake on {Free,DragonFly}BSD.
1 parent 0b4df22 commit c4c6914

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -
104104
///
105105
/// Returns true if this actually woke up such a thread,
106106
/// or false if no thread was waiting on this futex.
107+
///
108+
/// On some platforms, this always returns false.
107109
#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
108110
pub fn futex_wake(futex: &AtomicU32) -> bool {
109111
let ptr = futex as *const AtomicU32;
@@ -135,9 +137,9 @@ pub fn futex_wake_all(futex: &AtomicU32) {
135137
}
136138
}
137139

138-
// FreeBSD doesn't tell us how many threads are woken up, so this doesn't return a bool.
140+
// FreeBSD doesn't tell us how many threads are woken up, so this always returns false.
139141
#[cfg(target_os = "freebsd")]
140-
pub fn futex_wake(futex: &AtomicU32) {
142+
pub fn futex_wake(futex: &AtomicU32) -> bool {
141143
use crate::ptr::null_mut;
142144
unsafe {
143145
libc::_umtx_op(
@@ -148,6 +150,7 @@ pub fn futex_wake(futex: &AtomicU32) {
148150
null_mut(),
149151
)
150152
};
153+
false
151154
}
152155

153156
#[cfg(target_os = "freebsd")]
@@ -231,10 +234,11 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -
231234
r == 0 || super::os::errno() != libc::ETIMEDOUT
232235
}
233236

234-
// DragonflyBSD doesn't tell us how many threads are woken up, so this doesn't return a bool.
237+
// DragonflyBSD doesn't tell us how many threads are woken up, so this always returns false.
235238
#[cfg(target_os = "dragonfly")]
236-
pub fn futex_wake(futex: &AtomicU32) {
239+
pub fn futex_wake(futex: &AtomicU32) -> bool {
237240
unsafe { libc::umtx_wakeup(futex as *const AtomicU32 as *const i32, 1) };
241+
false
238242
}
239243

240244
#[cfg(target_os = "dragonfly")]

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,11 @@ impl RwLock {
283283
/// writer that was about to go to sleep.
284284
fn wake_writer(&self) -> bool {
285285
self.writer_notify.fetch_add(1, Release);
286-
cfg_if::cfg_if! {
287-
if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] {
288-
// FreeBSD and DragonFlyBSD don't tell us whether they woke up any threads or not.
289-
// So, we always return `false` here, as that still results in correct behaviour.
290-
// The downside is an extra syscall in case both readers and writers were waiting,
291-
// and unnecessarily waking up readers when a writer is about to attempt to lock the lock.
292-
futex_wake(&self.writer_notify);
293-
false
294-
} else {
295-
futex_wake(&self.writer_notify)
296-
}
297-
}
286+
futex_wake(&self.writer_notify)
287+
// Note that FreeBSD and DragonFlyBSD don't tell us whether they woke
288+
// up any threads or not, and always return `false` here. That still
289+
// results in correct behaviour: it just means readers get woken up as
290+
// well in case both readers and writers were waiting.
298291
}
299292

300293
/// Spin for a while, but stop directly at the given condition.

0 commit comments

Comments
 (0)