Skip to content

Commit 8d8db27

Browse files
authored
tokio: add load and compare_exchange_weak to loom StaticAtomicU64 (#5356)
1 parent dfe252d commit 8d8db27

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tokio/src/loom/std/atomic_u64_static_once_cell.rs

+21
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,34 @@ impl StaticAtomicU64 {
2323
}
2424
}
2525

26+
pub(crate) fn load(&self, order: Ordering) -> u64 {
27+
*self.inner().lock()
28+
}
29+
2630
pub(crate) fn fetch_add(&self, val: u64, order: Ordering) -> u64 {
2731
let mut lock = self.inner().lock();
2832
let prev = *lock;
2933
*lock = prev + val;
3034
prev
3135
}
3236

37+
pub(crate) fn compare_exchange_weak(
38+
&self,
39+
current: u64,
40+
new: u64,
41+
_success: Ordering,
42+
_failure: Ordering,
43+
) -> Result<u64, u64> {
44+
let mut lock = self.inner().lock();
45+
46+
if *lock == current {
47+
*lock = new;
48+
Ok(current)
49+
} else {
50+
Err(*lock)
51+
}
52+
}
53+
3354
fn inner(&self) -> &Mutex<u64> {
3455
self.cell.get(|| Mutex::new(self.init))
3556
}

0 commit comments

Comments
 (0)