Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 46bb073

Browse files
committed
SeqCst->{Release,Acquire} for wasm DropLock.
SeqCst is unnecessary. Release+Acquire is the right ordering for a mutex.
1 parent e43aef0 commit 46bb073

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

library/std/src/sys/pal/wasm/alloc.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,18 @@ unsafe impl GlobalAlloc for System {
5757

5858
#[cfg(target_feature = "atomics")]
5959
mod lock {
60-
use crate::sync::atomic::{AtomicI32, Ordering::SeqCst};
60+
use crate::sync::atomic::{
61+
AtomicI32,
62+
Ordering::{Acquire, Release},
63+
};
6164

6265
static LOCKED: AtomicI32 = AtomicI32::new(0);
6366

6467
pub struct DropLock;
6568

6669
pub fn lock() -> DropLock {
6770
loop {
68-
if LOCKED.swap(1, SeqCst) == 0 {
71+
if LOCKED.swap(1, Acquire) == 0 {
6972
return DropLock;
7073
}
7174
// Ok so here's where things get a little depressing. At this point
@@ -143,7 +146,7 @@ mod lock {
143146

144147
impl Drop for DropLock {
145148
fn drop(&mut self) {
146-
let r = LOCKED.swap(0, SeqCst);
149+
let r = LOCKED.swap(0, Release);
147150
debug_assert_eq!(r, 1);
148151

149152
// Note that due to the above logic we don't actually need to wake

0 commit comments

Comments
 (0)