2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2014-06-20 23:39:23 +00:00
|
|
|
#![feature(intrinsics)]
|
|
|
|
|
2013-03-05 22:42:58 +00:00
|
|
|
mod rusti {
|
2013-07-19 02:08:57 +00:00
|
|
|
extern "rust-intrinsic" {
|
2022-06-22 11:02:23 +00:00
|
|
|
pub fn atomic_cxchg_seqcst_seqcst<T>(dst: *mut T, old: T, src: T) -> (T, bool);
|
|
|
|
pub fn atomic_cxchg_acquire_acquire<T>(dst: *mut T, old: T, src: T) -> (T, bool);
|
|
|
|
pub fn atomic_cxchg_release_relaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2013-03-05 22:42:58 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
pub fn atomic_cxchgweak_seqcst_seqcst<T>(dst: *mut T, old: T, src: T) -> (T, bool);
|
|
|
|
pub fn atomic_cxchgweak_acquire_acquire<T>(dst: *mut T, old: T, src: T) -> (T, bool);
|
|
|
|
pub fn atomic_cxchgweak_release_relaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-01-16 23:40:11 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
pub fn atomic_load_seqcst<T>(src: *const T) -> T;
|
|
|
|
pub fn atomic_load_acquire<T>(src: *const T) -> T;
|
2013-05-19 02:40:12 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
pub fn atomic_store_seqcst<T>(dst: *mut T, val: T);
|
|
|
|
pub fn atomic_store_release<T>(dst: *mut T, val: T);
|
2013-05-12 19:22:20 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
pub fn atomic_xchg_seqcst<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xchg_acquire<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xchg_release<T>(dst: *mut T, src: T) -> T;
|
2013-03-14 02:25:28 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
pub fn atomic_xadd_seqcst<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xadd_acquire<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xadd_release<T>(dst: *mut T, src: T) -> T;
|
2013-03-14 02:25:28 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
pub fn atomic_xsub_seqcst<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xsub_acquire<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xsub_release<T>(dst: *mut T, src: T) -> T;
|
2013-03-05 22:42:58 +00:00
|
|
|
}
|
2012-06-21 22:01:32 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2013-01-24 00:29:31 +00:00
|
|
|
unsafe {
|
2021-08-25 00:39:40 +00:00
|
|
|
let mut x: Box<_> = Box::new(1);
|
2012-06-21 22:01:32 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
assert_eq!(rusti::atomic_load_seqcst(&*x), 1);
|
2013-05-12 19:22:20 +00:00
|
|
|
*x = 5;
|
2022-06-22 11:02:23 +00:00
|
|
|
assert_eq!(rusti::atomic_load_acquire(&*x), 5);
|
2013-05-19 02:40:12 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
rusti::atomic_store_seqcst(&mut *x,3);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*x, 3);
|
2022-06-22 11:02:23 +00:00
|
|
|
rusti::atomic_store_release(&mut *x,1);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*x, 1);
|
2013-05-12 19:22:20 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
assert_eq!(rusti::atomic_cxchg_seqcst_seqcst(&mut *x, 1, 2), (1, true));
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*x, 2);
|
2012-10-22 02:23:50 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
assert_eq!(rusti::atomic_cxchg_acquire_acquire(&mut *x, 1, 3), (2, false));
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*x, 2);
|
2012-10-22 02:23:50 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
assert_eq!(rusti::atomic_cxchg_release_relaxed(&mut *x, 2, 1), (2, true));
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*x, 1);
|
2012-10-22 02:23:50 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
assert_eq!(rusti::atomic_xchg_seqcst(&mut *x, 0), 1);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*x, 0);
|
2012-06-21 22:01:32 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
assert_eq!(rusti::atomic_xchg_acquire(&mut *x, 1), 0);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*x, 1);
|
2012-06-21 22:01:32 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
assert_eq!(rusti::atomic_xchg_release(&mut *x, 0), 1);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*x, 0);
|
2012-06-21 22:01:32 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
assert_eq!(rusti::atomic_xadd_seqcst(&mut *x, 1), 0);
|
|
|
|
assert_eq!(rusti::atomic_xadd_acquire(&mut *x, 1), 1);
|
|
|
|
assert_eq!(rusti::atomic_xadd_release(&mut *x, 1), 2);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*x, 3);
|
2012-06-21 22:01:32 +00:00
|
|
|
|
2022-06-22 11:02:23 +00:00
|
|
|
assert_eq!(rusti::atomic_xsub_seqcst(&mut *x, 1), 3);
|
|
|
|
assert_eq!(rusti::atomic_xsub_acquire(&mut *x, 1), 2);
|
|
|
|
assert_eq!(rusti::atomic_xsub_release(&mut *x, 1), 1);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*x, 0);
|
2016-01-16 23:40:11 +00:00
|
|
|
|
|
|
|
loop {
|
2022-06-22 11:02:23 +00:00
|
|
|
let res = rusti::atomic_cxchgweak_seqcst_seqcst(&mut *x, 0, 1);
|
2016-01-16 23:40:11 +00:00
|
|
|
assert_eq!(res.0, 0);
|
|
|
|
if res.1 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert_eq!(*x, 1);
|
|
|
|
|
|
|
|
loop {
|
2022-06-22 11:02:23 +00:00
|
|
|
let res = rusti::atomic_cxchgweak_acquire_acquire(&mut *x, 1, 2);
|
2016-01-16 23:40:11 +00:00
|
|
|
assert_eq!(res.0, 1);
|
|
|
|
if res.1 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert_eq!(*x, 2);
|
|
|
|
|
|
|
|
loop {
|
2022-06-22 11:02:23 +00:00
|
|
|
let res = rusti::atomic_cxchgweak_release_relaxed(&mut *x, 2, 3);
|
2016-01-16 23:40:11 +00:00
|
|
|
assert_eq!(res.0, 2);
|
|
|
|
if res.1 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert_eq!(*x, 3);
|
2013-01-24 00:29:31 +00:00
|
|
|
}
|
2012-06-21 22:01:32 +00:00
|
|
|
}
|