diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2024-03-19 15:03:58 +0100 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2024-03-19 15:27:11 +0100 |
| commit | 46bb0734235bd25be5beb0c11e73c61905f5044b (patch) | |
| tree | 7be710bf9ae964a0887868163e1fbcc5206ee312 | |
| parent | e43aef0ef9cc9d2d12c138b36fd817f7c41d0152 (diff) | |
| download | rust-46bb0734235bd25be5beb0c11e73c61905f5044b.tar.gz rust-46bb0734235bd25be5beb0c11e73c61905f5044b.zip | |
SeqCst->{Release,Acquire} for wasm DropLock.
SeqCst is unnecessary. Release+Acquire is the right ordering for a mutex.
| -rw-r--r-- | library/std/src/sys/pal/wasm/alloc.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/library/std/src/sys/pal/wasm/alloc.rs b/library/std/src/sys/pal/wasm/alloc.rs index 6dceb1689a8..b74ce0d4742 100644 --- a/library/std/src/sys/pal/wasm/alloc.rs +++ b/library/std/src/sys/pal/wasm/alloc.rs @@ -57,7 +57,10 @@ unsafe impl GlobalAlloc for System { #[cfg(target_feature = "atomics")] mod lock { - use crate::sync::atomic::{AtomicI32, Ordering::SeqCst}; + use crate::sync::atomic::{ + AtomicI32, + Ordering::{Acquire, Release}, + }; static LOCKED: AtomicI32 = AtomicI32::new(0); @@ -65,7 +68,7 @@ mod lock { pub fn lock() -> DropLock { loop { - if LOCKED.swap(1, SeqCst) == 0 { + if LOCKED.swap(1, Acquire) == 0 { return DropLock; } // Ok so here's where things get a little depressing. At this point @@ -143,7 +146,7 @@ mod lock { impl Drop for DropLock { fn drop(&mut self) { - let r = LOCKED.swap(0, SeqCst); + let r = LOCKED.swap(0, Release); debug_assert_eq!(r, 1); // Note that due to the above logic we don't actually need to wake |
