summaryrefslogtreecommitdiff
path: root/src/sync.rs
diff options
context:
space:
mode:
authorChristian Cunningham <c@localhost>2022-08-26 19:00:35 -0700
committerChristian Cunningham <c@localhost>2022-08-26 19:00:35 -0700
commit58ca9615b99417b76118b606be956185ea5894f9 (patch)
tree600744900cef881be165c8482b6da475f1ceb7fa /src/sync.rs
parent3deed9bee660cb9bbcbf0ec835fc042a3793f570 (diff)
Ordering
Diffstat (limited to 'src/sync.rs')
-rw-r--r--src/sync.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/sync.rs b/src/sync.rs
index e0a8767..8c20071 100644
--- a/src/sync.rs
+++ b/src/sync.rs
@@ -124,24 +124,30 @@ impl<T> interface::Mutex for SpinLock<T> {
// Loop until acquired the lock
match self
.lock
- .compare_exchange(false, true, Ordering::Acquire, Ordering::Acquire)
+ .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
{
Ok(false) => {
break;
}
- Ok(true) => {
- }
- Err(true) => {
- break;
- }
- Err(false) => {}
+ _ => {}
}
}
let data = unsafe { &mut *self.data.get() };
let res = f(data);
// Release the lock after finished with the underlying data
- self.lock.store(false, Ordering::Release);
+ loop {
+ // Loop until acquired the lock
+ match self
+ .lock
+ .compare_exchange(true, false, Ordering::Release, Ordering::Relaxed)
+ {
+ Ok(false) => {
+ break;
+ }
+ _ => {}
+ }
+ }
res
}
}