diff options
| author | bors <bors@rust-lang.org> | 2022-04-20 01:34:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-04-20 01:34:43 +0000 |
| commit | a2df8baea6fb7199822d39cfcfddb197604aa8a2 (patch) | |
| tree | 7af4ae85c6eb05003d29f6771f36854747334307 /library/std/src/sys | |
| parent | 4ca19e09d302a4cbde14f9cb1bc109179dc824cd (diff) | |
| parent | da1ddf371c13aed51ae6f81b4dc13ed0d6d58e20 (diff) | |
| download | rust-a2df8baea6fb7199822d39cfcfddb197604aa8a2.tar.gz rust-a2df8baea6fb7199822d39cfcfddb197604aa8a2.zip | |
Auto merge of #96224 - Dylan-DPC:rollup-h2h3j93, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #95740 (asm: Add a kreg0 register class on x86 which includes k0) - #95813 (Remove extra space before a where clause) - #96029 (Refactor loop into iterator; simplify negation logic.) - #96162 (interpret: Fix writing uninit to an allocation) - #96165 (Miri provenance cleanup) - #96205 (Use futex locks on emscripten.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/unix/futex.rs | 47 | ||||
| -rw-r--r-- | library/std/src/sys/unix/locks/mod.rs | 1 |
2 files changed, 26 insertions, 22 deletions
diff --git a/library/std/src/sys/unix/futex.rs b/library/std/src/sys/unix/futex.rs index 62760373a6a..c12ee169e79 100644 --- a/library/std/src/sys/unix/futex.rs +++ b/library/std/src/sys/unix/futex.rs @@ -52,25 +52,6 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) - } } -#[cfg(target_os = "emscripten")] -pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) { - extern "C" { - fn emscripten_futex_wait( - addr: *const AtomicU32, - val: libc::c_uint, - max_wait_ms: libc::c_double, - ) -> libc::c_int; - } - - unsafe { - emscripten_futex_wait( - futex, - expected, - timeout.map_or(crate::f64::INFINITY, |d| d.as_secs_f64() * 1000.0), - ); - } -} - /// Wake up one thread that's blocked on futex_wait on this futex. /// /// Returns true if this actually woke up such a thread, @@ -101,10 +82,32 @@ pub fn futex_wake_all(futex: &AtomicU32) { } #[cfg(target_os = "emscripten")] -pub fn futex_wake(futex: &AtomicU32) -> bool { - extern "C" { - fn emscripten_futex_wake(addr: *const AtomicU32, count: libc::c_int) -> libc::c_int; +extern "C" { + fn emscripten_futex_wake(addr: *const AtomicU32, count: libc::c_int) -> libc::c_int; + fn emscripten_futex_wait( + addr: *const AtomicU32, + val: libc::c_uint, + max_wait_ms: libc::c_double, + ) -> libc::c_int; +} + +#[cfg(target_os = "emscripten")] +pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool { + unsafe { + emscripten_futex_wait( + futex, + expected, + timeout.map_or(f64::INFINITY, |d| d.as_secs_f64() * 1000.0), + ) != -libc::ETIMEDOUT } +} +#[cfg(target_os = "emscripten")] +pub fn futex_wake(futex: &AtomicU32) -> bool { unsafe { emscripten_futex_wake(futex, 1) > 0 } } + +#[cfg(target_os = "emscripten")] +pub fn futex_wake_all(futex: &AtomicU32) { + unsafe { emscripten_futex_wake(futex, i32::MAX) }; +} diff --git a/library/std/src/sys/unix/locks/mod.rs b/library/std/src/sys/unix/locks/mod.rs index 17796f8894b..3e39c8b9b23 100644 --- a/library/std/src/sys/unix/locks/mod.rs +++ b/library/std/src/sys/unix/locks/mod.rs @@ -2,6 +2,7 @@ cfg_if::cfg_if! { if #[cfg(any( target_os = "linux", target_os = "android", + all(target_os = "emscripten", target_feature = "atomics"), ))] { mod futex; mod futex_rwlock; |
