Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Linux Mutex and Condvar with futex based ones. #95035

Merged
merged 14 commits into from
Apr 5, 2022
Merged
Next Next commit
Return timeout status in futex_wait.
m-ou-se committed Mar 23, 2022
commit 4fbd71c94324965f5a3bcf01845b6da0d51076b7
9 changes: 5 additions & 4 deletions library/std/src/sys/unix/futex.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ use crate::sync::atomic::AtomicI32;
use crate::time::Duration;

#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) {
pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) -> bool {
let timespec = timeout.and_then(|d| {
Some(libc::timespec {
// Sleep forever if the timeout is longer than fits in a timespec.
@@ -21,15 +21,16 @@ pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) {
tv_nsec: d.subsec_nanos() as _,
})
});
unsafe {
let r = unsafe {
libc::syscall(
libc::SYS_futex,
futex as *const AtomicI32,
libc::FUTEX_WAIT | libc::FUTEX_PRIVATE_FLAG,
expected,
timespec.as_ref().map_or(null(), |d| d as *const libc::timespec),
);
}
)
};
!(r < 0 && super::os::errno() == libc::ETIMEDOUT)
}

#[cfg(target_os = "emscripten")]