forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatomic.rs
More file actions
52 lines (48 loc) · 1.1 KB
/
atomic.rs
File metadata and controls
52 lines (48 loc) · 1.1 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
pub use core::sync::atomic::*;
pub use radium::Radium;
mod sealed {
pub trait Sealed {}
}
pub trait PyAtomicScalar: sealed::Sealed {
type Radium: Radium<Item = Self>;
}
pub type PyAtomic<T> = <T as PyAtomicScalar>::Radium;
#[cfg(feature = "threading")]
macro_rules! atomic_ty {
($i:ty, $atomic:ty) => {
$atomic
};
}
#[cfg(not(feature = "threading"))]
macro_rules! atomic_ty {
($i:ty, $atomic:ty) => {
core::cell::Cell<$i>
};
}
macro_rules! impl_atomic_scalar {
($(($i:ty, $atomic:ty),)*) => {
$(
impl sealed::Sealed for $i {}
impl PyAtomicScalar for $i {
type Radium = atomic_ty!($i, $atomic);
}
)*
};
}
impl_atomic_scalar!(
(u8, AtomicU8),
(i8, AtomicI8),
(u16, AtomicU16),
(i16, AtomicI16),
(u32, AtomicU32),
(i32, AtomicI32),
(u64, AtomicU64),
(i64, AtomicI64),
(usize, AtomicUsize),
(isize, AtomicIsize),
(bool, AtomicBool),
);
impl<T> sealed::Sealed for *mut T {}
impl<T> PyAtomicScalar for *mut T {
type Radium = atomic_ty!(*mut T, AtomicPtr<T>);
}