From efac7c9a197fa3ff3497ce99a2dda8693b3ef683 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 16 Aug 2011 17:12:46 -0700 Subject: Yet another comm interface. --- src/lib/comm.rs | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'src/lib') diff --git a/src/lib/comm.rs b/src/lib/comm.rs index 03b719cdc73..318d9782301 100644 --- a/src/lib/comm.rs +++ b/src/lib/comm.rs @@ -10,16 +10,14 @@ export _port; export mk_port; export chan_from_unsafe_ptr; export send; +export recv; +export chan; +export port; native "rust" mod rustrt { type void; - type rust_chan; type rust_port; - fn new_chan(po : *rust_port) -> *rust_chan; - fn take_chan(ch : *rust_chan); - fn drop_chan(ch : *rust_chan); - fn chan_send(ch: *rust_chan, v : *void); fn chan_id_send<~T>(target_task : task_id, target_port : port_id, data : -T); @@ -35,34 +33,50 @@ native "rust-intrinsic" mod rusti { type port_id = int; -type _chan<~T> = { +type chan<~T> = { task : task_id, port : port_id }; +type _chan<~T> = chan; resource port_ptr(po: *rustrt::rust_port) { rustrt::drop_port(po); rustrt::del_port(po); } -obj _port<~T>(raw_port : @port_ptr) { +type port<~T> = @port_ptr; + +obj port_obj<~T>(raw_port : port) { // FIXME: rename this to chan once chan is not a keyword. fn mk_chan() -> _chan { - { - task: task::get_task_id(), - port: rustrt::get_port_id(**raw_port) - } + chan::(raw_port) } fn recv() -> T { - ret rusti::recv(**raw_port) + recv(raw_port) } } +type _port<~T> = port_obj; fn mk_port<~T>() -> _port { - _port(@port_ptr(rustrt::new_port(sys::size_of::()))) + ret port_obj::(port::()); } -fn send<~T>(ch : _chan, data : -T) { +fn send<~T>(ch : chan, data : -T) { rustrt::chan_id_send(ch.task, ch.port, data); } + +fn port<~T>() -> port { + @port_ptr(rustrt::new_port(sys::size_of::())) +} + +fn recv<~T>(p : port) -> T { + ret rusti::recv(**p) +} + +fn chan<~T>(p : port) -> chan { + { + task: task::get_task_id(), + port: rustrt::get_port_id(**p) + } +} -- cgit 1.4.1-3-g733a5