1#[cfg(all(feature = "multi-core", feature = "no-atomic-cas"))]
4compile_error!(
5 "The `multi-core` feature requires atomic-cas operations to be available on the target. Enable the `atomic-cas` feature."
6);
7
8#[cfg(all(feature = "no-atomic-cas", not(target_has_atomic = "8")))]
9compile_error!(
10 "The `atomic-cas` feature requires the target to have atomic operations on at least 8-bit integers."
11);
12
13#[cfg(all(feature = "no-atomic-cas"))]
15pub use core::sync::atomic::Ordering;
16
17#[cfg(all(feature = "no-atomic-cas"))]
18use core::cell::UnsafeCell;
19
20#[cfg(all(feature = "no-atomic-cas"))]
21pub struct AtomicU8 {
23 value: UnsafeCell<u8>,
24}
25
26#[cfg(not(all(feature = "no-atomic-cas")))]
27pub use core::sync::atomic::AtomicU8;
28
29#[cfg(all(feature = "no-atomic-cas"))]
30impl AtomicU8 {
31 pub const fn new(value: u8) -> Self {
33 Self {
34 value: UnsafeCell::new(value),
35 }
36 }
37
38 pub fn load(&self, _: Ordering) -> u8 {
40 todo!("Implement atomic load for u8");
41 }
42
43 pub fn store(&self, value: u8, _: Ordering) {
45 todo!("Implement atomic store for u8");
46 }
47
48 pub fn compare_exchange(
50 &self,
51 current: u8,
52 new: u8,
53 _: Ordering,
54 _: Ordering,
55 ) -> Result<u8, u8> {
56 todo!("Implement atomic compare_exchange for u8");
57 }
58
59 pub fn fetch_update<F>(&self, _: Ordering, _: Ordering, f: F) -> Result<u8, u8>
61 where
62 F: FnMut(u8) -> Option<u8>,
63 {
64 todo!("Implement atomic fetch_update for u8");
65 }
66}
67
68#[cfg(not(all(feature = "no-atomic-cas")))]
69pub use core::sync::atomic::AtomicBool;
70
71#[cfg(all(feature = "no-atomic-cas"))]
72pub struct AtomicBool {
74 value: UnsafeCell<bool>,
75}
76
77#[cfg(all(feature = "no-atomic-cas"))]
78impl AtomicBool {
79 pub const fn new(value: bool) -> Self {
81 Self {
82 value: UnsafeCell::new(value),
83 }
84 }
85
86 pub fn load(&self, _: Ordering) -> bool {
88 todo!("Implement atomic load for bool");
89 }
90
91 pub fn store(&self, value: bool, _: Ordering) {
93 todo!("Implement atomic store for bool");
94 }
95
96 pub fn compare_exchange(
98 &self,
99 current: bool,
100 new: bool,
101 _: Ordering,
102 _: Ordering,
103 ) -> Result<bool, bool> {
104 todo!("Implement atomic compare_exchange for bool");
105 }
106}