Skip to content

Commit ced8393

Browse files
committed
Modify task::join to indicate how the task terminated
This involves sticking yet another field into the task structure
1 parent d9cc4cb commit ced8393

File tree

6 files changed

+43
-6
lines changed

6 files changed

+43
-6
lines changed

src/lib/task.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
native "rust" mod rustrt {
22
fn task_sleep(uint time_in_us);
33
fn task_yield();
4-
fn task_join(task t);
4+
fn task_join(task t) -> int;
55
fn task_unsupervise();
66
fn pin_task();
77
fn unpin_task();
@@ -20,8 +20,16 @@ fn yield() {
2020
ret rustrt::task_yield();
2121
}
2222

23-
fn join(task t) {
24-
ret rustrt::task_join(t);
23+
tag task_result {
24+
tr_success;
25+
tr_failure;
26+
}
27+
28+
fn join(task t) -> task_result {
29+
alt (rustrt::task_join(t)) {
30+
0 { tr_success }
31+
_ { tr_failure }
32+
}
2533
}
2634

2735
fn unsupervise() {

src/rt/rust_builtin.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ task_yield(rust_task *task) {
410410
task->yield(1);
411411
}
412412

413-
extern "C" CDECL void
413+
extern "C" CDECL intptr_t
414414
task_join(rust_task *task, rust_task *join_task) {
415415
// If the other task is already dying, we don't have to wait for it.
416416
join_task->lock.lock();
@@ -423,6 +423,11 @@ task_join(rust_task *task, rust_task *join_task) {
423423
else {
424424
join_task->lock.unlock();
425425
}
426+
if (!join_task->failed) {
427+
return 0;
428+
} else {
429+
return -1;
430+
}
426431
}
427432

428433
extern "C" CDECL void

src/rt/rust_task.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
8282
running_on(-1),
8383
pinned_on(-1),
8484
local_region(&sched->srv->local_region),
85-
_on_wakeup(NULL)
85+
_on_wakeup(NULL),
86+
failed(false)
8687
{
8788
LOGPTR(sched, "new task", (uintptr_t)this);
8889
DLOG(sched, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this);
@@ -230,6 +231,7 @@ rust_task::fail() {
230231
// FIXME: implement unwinding again.
231232
if (this == sched->root_task)
232233
sched->fail();
234+
failed = true;
233235
}
234236

235237
void

src/rt/rust_task.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ rust_task : public maybe_proxy<rust_task>,
8989

9090
wakeup_callback *_on_wakeup;
9191

92+
// Indicates that the task ended in failure
93+
bool failed;
94+
9295
lock_and_signal lock;
9396

9497
// Only a pointer to 'name' is kept, so it must live as long as this task.

src/test/run-pass/lib-task.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,27 @@ fn test_unsupervise() {
1515
spawn f();
1616
}
1717

18+
fn test_join() {
19+
fn winner() {
20+
}
21+
22+
auto wintask = spawn winner();
23+
24+
assert task::join(wintask) == task::tr_success;
25+
26+
fn failer() {
27+
task::unsupervise();
28+
fail;
29+
}
30+
31+
auto failtask = spawn failer();
32+
33+
assert task::join(failtask) == task::tr_failure;
34+
}
35+
1836
fn main() {
1937
// FIXME: Why aren't we running this?
2038
//test_sleep();
2139
test_unsupervise();
40+
test_join();
2241
}

src/test/run-pass/spawn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std;
55

66
fn main() {
77
auto t = spawn child(10);
8-
std::task::join(t)
8+
std::task::join(t);
99
}
1010

1111
fn child(int i) {

0 commit comments

Comments
 (0)