Skip to content

Commit 77295c5

Browse files
committed
rt: Simplify the recv interface
1 parent 8e0efce commit 77295c5

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

src/libcore/comm.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ native mod rustrt {
4646
fn get_port_id(po: *rust_port) -> port_id;
4747
fn rust_port_size(po: *rust_port) -> ctypes::size_t;
4848
fn port_recv(dptr: *uint, po: *rust_port,
49-
yield: *ctypes::uintptr_t,
50-
killed: *ctypes::uintptr_t);
49+
yield: *ctypes::uintptr_t);
5150
fn rust_port_select(dptr: **rust_port, ports: **rust_port,
5251
n_ports: ctypes::size_t,
5352
yield: *ctypes::uintptr_t);
@@ -142,21 +141,19 @@ fn recv_<T: send>(p: *rust_port) -> T {
142141
// that will grab the value of the return pointer, then call this
143142
// function, which we will then use to call the runtime.
144143
fn recv(dptr: *uint, port: *rust_port,
145-
yield: *ctypes::uintptr_t,
146-
killed: *ctypes::uintptr_t) unsafe {
147-
rustrt::port_recv(dptr, port, yield, killed);
144+
yield: *ctypes::uintptr_t) unsafe {
145+
rustrt::port_recv(dptr, port, yield);
148146
}
149147
let yield = 0u;
150148
let yieldp = ptr::addr_of(yield);
151-
let killed = 0u;
152-
let killedp = ptr::addr_of(killed);
153-
let res = rusti::call_with_retptr(bind recv(_, p, yieldp, killedp));
154-
if killed != 0u {
155-
fail "killed";
156-
}
149+
let res = rusti::call_with_retptr(bind recv(_, p, yieldp));
157150
if yield != 0u {
158151
// Data isn't available yet, so res has not been initialized.
159152
task::yield();
153+
} else {
154+
// In the absense of compiler-generated preemption points
155+
// this is a good place to yield
156+
task::yield();
160157
}
161158
ret res;
162159
}
@@ -186,6 +183,10 @@ fn select2<A: send, B: send>(
186183
if yield != 0u {
187184
// Wait for data
188185
task::yield();
186+
} else {
187+
// As in recv, this is a good place to yield anyway until
188+
// the compiler generates yield calls
189+
task::yield();
189190
}
190191

191192
// Now we know the port we're supposed to receive from

src/rt/rust_builtin.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,8 @@ rust_task_yield(rust_task *task, bool *killed) {
543543
}
544544

545545
extern "C" CDECL void
546-
port_recv(uintptr_t *dptr, rust_port *port,
547-
uintptr_t *yield, uintptr_t *killed) {
546+
port_recv(uintptr_t *dptr, rust_port *port, uintptr_t *yield) {
548547
*yield = false;
549-
*killed = false;
550548
rust_task *task = rust_task_thread::get_task();
551549
{
552550
scoped_lock with(port->lock);
@@ -559,13 +557,6 @@ port_recv(uintptr_t *dptr, rust_port *port,
559557
return;
560558
}
561559

562-
// If this task has been killed then we're not going to bother
563-
// blocking, we have to unwind.
564-
if (task->must_fail_from_being_killed()) {
565-
*killed = true;
566-
return;
567-
}
568-
569560
// No data was buffered on any incoming channel, so block this task on
570561
// the port. Remember the rendezvous location so that any sender task
571562
// can write to it before waking up this task.

0 commit comments

Comments
 (0)