mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
tokio: add load and compare_exchange_weak to loom StaticAtomicU64 (#5356)
This commit is contained in:
@@ -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 {
|
pub(crate) fn fetch_add(&self, val: u64, order: Ordering) -> u64 {
|
||||||
let mut lock = self.inner().lock();
|
let mut lock = self.inner().lock();
|
||||||
let prev = *lock;
|
let prev = *lock;
|
||||||
@@ -30,6 +34,23 @@ impl StaticAtomicU64 {
|
|||||||
prev
|
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> {
|
fn inner(&self) -> &Mutex<u64> {
|
||||||
self.cell.get(|| Mutex::new(self.init))
|
self.cell.get(|| Mutex::new(self.init))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user