From 01a5845db56621d0dca7a30f2bda914d5deb8a4f Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Thu, 23 Aug 2012 17:19:35 -0400 Subject: [PATCH] fix atomic intrinsic test cases --- src/test/auxiliary/cci_intrinsic.rs | 24 ++++++------ src/test/run-pass/intrinsic-atomics-cc.rs | 4 +- src/test/run-pass/intrinsic-atomics.rs | 48 +++++++++++------------ src/test/run-pass/issue-2718.rs | 36 ++++++++--------- 4 files changed, 54 insertions(+), 58 deletions(-) diff --git a/src/test/auxiliary/cci_intrinsic.rs b/src/test/auxiliary/cci_intrinsic.rs index 886a8d1bfe1..b75462b3c4a 100644 --- a/src/test/auxiliary/cci_intrinsic.rs +++ b/src/test/auxiliary/cci_intrinsic.rs @@ -1,19 +1,19 @@ #[abi = "rust-intrinsic"] extern mod rusti { - fn atomic_xchng(&dst: int, src: int) -> int; - fn atomic_xchng_acq(&dst: int, src: int) -> int; - fn atomic_xchng_rel(&dst: int, src: int) -> int; + fn atomic_xchg(dst: &mut int, src: int) -> int; + fn atomic_xchg_acq(dst: &mut int, src: int) -> int; + fn atomic_xchg_rel(dst: &mut int, src: int) -> int; - fn atomic_add(&dst: int, src: int) -> int; - fn atomic_add_acq(&dst: int, src: int) -> int; - fn atomic_add_rel(&dst: int, src: int) -> int; + fn atomic_xadd(dst: &mut int, src: int) -> int; + fn atomic_xadd_acq(dst: &mut int, src: int) -> int; + fn atomic_xadd_rel(dst: &mut int, src: int) -> int; - fn atomic_sub(&dst: int, src: int) -> int; - fn atomic_sub_acq(&dst: int, src: int) -> int; - fn atomic_sub_rel(&dst: int, src: int) -> int; + fn atomic_xsub(dst: &mut int, src: int) -> int; + fn atomic_xsub_acq(dst: &mut int, src: int) -> int; + fn atomic_xsub_rel(dst: &mut int, src: int) -> int; } #[inline(always)] -fn atomic_xchng(&dst: int, src: int) -> int { - rusti::atomic_xchng(dst, src) -} \ No newline at end of file +fn atomic_xchg(dst: &mut int, src: int) -> int { + rusti::atomic_xchg(dst, src) +} diff --git a/src/test/run-pass/intrinsic-atomics-cc.rs b/src/test/run-pass/intrinsic-atomics-cc.rs index bcfa69dbb20..601bdde8b3a 100644 --- a/src/test/run-pass/intrinsic-atomics-cc.rs +++ b/src/test/run-pass/intrinsic-atomics-cc.rs @@ -4,10 +4,10 @@ // xfail-test use cci_intrinsic; -import cci_intrinsic::atomic_xchng; +import cci_intrinsic::atomic_xchg; fn main() { let mut x = 1; - atomic_xchng(x, 5); + atomic_xchg(&mut x, 5); assert x == 5; } diff --git a/src/test/run-pass/intrinsic-atomics.rs b/src/test/run-pass/intrinsic-atomics.rs index 5170e5b407b..512e0edbec9 100644 --- a/src/test/run-pass/intrinsic-atomics.rs +++ b/src/test/run-pass/intrinsic-atomics.rs @@ -1,37 +1,37 @@ #[abi = "rust-intrinsic"] extern mod rusti { - fn atomic_xchng(&dst: int, src: int) -> int; - fn atomic_xchng_acq(&dst: int, src: int) -> int; - fn atomic_xchng_rel(&dst: int, src: int) -> int; + fn atomic_xchg(dst: &mut int, src: int) -> int; + fn atomic_xchg_acq(dst: &mut int, src: int) -> int; + fn atomic_xchg_rel(dst: &mut int, src: int) -> int; - fn atomic_add(&dst: int, src: int) -> int; - fn atomic_add_acq(&dst: int, src: int) -> int; - fn atomic_add_rel(&dst: int, src: int) -> int; + fn atomic_xadd(dst: &mut int, src: int) -> int; + fn atomic_xadd_acq(dst: &mut int, src: int) -> int; + fn atomic_xadd_rel(dst: &mut int, src: int) -> int; - fn atomic_sub(&dst: int, src: int) -> int; - fn atomic_sub_acq(&dst: int, src: int) -> int; - fn atomic_sub_rel(&dst: int, src: int) -> int; + fn atomic_xsub(dst: &mut int, src: int) -> int; + fn atomic_xsub_acq(dst: &mut int, src: int) -> int; + fn atomic_xsub_rel(dst: &mut int, src: int) -> int; } fn main() { - let mut x = 1; + let x = ~mut 1; - assert rusti::atomic_xchng(x, 0) == 1; - assert x == 0; + assert rusti::atomic_xchg(x, 0) == 1; + assert *x == 0; - assert rusti::atomic_xchng_acq(x, 1) == 0; - assert x == 1; + assert rusti::atomic_xchg_acq(x, 1) == 0; + assert *x == 1; - assert rusti::atomic_xchng_rel(x, 0) == 1; - assert x == 0; + assert rusti::atomic_xchg_rel(x, 0) == 1; + assert *x == 0; - assert rusti::atomic_add(x, 1) == 0; - assert rusti::atomic_add_acq(x, 1) == 1; - assert rusti::atomic_add_rel(x, 1) == 2; - assert x == 3; + assert rusti::atomic_xadd(x, 1) == 0; + assert rusti::atomic_xadd_acq(x, 1) == 1; + assert rusti::atomic_xadd_rel(x, 1) == 2; + assert *x == 3; - assert rusti::atomic_sub(x, 1) == 3; - assert rusti::atomic_sub_acq(x, 1) == 2; - assert rusti::atomic_sub_rel(x, 1) == 1; - assert x == 0; + assert rusti::atomic_xsub(x, 1) == 3; + assert rusti::atomic_xsub_acq(x, 1) == 2; + assert rusti::atomic_xsub_rel(x, 1) == 1; + assert *x == 0; } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index cc3e18bff84..a8678e6126d 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -1,5 +1,5 @@ mod pipes { - import unsafe::{forget, reinterpret_cast}; + import unsafe::{forget, transmute}; enum state { empty, @@ -25,30 +25,26 @@ mod pipes { #[abi = "rust-intrinsic"] mod rusti { - fn atomic_xchng(&dst: int, src: int) -> int { fail; } - fn atomic_xchng_acq(&dst: int, src: int) -> int { fail; } - fn atomic_xchng_rel(&dst: int, src: int) -> int { fail; } + fn atomic_xchg(_dst: &mut int, _src: int) -> int { fail; } + fn atomic_xchg_acq(_dst: &mut int, _src: int) -> int { fail; } + fn atomic_xchg_rel(_dst: &mut int, _src: int) -> int { fail; } } // We should consider moving this to core::unsafe, although I // suspect graydon would want us to use void pointers instead. - unsafe fn uniquify(x: *T) -> ~T { - unsafe { unsafe::reinterpret_cast(x) } + unsafe fn uniquify(+x: *T) -> ~T { + unsafe { unsafe::transmute(x) } } - fn swap_state_acq(&dst: state, src: state) -> state { + fn swap_state_acq(+dst: &mut state, src: state) -> state { unsafe { - reinterpret_cast(rusti::atomic_xchng_acq( - *(ptr::mut_addr_of(dst) as *mut int), - src as int)) + transmute(rusti::atomic_xchg_acq(transmute(dst), src as int)) } } - fn swap_state_rel(&dst: state, src: state) -> state { + fn swap_state_rel(+dst: &mut state, src: state) -> state { unsafe { - reinterpret_cast(rusti::atomic_xchng_rel( - *(ptr::mut_addr_of(dst) as *mut int), - src as int)) + transmute(rusti::atomic_xchg_rel(transmute(dst), src as int)) } } @@ -57,7 +53,7 @@ mod pipes { let p = unsafe { uniquify(p) }; assert (*p).payload == none; (*p).payload <- some(payload); - let old_state = swap_state_rel((*p).state, full); + let old_state = swap_state_rel(&mut (*p).state, full); match old_state { empty => { // Yay, fastpath. @@ -82,7 +78,7 @@ mod pipes { let p = p.unwrap(); let p = unsafe { uniquify(p) }; loop { - let old_state = swap_state_acq((*p).state, + let old_state = swap_state_acq(&mut (*p).state, blocked); match old_state { empty | blocked => { task::yield(); } @@ -101,7 +97,7 @@ mod pipes { fn sender_terminate(p: *packet) { let p = unsafe { uniquify(p) }; - match swap_state_rel((*p).state, terminated) { + match swap_state_rel(&mut (*p).state, terminated) { empty | blocked => { // The receiver will eventually clean up. unsafe { forget(p) } @@ -118,7 +114,7 @@ mod pipes { fn receiver_terminate(p: *packet) { let p = unsafe { uniquify(p) }; - match swap_state_rel((*p).state, terminated) { + match swap_state_rel(&mut (*p).state, terminated) { empty => { // the sender will clean up unsafe { forget(p) } @@ -179,7 +175,7 @@ mod pingpong { fn liberate_ping(-p: ping) -> pipes::send_packet unsafe { let addr : *pipes::send_packet = match p { - ping(x) => { unsafe::reinterpret_cast(ptr::addr_of(x)) } + ping(x) => { unsafe::transmute(ptr::addr_of(x)) } }; let liberated_value <- *addr; unsafe::forget(p); @@ -188,7 +184,7 @@ mod pingpong { fn liberate_pong(-p: pong) -> pipes::send_packet unsafe { let addr : *pipes::send_packet = match p { - pong(x) => { unsafe::reinterpret_cast(ptr::addr_of(x)) } + pong(x) => { unsafe::transmute(ptr::addr_of(x)) } }; let liberated_value <- *addr; unsafe::forget(p);