diff --git a/libcortex_a9/src/mutex.rs b/libcortex_a9/src/mutex.rs index 9d3c6c6..8d84105 100644 --- a/libcortex_a9/src/mutex.rs +++ b/libcortex_a9/src/mutex.rs @@ -48,6 +48,15 @@ impl Mutex { MutexGuard { mutex: self } } + pub fn try_lock(&self) -> Option> { + if self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::Acquire) != UNLOCKED { + None + } else { + dmb(); + Some(MutexGuard { mutex: self }) + } + } + fn unlock(&self) { dmb(); self.locked.store(UNLOCKED, Ordering::Release);