diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2011-10-19 14:47:50 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-10-24 16:06:16 -0700 |
| commit | d9b23cb0224efb7157d2888bdaef85edebf6dd08 (patch) | |
| tree | 9b90f44fc8441a7dff8d2499dcda9f726f08b898 | |
| parent | 44697a4293ae083e57b49cc2afe6cf7fca71b10a (diff) | |
| download | rust-d9b23cb0224efb7157d2888bdaef85edebf6dd08.tar.gz rust-d9b23cb0224efb7157d2888bdaef85edebf6dd08.zip | |
move comm functions out of rust abi
| -rw-r--r-- | src/lib/comm.rs | 30 | ||||
| -rw-r--r-- | src/rt/rust_builtin.cpp | 1 | ||||
| -rw-r--r-- | src/test/stdtest/comm.rs | 17 |
3 files changed, 34 insertions, 14 deletions
diff --git a/src/lib/comm.rs b/src/lib/comm.rs index dfd8587e36b..07097079c0e 100644 --- a/src/lib/comm.rs +++ b/src/lib/comm.rs @@ -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); } diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 32eb4a685d7..310d61b182e 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -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(); } } diff --git a/src/test/stdtest/comm.rs b/src/test/stdtest/comm.rs index 9c31c5e6f72..bef5a3c4e5b 100644 --- a/src/test/stdtest/comm.rs +++ b/src/test/stdtest/comm.rs @@ -5,6 +5,13 @@ import std::comm; 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>(); let c = comm::chan::<int>(p); @@ -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); +} |
