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