mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 10:08:20 +00:00
use compare_exchange
This commit is contained in:
parent
20f5ade95e
commit
cbc46ce2fe
1 changed files with 9 additions and 2 deletions
|
@ -37,14 +37,21 @@ impl<T> FastLock<T> {
|
|||
}
|
||||
|
||||
pub fn lock(&self) -> FastLockGuard<T> {
|
||||
while self.lock.compare_and_swap(false, true, Ordering::Acquire) {
|
||||
while self
|
||||
.lock
|
||||
.compare_exchange(false, true, Ordering::Acquire, Ordering::Acquire)
|
||||
.is_err()
|
||||
{
|
||||
std::thread::yield_now();
|
||||
}
|
||||
FastLockGuard { lock: self }
|
||||
}
|
||||
|
||||
pub fn unlock(&self) {
|
||||
assert!(self.lock.compare_and_swap(true, false, Ordering::Acquire));
|
||||
assert!(self
|
||||
.lock
|
||||
.compare_exchange(true, false, Ordering::Acquire, Ordering::Acquire)
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
pub fn get_mut(&self) -> &mut T {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue