1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use core::sync::atomic::*;
12 use core::sync::atomic::Ordering::SeqCst;
16 let a = AtomicBool::new(false);
17 assert_eq!(a.compare_and_swap(false, true, SeqCst), false);
18 assert_eq!(a.compare_and_swap(false, true, SeqCst), true);
20 a.store(false, SeqCst);
21 assert_eq!(a.compare_and_swap(false, true, SeqCst), false);
26 let a = AtomicBool::new(true);
27 assert_eq!(a.fetch_and(false, SeqCst),true);
28 assert_eq!(a.load(SeqCst),false);
33 let x = AtomicUsize::new(0xf731);
34 assert_eq!(x.fetch_and(0x137f, SeqCst), 0xf731);
35 assert_eq!(x.load(SeqCst), 0xf731 & 0x137f);
40 let x = AtomicUsize::new(0xf731);
41 assert_eq!(x.fetch_or(0x137f, SeqCst), 0xf731);
42 assert_eq!(x.load(SeqCst), 0xf731 | 0x137f);
47 let x = AtomicUsize::new(0xf731);
48 assert_eq!(x.fetch_xor(0x137f, SeqCst), 0xf731);
49 assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
54 let x = AtomicIsize::new(0xf731);
55 assert_eq!(x.fetch_and(0x137f, SeqCst), 0xf731);
56 assert_eq!(x.load(SeqCst), 0xf731 & 0x137f);
61 let x = AtomicIsize::new(0xf731);
62 assert_eq!(x.fetch_or(0x137f, SeqCst), 0xf731);
63 assert_eq!(x.load(SeqCst), 0xf731 | 0x137f);
68 let x = AtomicIsize::new(0xf731);
69 assert_eq!(x.fetch_xor(0x137f, SeqCst), 0xf731);
70 assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
73 static S_FALSE: AtomicBool = AtomicBool::new(false);
74 static S_TRUE: AtomicBool = AtomicBool::new(true);
75 static S_INT: AtomicIsize = AtomicIsize::new(0);
76 static S_UINT: AtomicUsize = AtomicUsize::new(0);
80 assert!(!S_FALSE.load(SeqCst));
81 assert!(S_TRUE.load(SeqCst));
82 assert!(S_INT.load(SeqCst) == 0);
83 assert!(S_UINT.load(SeqCst) == 0);