Objectified library chans and ports.

This commit is contained in:
Eric Holk 2011-07-29 18:52:16 -07:00
parent 5a673cc2c9
commit b3d9d9b73c
3 changed files with 17 additions and 15 deletions

View file

@ -4,7 +4,6 @@ export _chan;
export _port; export _port;
export mk_port; export mk_port;
export mk_chan;
native "rust" mod rustrt { native "rust" mod rustrt {
type rust_chan; type rust_chan;
@ -26,23 +25,27 @@ resource chan_ptr(ch: *rustrt::rust_chan) {
rustrt::del_chan(ch); rustrt::del_chan(ch);
} }
tag _chan[T] { _chan(@chan_dtor); }
resource port_ptr(po: *rustrt::rust_port) { resource port_ptr(po: *rustrt::rust_port) {
rustrt::drop_port(po); rustrt::drop_port(po);
rustrt::del_port(po); rustrt::del_port(po);
} }
tag _port[T] { _port(@port_dtor); } obj _chan[T](raw_chan : @chan_ptr) {
fn send(v : &T) {
fn mk_port[T]() -> _port[T] {
_port(@port_dtor(rustrt::new_port(sys::size_of[T]())))
}
fn mk_chan[T](po : &_port[T]) -> _chan[T] {
alt po {
_port(_po) {
_chan(@chan_dtor(rustrt::new_chan(**_po)))
}
} }
} }
obj _port[T](raw_port : @port_ptr) {
fn mk_chan() -> _chan[T] {
_chan(@chan_ptr(rustrt::new_chan(**raw_port)))
}
fn recv_into(v : &T) {
}
}
fn mk_port[T]() -> _port[T] {
_port(@port_ptr(rustrt::new_port(sys::size_of[T]())))
}

View file

@ -912,7 +912,6 @@ void drop_chan(rust_task *task, rust_chan *chan) {
extern "C" CDECL extern "C" CDECL
void drop_port(rust_task *, rust_port *port) { void drop_port(rust_task *, rust_port *port) {
port->ref_count--; port->ref_count--;
>>>>>>> Started working on a library-based comm system. Creating and deleting ports work.
} }
// //

View file

@ -4,5 +4,5 @@ import std::comm;
#[test] #[test]
fn create_port_and_chan() { fn create_port_and_chan() {
let p = comm::mk_port[int](); let p = comm::mk_port[int]();
let c = comm::mk_chan(p); let c = p.mk_chan();
} }