move comm functions out of rust abi

This commit is contained in:
Niko Matsakis 2011-10-19 14:47:50 -07:00 committed by Brian Anderson
parent 44697a4293
commit d9b23cb022
3 changed files with 34 additions and 14 deletions

View File

@ -8,17 +8,18 @@ export recv;
export chan;
export port;
native "rust" mod rustrt {
native "c-stack-cdecl" mod rustrt {
type void;
type rust_port;
fn chan_id_send<~T>(target_task: task::task, target_port: port_id,
fn chan_id_send<~T>(unused_task: *void, t: *sys::type_desc,
target_task: task::task, target_port: port_id,
-data: T);
fn new_port(unit_sz: uint) -> *rust_port;
fn del_port(po: *rust_port);
fn drop_port(po: *rust_port);
fn get_port_id(po: *rust_port) -> port_id;
fn new_port(unused_task: *void, unit_sz: uint) -> *rust_port;
fn del_port(unused_task: *void, po: *rust_port);
fn drop_port(unused_task: *void, po: *rust_port);
fn get_port_id(unused_task: *void, po: *rust_port) -> port_id;
}
native "rust-intrinsic" mod rusti {
@ -32,23 +33,28 @@ type port_id = int;
tag chan<~T> { chan_t(task::task, port_id); }
resource port_ptr(po: *rustrt::rust_port) {
rustrt::drop_port(po);
rustrt::del_port(po);
rustrt::drop_port(ptr::null(), po);
rustrt::del_port(ptr::null(), po);
}
tag port<~T> { port_t(@port_ptr); }
fn send<~T>(ch: chan<T>, -data: T) {
let chan_t(t, p) = ch;
rustrt::chan_id_send(t, p, data);
rustrt::chan_id_send(ptr::null(), sys::get_type_desc::<T>(), t, p, data);
task::yield();
}
fn port<~T>() -> port<T> {
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>())))
let p = rustrt::new_port(ptr::null(), sys::size_of::<T>());
ret port_t(@port_ptr(p));
}
fn recv<~T>(p: port<T>) -> T { ret rusti::recv(***p) }
fn recv<~T>(p: port<T>) -> T {
ret rusti::recv(***p);
}
fn chan<~T>(p: port<T>) -> chan<T> {
chan_t(task::get_task_id(), rustrt::get_port_id(***p))
let id = rustrt::get_port_id(ptr::null(), ***p);
ret chan_t(task::get_task_id(), id);
}

View File

@ -576,7 +576,6 @@ chan_id_send(type_desc *t, rust_task_id target_task_id,
port->remote_chan->send(sptr);
}
target_task->deref();
task->yield();
}
}

View File

@ -4,6 +4,13 @@ import std::comm;
#[test]
fn create_port_and_chan() { let p = comm::port::<int>(); comm::chan(p); }
#[test]
fn send_int() {
let p = comm::port::<int>();
let c = comm::chan(p);
comm::send(c, 22);
}
#[test]
fn send_recv_fn() {
let p = comm::port::<int>();
@ -21,9 +28,17 @@ fn send_recv_fn_infer() {
}
#[test]
fn chan_chan() {
fn chan_chan_infer() {
let p = comm::port(), p2 = comm::port::<int>();
let c = comm::chan(p);
comm::send(c, comm::chan(p2));
comm::recv(p);
}
#[test]
fn chan_chan() {
let p = comm::port::<comm::chan<int>>(), p2 = comm::port::<int>();
let c = comm::chan(p);
comm::send(c, comm::chan(p2));
comm::recv(p);
}