-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #96040 - m-ou-se:futex-u32, r=Amanieu
Use u32 instead of i32 for futexes. This changes futexes from i32 to u32. The [Linux man page](https://man7.org/linux/man-pages/man2/futex.2.html) uses `uint32_t` for them, so I'm not sure why I used i32 for them. Maybe because I first used them for thread parkers, where I used -1, 0, and 1 as the states. (Wasm's `memory.atomic.wait32` does use `i32`, because wasm doesn't support `u32`.) It doesn't matter much, but using the unsigned type probably results in fewer surprises when shifting bits around or using comparison operators. r? ```@Amanieu```
- Loading branch information
Showing
5 changed files
with
55 additions
and
53 deletions.
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
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
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 |
---|---|---|
@@ -1,17 +1,21 @@ | ||
use crate::arch::wasm32; | ||
use crate::convert::TryInto; | ||
use crate::sync::atomic::AtomicI32; | ||
use crate::sync::atomic::AtomicU32; | ||
use crate::time::Duration; | ||
|
||
pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) { | ||
pub fn futex_wait(futex: &AtomicU32, expected: u32, 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); | ||
wasm32::memory_atomic_wait32( | ||
futex as *const AtomicU32 as *mut i32, | ||
expected as i32, | ||
timeout, | ||
); | ||
} | ||
} | ||
|
||
pub fn futex_wake(futex: &AtomicI32) { | ||
pub fn futex_wake(futex: &AtomicU32) { | ||
unsafe { | ||
wasm32::memory_atomic_notify(futex as *const AtomicI32 as *mut i32, 1); | ||
wasm32::memory_atomic_notify(futex as *const AtomicU32 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