1 use core::sync::atomic::Ordering::SeqCst;
2 use core::sync::atomic::*;
6 let a = AtomicBool::new(false);
7 assert_eq!(a.compare_and_swap(false, true, SeqCst), false);
8 assert_eq!(a.compare_and_swap(false, true, SeqCst), true);
10 a.store(false, SeqCst);
11 assert_eq!(a.compare_and_swap(false, true, SeqCst), false);
16 let a = AtomicBool::new(true);
17 assert_eq!(a.fetch_and(false, SeqCst), true);
18 assert_eq!(a.load(SeqCst), false);
23 let a = AtomicBool::new(false);
24 assert_eq!(a.fetch_nand(false, SeqCst), false);
25 assert_eq!(a.load(SeqCst), true);
26 assert_eq!(a.fetch_nand(false, SeqCst), true);
27 assert_eq!(a.load(SeqCst), true);
28 assert_eq!(a.fetch_nand(true, SeqCst), true);
29 assert_eq!(a.load(SeqCst), false);
30 assert_eq!(a.fetch_nand(true, SeqCst), false);
31 assert_eq!(a.load(SeqCst), true);
36 let x = AtomicUsize::new(0xf731);
37 assert_eq!(x.fetch_and(0x137f, SeqCst), 0xf731);
38 assert_eq!(x.load(SeqCst), 0xf731 & 0x137f);
43 let x = AtomicUsize::new(0xf731);
44 assert_eq!(x.fetch_nand(0x137f, SeqCst), 0xf731);
45 assert_eq!(x.load(SeqCst), !(0xf731 & 0x137f));
50 let x = AtomicUsize::new(0xf731);
51 assert_eq!(x.fetch_or(0x137f, SeqCst), 0xf731);
52 assert_eq!(x.load(SeqCst), 0xf731 | 0x137f);
57 let x = AtomicUsize::new(0xf731);
58 assert_eq!(x.fetch_xor(0x137f, SeqCst), 0xf731);
59 assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
64 let x = AtomicIsize::new(0xf731);
65 assert_eq!(x.fetch_and(0x137f, SeqCst), 0xf731);
66 assert_eq!(x.load(SeqCst), 0xf731 & 0x137f);
71 let x = AtomicIsize::new(0xf731);
72 assert_eq!(x.fetch_nand(0x137f, SeqCst), 0xf731);
73 assert_eq!(x.load(SeqCst), !(0xf731 & 0x137f));
78 let x = AtomicIsize::new(0xf731);
79 assert_eq!(x.fetch_or(0x137f, SeqCst), 0xf731);
80 assert_eq!(x.load(SeqCst), 0xf731 | 0x137f);
85 let x = AtomicIsize::new(0xf731);
86 assert_eq!(x.fetch_xor(0x137f, SeqCst), 0xf731);
87 assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
90 static S_FALSE: AtomicBool = AtomicBool::new(false);
91 static S_TRUE: AtomicBool = AtomicBool::new(true);
92 static S_INT: AtomicIsize = AtomicIsize::new(0);
93 static S_UINT: AtomicUsize = AtomicUsize::new(0);
97 // Note that we're not really testing the mutability here but it's important
98 // on Android at the moment (#49775)
99 assert!(!S_FALSE.swap(true, SeqCst));
100 assert!(S_TRUE.swap(false, SeqCst));
101 assert!(S_INT.fetch_add(1, SeqCst) == 0);
102 assert!(S_UINT.fetch_add(1, SeqCst) == 0);