forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#77619 - fusion-engineering-forks:wasm-parke…
…r, r=dtolnay Use futex-based thread-parker for Wasm32. This uses the existing `sys_common/thread_parker/futex.rs` futex-based thread parker (that was already used for Linux) for wasm32 as well (if the wasm32 atomics target feature is enabled, which is not the case by default). Wasm32 provides the basic futex operations as instructions: https://webassembly.github.io/threads/syntax/instructions.html These are now exposed from `sys::futex::{futex_wait, futex_wake}`, just like on Linux. So, `thread_parker/futex.rs` stays completely unmodified.
- Loading branch information
Showing
3 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::arch::wasm32; | ||
use crate::convert::TryInto; | ||
use crate::sync::atomic::AtomicI32; | ||
use crate::time::Duration; | ||
|
||
pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) { | ||
let timeout = timeout.and_then(|t| t.as_nanos().try_into().ok()).unwrap_or(-1); | ||
unsafe { | ||
wasm32::memory_atomic_wait32(futex as *const AtomicI32 as *mut i32, expected, timeout); | ||
} | ||
} | ||
|
||
pub fn futex_wake(futex: &AtomicI32) { | ||
unsafe { | ||
wasm32::memory_atomic_notify(futex as *const AtomicI32 as *mut i32, 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters