1pub use implementation::AtomicU64;
2
3#[cfg(target_pointer_width = "64")]
4mod implementation {
5 use std::sync::atomic;
6
7 pub struct AtomicU64(atomic::AtomicU64);
8
9 impl AtomicU64 {
10 pub const fn new(initial: u64) -> Self {
11 Self(atomic::AtomicU64::new(initial))
12 }
13
14 pub fn fetch_add(&self, v: u64) -> u64 {
15 self.0.fetch_add(v, atomic::Ordering::Relaxed)
16 }
17 }
18}
19
20#[cfg(not(target_pointer_width = "64"))]
21mod implementation {
22 use parking_lot::{const_mutex, Mutex};
23
24 pub struct AtomicU64(Mutex<u64>);
25
26 impl AtomicU64 {
27 pub const fn new(initial: u64) -> Self {
28 Self(const_mutex(initial))
29 }
30
31 pub fn fetch_add(&self, v: u64) -> u64 {
32 let mut lock = self.0.lock();
33 let i = *lock;
34 *lock = i + v;
35 i
36 }
37 }
38}