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