libcortex_a9: added try_lock
for mutex.
This commit is contained in:
parent
191abf6b8f
commit
074438c3c7
@ -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…
Reference in New Issue
Block a user