libcortex_a9: added `try_lock` for mutex.

tcp-recv-fnmut
pca006132 3 years ago
parent 191abf6b8f
commit 074438c3c7
  1. 9
      libcortex_a9/src/mutex.rs

@ -48,6 +48,15 @@ impl<T> Mutex<T> {
MutexGuard { mutex: self }
}
pub fn try_lock(&self) -> Option<MutexGuard<T>> {
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);

Loading…
Cancel
Save