1 // Copyright 2012 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.
12 #[abi = "rust-intrinsic"]
13 extern "rust-intrinsic" {
14 pub fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
15 pub fn atomic_cxchg_acq(dst: &mut int, old: int, src: int) -> int;
16 pub fn atomic_cxchg_rel(dst: &mut int, old: int, src: int) -> int;
18 pub fn atomic_load(src: &int) -> int;
19 pub fn atomic_load_acq(src: &int) -> int;
21 pub fn atomic_store(dst: &mut int, val: int);
22 pub fn atomic_store_rel(dst: &mut int, val: int);
24 pub fn atomic_xchg(dst: &mut int, src: int) -> int;
25 pub fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
26 pub fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
28 pub fn atomic_xadd(dst: &mut int, src: int) -> int;
29 pub fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
30 pub fn atomic_xadd_rel(dst: &mut int, src: int) -> int;
32 pub fn atomic_xsub(dst: &mut int, src: int) -> int;
33 pub fn atomic_xsub_acq(dst: &mut int, src: int) -> int;
34 pub fn atomic_xsub_rel(dst: &mut int, src: int) -> int;
42 assert_eq!(rusti::atomic_load(x), 1);
44 assert_eq!(rusti::atomic_load_acq(x), 5);
46 rusti::atomic_store(x,3);
48 rusti::atomic_store_rel(x,1);
51 assert_eq!(rusti::atomic_cxchg(x, 1, 2), 1);
54 assert_eq!(rusti::atomic_cxchg_acq(x, 1, 3), 2);
57 assert_eq!(rusti::atomic_cxchg_rel(x, 2, 1), 2);
60 assert_eq!(rusti::atomic_xchg(x, 0), 1);
63 assert_eq!(rusti::atomic_xchg_acq(x, 1), 0);
66 assert_eq!(rusti::atomic_xchg_rel(x, 0), 1);
69 assert_eq!(rusti::atomic_xadd(x, 1), 0);
70 assert_eq!(rusti::atomic_xadd_acq(x, 1), 1);
71 assert_eq!(rusti::atomic_xadd_rel(x, 1), 2);
74 assert_eq!(rusti::atomic_xsub(x, 1), 3);
75 assert_eq!(rusti::atomic_xsub_acq(x, 1), 2);
76 assert_eq!(rusti::atomic_xsub_rel(x, 1), 1);