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 extern "rust-intrinsic" {
13 pub fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
14 pub fn atomic_cxchg_acq(dst: &mut int, old: int, src: int) -> int;
15 pub fn atomic_cxchg_rel(dst: &mut int, old: int, src: int) -> int;
17 pub fn atomic_load(src: &int) -> int;
18 pub fn atomic_load_acq(src: &int) -> int;
20 pub fn atomic_store(dst: &mut int, val: int);
21 pub fn atomic_store_rel(dst: &mut int, val: int);
23 pub fn atomic_xchg(dst: &mut int, src: int) -> int;
24 pub fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
25 pub fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
27 pub fn atomic_xadd(dst: &mut int, src: int) -> int;
28 pub fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
29 pub fn atomic_xadd_rel(dst: &mut int, src: int) -> int;
31 pub fn atomic_xsub(dst: &mut int, src: int) -> int;
32 pub fn atomic_xsub_acq(dst: &mut int, src: int) -> int;
33 pub fn atomic_xsub_rel(dst: &mut int, src: int) -> int;
41 assert_eq!(rusti::atomic_load(x), 1);
43 assert_eq!(rusti::atomic_load_acq(x), 5);
45 rusti::atomic_store(x,3);
47 rusti::atomic_store_rel(x,1);
50 assert_eq!(rusti::atomic_cxchg(x, 1, 2), 1);
53 assert_eq!(rusti::atomic_cxchg_acq(x, 1, 3), 2);
56 assert_eq!(rusti::atomic_cxchg_rel(x, 2, 1), 2);
59 assert_eq!(rusti::atomic_xchg(x, 0), 1);
62 assert_eq!(rusti::atomic_xchg_acq(x, 1), 0);
65 assert_eq!(rusti::atomic_xchg_rel(x, 0), 1);
68 assert_eq!(rusti::atomic_xadd(x, 1), 0);
69 assert_eq!(rusti::atomic_xadd_acq(x, 1), 1);
70 assert_eq!(rusti::atomic_xadd_rel(x, 1), 2);
73 assert_eq!(rusti::atomic_xsub(x, 1), 3);
74 assert_eq!(rusti::atomic_xsub_acq(x, 1), 2);
75 assert_eq!(rusti::atomic_xsub_rel(x, 1), 1);