Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2273,9 +2273,9 @@ checksum = "803ec87c9cfb29b9d2633f20cba1f488db3fd53f2158b1024cbefb47ba05d413"

[[package]]
name = "libc"
version = "0.2.189"
version = "0.2.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"

[[package]]
name = "libffi"
Expand Down Expand Up @@ -2378,9 +2378,9 @@ dependencies = [

[[package]]
name = "linux-raw-sys"
version = "0.11.0"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"

[[package]]
name = "litemap"
Expand Down Expand Up @@ -5191,9 +5191,9 @@ dependencies = [

[[package]]
name = "rustix"
version = "1.1.2"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e"
checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d"
dependencies = [
"bitflags",
"errno",
Expand Down
18 changes: 15 additions & 3 deletions library/std/src/sys/sync/futex/unix.rs
Comment thread
TechnoPorg marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ pub type SmallFutex = Atomic<SmallPrimitive>;
/// Must be the underlying type of SmallFutex
pub type SmallPrimitive = u32;

#[cfg(any(target_os = "linux", target_os = "android"))]
cfg_select! {
// riscv32 only exposes the `SYS_futex_time64` syscall,
// whereas other 32-bit targets also expose `SYS_futex`, which uses 32-bit time.
target_arch = "riscv32" => {
use libc::SYS_futex_time64 as SYS_futex;
}
_ => {
use libc::SYS_futex;
}
}

/// Waits for a `futex_wake` operation to wake us.
///
/// Returns directly if the futex doesn't hold the expected value.
Expand Down Expand Up @@ -61,7 +73,7 @@ pub fn futex_wait(futex: &Atomic<u32>, expected: u32, timeout: Option<Duration>)
// Use FUTEX_WAIT_BITSET rather than FUTEX_WAIT to be able to give an
// absolute time rather than a relative time.
libc::syscall(
libc::SYS_futex,
SYS_futex,
futex as *const Atomic<u32> as *const u32,
libc::FUTEX_WAIT_BITSET | libc::FUTEX_PRIVATE_FLAG,
expected,
Expand Down Expand Up @@ -94,7 +106,7 @@ pub fn futex_wait(futex: &Atomic<u32>, expected: u32, timeout: Option<Duration>)
pub fn futex_wake(futex: &Atomic<u32>) -> bool {
let ptr = futex as *const Atomic<u32> as *const u32;
let op = libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG;
unsafe { libc::syscall(libc::SYS_futex, ptr, op, 1) > 0 }
unsafe { libc::syscall(SYS_futex, ptr, op, 1) > 0 }
}

/// Wakes up all threads that are waiting on `futex_wait` on this futex.
Expand All @@ -103,7 +115,7 @@ pub fn futex_wake_all(futex: &Atomic<u32>) {
let ptr = futex as *const Atomic<u32> as *const u32;
let op = libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG;
unsafe {
libc::syscall(libc::SYS_futex, ptr, op, i32::MAX);
libc::syscall(SYS_futex, ptr, op, i32::MAX);
}
}

Expand Down
Loading