Skip to content

Commit b5c1c47

Browse files
committed
std: xous: use blocking_scalars for mutex unlock
Use blocking scalars when unlocking a mutex. This ensures that mutexes are unlocked immediately rather than dangling. Signed-off-by: Sean Cross <[email protected]>
1 parent f732d2b commit b5c1c47

File tree

1 file changed

+7
-13
lines changed
  • library/std/src/sys/pal/xous/locks

1 file changed

+7
-13
lines changed

library/std/src/sys/pal/xous/locks/mutex.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::os::xous::ffi::{blocking_scalar, do_yield, scalar};
2-
use crate::os::xous::services::ticktimer_server;
1+
use crate::os::xous::ffi::{blocking_scalar, do_yield};
2+
use crate::os::xous::services::{ticktimer_server, TicktimerScalar};
33
use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering::Relaxed, Ordering::SeqCst};
44

55
pub struct Mutex {
@@ -29,7 +29,7 @@ impl Mutex {
2929
}
3030

3131
fn index(&self) -> usize {
32-
self as *const Mutex as usize
32+
core::ptr::from_ref(self).addr()
3333
}
3434

3535
#[inline]
@@ -83,11 +83,8 @@ impl Mutex {
8383
}
8484

8585
// Unblock one thread that is waiting on this message.
86-
scalar(
87-
ticktimer_server(),
88-
crate::os::xous::services::TicktimerScalar::UnlockMutex(self.index()).into(),
89-
)
90-
.expect("failure to send UnlockMutex command");
86+
blocking_scalar(ticktimer_server(), TicktimerScalar::UnlockMutex(self.index()).into())
87+
.expect("failure to send UnlockMutex command");
9188
}
9289

9390
#[inline]
@@ -106,11 +103,8 @@ impl Drop for Mutex {
106103
// If there was Mutex contention, then we involved the ticktimer. Free
107104
// the resources associated with this Mutex as it is deallocated.
108105
if self.contended.load(Relaxed) {
109-
scalar(
110-
ticktimer_server(),
111-
crate::os::xous::services::TicktimerScalar::FreeMutex(self.index()).into(),
112-
)
113-
.ok();
106+
blocking_scalar(ticktimer_server(), TicktimerScalar::FreeMutex(self.index()).into())
107+
.ok();
114108
}
115109
}
116110
}

0 commit comments

Comments
 (0)