tokio: add load and compare_exchange_weak to loom StaticAtomicU64 (#5356)

This commit is contained in:
2023-01-06 15:19:31 +09:00
committed by GitHub
parent dfe252d1fa
commit 8d8db27442
@@ -23,6 +23,10 @@ impl StaticAtomicU64 {
}
}
pub(crate) fn load(&self, order: Ordering) -> u64 {
*self.inner().lock()
}
pub(crate) fn fetch_add(&self, val: u64, order: Ordering) -> u64 {
let mut lock = self.inner().lock();
let prev = *lock;
@@ -30,6 +34,23 @@ impl StaticAtomicU64 {
prev
}
pub(crate) fn compare_exchange_weak(
&self,
current: u64,
new: u64,
_success: Ordering,
_failure: Ordering,
) -> Result<u64, u64> {
let mut lock = self.inner().lock();
if *lock == current {
*lock = new;
Ok(current)
} else {
Err(*lock)
}
}
fn inner(&self) -> &Mutex<u64> {
self.cell.get(|| Mutex::new(self.init))
}