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<T>(dst: &mut T, old: T, src: T) -> T;
14 pub fn atomic_cxchg_acq<T>(dst: &mut T, old: T, src: T) -> T;
15 pub fn atomic_cxchg_rel<T>(dst: &mut T, old: T, src: T) -> T;
17 pub fn atomic_load<T>(src: &T) -> T;
18 pub fn atomic_load_acq<T>(src: &T) -> T;
20 pub fn atomic_store<T>(dst: &mut T, val: T);
21 pub fn atomic_store_rel<T>(dst: &mut T, val: T);
23 pub fn atomic_xchg<T>(dst: &mut T, src: T) -> T;
24 pub fn atomic_xchg_acq<T>(dst: &mut T, src: T) -> T;
25 pub fn atomic_xchg_rel<T>(dst: &mut T, src: T) -> T;
27 pub fn atomic_xadd<T>(dst: &mut T, src: T) -> T;
28 pub fn atomic_xadd_acq<T>(dst: &mut T, src: T) -> T;
29 pub fn atomic_xadd_rel<T>(dst: &mut T, src: T) -> T;
31 pub fn atomic_xsub<T>(dst: &mut T, src: T) -> T;
32 pub fn atomic_xsub_acq<T>(dst: &mut T, src: T) -> T;
33 pub fn atomic_xsub_rel<T>(dst: &mut T, src: T) -> T;
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);