mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-08 13:02:50 +00:00
fix atomic intrinsic test cases
This commit is contained in:
parent
caceac06ce
commit
01a5845db5
@ -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)
|
||||
}
|
||||
fn atomic_xchg(dst: &mut int, src: int) -> int {
|
||||
rusti::atomic_xchg(dst, src)
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<T>(x: *T) -> ~T {
|
||||
unsafe { unsafe::reinterpret_cast(x) }
|
||||
unsafe fn uniquify<T>(+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<T: send>(p: *packet<T>) {
|
||||
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<T: send>(p: *packet<T>) {
|
||||
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<pong> unsafe {
|
||||
let addr : *pipes::send_packet<pong> = 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<ping> unsafe {
|
||||
let addr : *pipes::send_packet<ping> = 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);
|
||||
|
Loading…
Reference in New Issue
Block a user