|
1 |
| -use std::sync::atomic::{AtomicIsize, Ordering::*}; |
2 |
| - |
3 |
| -static ATOMIC: AtomicIsize = AtomicIsize::new(0); |
| 1 | +use std::sync::atomic::{AtomicBool, AtomicIsize, Ordering::*}; |
4 | 2 |
|
5 | 3 | fn main() {
|
| 4 | + atomic_bool(); |
| 5 | + atomic_isize(); |
| 6 | +} |
| 7 | + |
| 8 | +fn atomic_bool() { |
| 9 | + static mut ATOMIC: AtomicBool = AtomicBool::new(false); |
| 10 | + |
| 11 | + unsafe { |
| 12 | + assert_eq!(*ATOMIC.get_mut(), false); |
| 13 | + ATOMIC.store(true, SeqCst); |
| 14 | + assert_eq!(*ATOMIC.get_mut(), true); |
| 15 | + ATOMIC.fetch_or(false, SeqCst); |
| 16 | + assert_eq!(*ATOMIC.get_mut(), true); |
| 17 | + ATOMIC.fetch_and(false, SeqCst); |
| 18 | + assert_eq!(*ATOMIC.get_mut(), false); |
| 19 | + ATOMIC.fetch_nand(true, SeqCst); |
| 20 | + assert_eq!(*ATOMIC.get_mut(), true); |
| 21 | + ATOMIC.fetch_xor(true, SeqCst); |
| 22 | + assert_eq!(*ATOMIC.get_mut(), false); |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +fn atomic_isize() { |
| 27 | + static ATOMIC: AtomicIsize = AtomicIsize::new(0); |
| 28 | + |
6 | 29 | // Make sure trans can emit all the intrinsics correctly
|
7 | 30 | assert_eq!(ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed), Ok(0));
|
8 | 31 | assert_eq!(ATOMIC.compare_exchange(0, 2, Acquire, Relaxed), Err(1));
|
|
0 commit comments