Improving move semantics for channel operations.

This lets us un-XFAIL task-comm-10.rs.
This commit is contained in:
Eric Holk 2011-07-19 14:31:55 -07:00 committed by Brian Anderson
parent 3ae4dcd41e
commit d79afd7916
8 changed files with 21 additions and 24 deletions

View File

@ -247,10 +247,11 @@ fn recv_val(&@block_ctxt cx, ValueRef to, &@ast::expr from, &ty::t unit_ty,
bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.recv,
~[bcx.fcx.lltaskptr, lldataptr, llportptr]);
auto data_load = load_if_immediate(bcx, to, unit_ty);
auto cp = copy_val(bcx, action, to, data_load, unit_ty);
bcx = cp.bcx;
// TODO: Any cleanup need to be done here?
ret rslt(bcx, to);
//auto cp = copy_val(bcx, action, to, data_load, unit_ty);
//bcx = cp.bcx;
add_clean_temp(cx, data_load, unit_ty);
ret rslt(bcx, data_load);
}
// Does a deep copy of a value. This is needed for passing arguments to child

View File

@ -4,7 +4,7 @@
// NB: please do not commit code with this uncommented. It's
// hugely expensive and should only be used as a last resort.
//
#define TRACK_ALLOCATIONS
// #define TRACK_ALLOCATIONS
#define MAGIC 0xbadc0ffe

View File

@ -4,12 +4,10 @@
/**
* Create a new rust channel and associate it with the specified port.
*/
rust_chan::rust_chan(rust_task *task,
maybe_proxy<rust_port> *port,
rust_chan::rust_chan(rust_kernel *kernel, maybe_proxy<rust_port> *port,
size_t unit_sz)
: ref_count(1),
kernel(task->kernel),
task(task),
kernel(kernel),
port(port),
buffer(kernel, unit_sz) {
if (port) {
@ -39,6 +37,7 @@ void rust_chan::associate(maybe_proxy<rust_port> *port) {
this, port);
++this->ref_count;
this->task = port->referent()->task;
this->task->ref();
this->port->referent()->chans.push(this);
}
}
@ -59,6 +58,7 @@ void rust_chan::disassociate() {
"disassociating chan: 0x%" PRIxPTR " from port: 0x%" PRIxPTR,
this, port->referent());
--this->ref_count;
--this->task->ref_count;
this->task = NULL;
port->referent()->chans.swap_delete(this);
}
@ -118,7 +118,7 @@ rust_chan *rust_chan::clone(maybe_proxy<rust_task> *target) {
target_task = target->as_proxy()->handle()->referent();
}
return new (target_task->kernel, "cloned chan")
rust_chan(target_task, port, unit_sz);
rust_chan(kernel, port, unit_sz);
}
/**

View File

@ -5,12 +5,13 @@ class rust_chan : public kernel_owned<rust_chan>,
public rust_cond {
public:
RUST_REFCOUNTED_WITH_DTOR(rust_chan, destroy())
rust_chan(rust_task *task, maybe_proxy<rust_port> *port, size_t unit_sz);
rust_chan(rust_kernel *kernel, maybe_proxy<rust_port> *port,
size_t unit_sz);
~rust_chan();
rust_kernel *kernel;
smart_ptr<rust_task> task;
rust_task *task;
maybe_proxy<rust_port> *port;
size_t idx;
circular_buffer buffer;

View File

@ -10,8 +10,8 @@ rust_port::rust_port(rust_task *task, size_t unit_sz)
PRIxPTR, (uintptr_t)task, unit_sz, (uintptr_t)this);
// Allocate a remote channel, for remote channel data.
remote_channel = new (task->kernel, "remote chan")
rust_chan(task, this, unit_sz);
remote_channel = new (kernel, "remote chan")
rust_chan(kernel, this, unit_sz);
}
rust_port::~rust_port() {

View File

@ -130,7 +130,7 @@ upcall_new_chan(rust_task *task, rust_port *port) {
(uintptr_t) task, task->name, port);
I(sched, port);
return new (task->kernel, "rust_chan")
rust_chan(task, port, port->unit_sz);
rust_chan(task->kernel, port, port->unit_sz);
}
/**

View File

@ -1,6 +1,4 @@
// xfail-stage0
// xfail-stage1
// xfail-stage2
use std;
import std::task;

View File

@ -1,6 +1,3 @@
// -*- rust -*-
// Tests of ports and channels on various types
@ -19,11 +16,11 @@ fn test_rec() {
}
fn test_vec() {
let port[vec[int]] po = port();
let chan[vec[int]] ch = chan(po);
let vec[int] v0 = [0, 1, 2];
let port[int[]] po = port();
let chan[int[]] ch = chan(po);
let int[] v0 = ~[0, 1, 2];
ch <| v0;
let vec[int] v1;
let int[] v1;
po |> v1;
assert (v1.(0) == 0);
assert (v1.(1) == 1);