-
Notifications
You must be signed in to change notification settings - Fork 332
/
atomic.rs
37 lines (29 loc) · 1.11 KB
/
atomic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
pub(crate) use self::imp::AtomicU64;
// `AtomicU64` can only be used on targets with `target_has_atomic` is 64 or greater.
// Once `cfg_target_has_atomic` feature is stable, we can replace it with
// `#[cfg(target_has_atomic = "64")]`.
// Refs: https://github.com/rust-lang/rust/tree/master/src/librustc_target
#[cfg(not(any(target_arch = "arm", target_arch = "mips", target_arch = "powerpc")))]
mod imp {
pub(crate) use std::sync::atomic::AtomicU64;
}
#[cfg(any(target_arch = "arm", target_arch = "mips", target_arch = "powerpc"))]
mod imp {
use std::sync::atomic::Ordering;
use crossbeam_utils::atomic::AtomicCell;
pub(crate) struct AtomicU64(AtomicCell<u64>);
impl AtomicU64 {
pub(crate) const fn new(val: u64) -> Self {
Self(AtomicCell::new(val))
}
pub(crate) fn load(&self, _: Ordering) -> u64 {
self.0.load()
}
pub(crate) fn fetch_add(&self, val: u64, _: Ordering) -> u64 {
self.0.fetch_add(val)
}
pub(crate) fn fetch_sub(&self, val: u64, _: Ordering) -> u64 {
self.0.fetch_sub(val)
}
}
}