From 5032708f8864e304b1ff269e98f0f2c390f6cba7 Mon Sep 17 00:00:00 2001 From: elle Date: Mon, 8 Sep 2025 20:22:10 +0000 Subject: [PATCH] redox-rt: fix dead code in `sync` --- redox-rt/src/sync.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/redox-rt/src/sync.rs b/redox-rt/src/sync.rs index 5b56434d70..beae40aa05 100644 --- a/redox-rt/src/sync.rs +++ b/redox-rt/src/sync.rs @@ -11,14 +11,17 @@ pub struct Mutex { pub inner: UnsafeCell, } -const UNLOCKED: u32 = 0; -const LOCKED: u32 = 1; -const WAITING: u32 = 2; - unsafe impl Send for Mutex {} unsafe impl Sync for Mutex {} impl Mutex { + /// Represents an unlocked [Mutex]. + pub const UNLOCKED: u32 = 0; + /// Represents a locked [Mutex]. + pub const LOCKED: u32 = 1; + /// Represents a waiting [Mutex]. + pub const WAITING: u32 = 2; + pub const fn new(t: T) -> Self { Self { lockword: AtomicU32::new(0), @@ -28,7 +31,12 @@ impl Mutex { pub fn lock(&self) -> MutexGuard<'_, T> { while self .lockword - .compare_exchange(UNLOCKED, LOCKED, Ordering::Acquire, Ordering::Relaxed) + .compare_exchange( + Self::UNLOCKED, + Self::LOCKED, + Ordering::Acquire, + Ordering::Relaxed, + ) .is_err() { core::hint::spin_loop(); @@ -53,6 +61,8 @@ impl DerefMut for MutexGuard<'_, T> { } impl Drop for MutexGuard<'_, T> { fn drop(&mut self) { - self.lock.lockword.store(UNLOCKED, Ordering::Release); + self.lock + .lockword + .store(Mutex::::UNLOCKED, Ordering::Release); } }