Skip to content

Commit

Permalink
SeqCst->{Release,Acquire} for xous DropLock.
Browse files Browse the repository at this point in the history
SeqCst is unnecessary. Release+Acquire is the right ordering for a
mutex.
  • Loading branch information
m-ou-se committed Mar 19, 2024
1 parent 60ad490 commit 69a4d77
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions library/std/src/sys/pal/xous/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ unsafe impl GlobalAlloc for System {
}

mod lock {
use crate::sync::atomic::{AtomicI32, Ordering::SeqCst};
use crate::sync::atomic::{
AtomicI32,
Ordering::{Acquire, Release},
};

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

pub struct DropLock;

pub fn lock() -> DropLock {
loop {
if LOCKED.swap(1, SeqCst) == 0 {
if LOCKED.swap(1, Acquire) == 0 {
return DropLock;
}
crate::os::xous::ffi::do_yield();
Expand All @@ -63,7 +66,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);
}
}
Expand Down

0 comments on commit 69a4d77

Please sign in to comment.