Add intrinsics for compare_exchange and compare_exchange_weak

This commit is contained in:
Amanieu d'Antras 2016-01-16 23:40:11 +00:00
parent 8e2a577804
commit 64ddcb33f4
8 changed files with 114 additions and 40 deletions

View file

@ -19,6 +19,10 @@ mod rusti {
pub fn atomic_cxchg_acq<T>(dst: *mut T, old: T, src: T) -> T;
pub fn atomic_cxchg_rel<T>(dst: *mut T, old: T, src: T) -> T;
pub fn atomic_cxchgweak<T>(dst: *mut T, old: T, src: T) -> (T, bool);
pub fn atomic_cxchgweak_acq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
pub fn atomic_cxchgweak_rel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
pub fn atomic_load<T>(src: *const T) -> T;
pub fn atomic_load_acq<T>(src: *const T) -> T;
@ -79,5 +83,32 @@ pub fn main() {
assert_eq!(rusti::atomic_xsub_acq(&mut *x, 1), 2);
assert_eq!(rusti::atomic_xsub_rel(&mut *x, 1), 1);
assert_eq!(*x, 0);
loop {
let res = rusti::atomic_cxchgweak(&mut *x, 0, 1);
assert_eq!(res.0, 0);
if res.1 {
break;
}
}
assert_eq!(*x, 1);
loop {
let res = rusti::atomic_cxchgweak_acq(&mut *x, 1, 2);
assert_eq!(res.0, 1);
if res.1 {
break;
}
}
assert_eq!(*x, 2);
loop {
let res = rusti::atomic_cxchgweak_rel(&mut *x, 2, 3);
assert_eq!(res.0, 2);
if res.1 {
break;
}
}
assert_eq!(*x, 3);
}
}