auto merge of #6437 : Thiez/rust/atomic, r=Aatch
This pull request adds 4 atomic intrinsics to the compiler, in preparation for #5042. * `atomic_load(src: &int) -> int` performs an atomic sequentially consistent load. * `atomic_load_acq(src: &int) -> int` performs an atomic acquiring load. * `atomic_store(dst: &mut int, val: int)` performs an atomic sequentially consistent store. * `atomic_store_rel(dst: &mut int, val: int)` performs an atomic releasing store. For more information about the whole acquire/release thing: http://llvm.org/docs/Atomics.html r?
This commit is contained in:
commit
1bf2f68bb2
9 changed files with 136 additions and 5 deletions
|
|
@ -15,6 +15,12 @@ mod rusti {
|
|||
pub fn atomic_cxchg_acq(dst: &mut int, old: int, src: int) -> int;
|
||||
pub fn atomic_cxchg_rel(dst: &mut int, old: int, src: int) -> int;
|
||||
|
||||
pub fn atomic_load(src: &int) -> int;
|
||||
pub fn atomic_load_acq(src: &int) -> int;
|
||||
|
||||
pub fn atomic_store(dst: &mut int, val: int);
|
||||
pub fn atomic_store_rel(dst: &mut int, val: int);
|
||||
|
||||
pub fn atomic_xchg(dst: &mut int, src: int) -> int;
|
||||
pub fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
|
||||
pub fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
|
||||
|
|
@ -33,6 +39,15 @@ pub fn main() {
|
|||
unsafe {
|
||||
let mut x = ~1;
|
||||
|
||||
assert!(rusti::atomic_load(x) == 1);
|
||||
*x = 5;
|
||||
assert!(rusti::atomic_load_acq(x) == 5);
|
||||
|
||||
rusti::atomic_store(x,3);
|
||||
assert!(*x == 3);
|
||||
rusti::atomic_store_rel(x,1);
|
||||
assert!(*x == 1);
|
||||
|
||||
assert!(rusti::atomic_cxchg(x, 1, 2) == 1);
|
||||
assert!(*x == 2);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue