Skip to content

Commit 792068d

Browse files
committed
rt: Remove unblock call from rust_task::yield
1 parent 0f339b4 commit 792068d

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/lib/comm.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ native mod rustrt {
4949
fn get_port_id(po: *rust_port) -> port_id;
5050
fn rust_port_size(po: *rust_port) -> ctypes::size_t;
5151
fn port_recv(dptr: *uint, po: *rust_port,
52-
yield: *ctypes::uintptr_t);
52+
yield: *ctypes::uintptr_t,
53+
killed: *ctypes::uintptr_t);
5354
}
5455

5556
#[abi = "rust-intrinsic"]
@@ -152,20 +153,29 @@ fn recv_<send T>(p: *rustrt::rust_port) -> T {
152153
// that will grab the value of the return pointer, then call this
153154
// function, which we will then use to call the runtime.
154155
fn recv(dptr: *uint, port: *rustrt::rust_port,
155-
yield: *ctypes::uintptr_t) unsafe {
156-
rustrt::port_recv(dptr,
157-
port, yield);
156+
yield: *ctypes::uintptr_t,
157+
killed: *ctypes::uintptr_t) unsafe {
158+
rustrt::port_recv(dptr, port, yield, killed);
158159
}
159160
let yield = 0u;
160161
let yieldp = ptr::addr_of(yield);
161-
let res = rusti::call_with_retptr(bind recv(_, p, yieldp));
162+
let killed = 0u;
163+
let killedp = ptr::addr_of(killed);
164+
let res = rusti::call_with_retptr(bind recv(_, p, yieldp, killedp));
165+
if killed != 0u {
166+
fail_killed();
167+
}
162168
if yield != 0u {
163169
// Data isn't available yet, so res has not been initialized.
164170
task::yield();
165171
}
166172
ret res;
167173
}
168174

175+
fn fail_killed() -> ! {
176+
fail "killed";
177+
}
178+
169179
/*
170180
Function: chan
171181

src/rt/rust_builtin.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,10 @@ rust_task_sleep(rust_task *task, size_t time_in_us) {
516516
}
517517

518518
extern "C" CDECL void
519-
port_recv(uintptr_t *dptr, rust_port *port, uintptr_t *yield) {
519+
port_recv(uintptr_t *dptr, rust_port *port,
520+
uintptr_t *yield, uintptr_t *killed) {
521+
*yield = false;
522+
*killed = false;
520523
rust_task *task = rust_scheduler::get_task();
521524
{
522525
scoped_lock with(port->lock);
@@ -526,7 +529,13 @@ port_recv(uintptr_t *dptr, rust_port *port, uintptr_t *yield) {
526529
(uintptr_t) port, (uintptr_t) dptr, port->unit_sz);
527530

528531
if (port->receive(dptr)) {
529-
*yield = false;
532+
return;
533+
}
534+
535+
// If this task has been killed then we're not going to bother
536+
// blocking, we have to unwind.
537+
if (task->killed) {
538+
*killed = true;
530539
return;
531540
}
532541

src/rt/rust_task.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,10 @@ rust_task::yield(size_t time_in_us) {
272272
name, this, time_in_us);
273273

274274
if (killed) {
275-
// Receive may have blocked before yielding
276-
unblock();
275+
A(sched, !blocked(), "Shouldn't be blocked before failing");
277276
fail();
278277
}
279278

280-
// FIXME: If we are blocked, and get killed right here then we may never
281-
// know it.
282-
283279
yield_timer.reset_us(time_in_us);
284280

285281
// Return to the scheduler.

0 commit comments

Comments
 (0)