Modify task::join to indicate how the task terminated
This involves sticking yet another field into the task structure
This commit is contained in:
parent
d9cc4cb81b
commit
ced8393f20
@ -1,7 +1,7 @@
|
|||||||
native "rust" mod rustrt {
|
native "rust" mod rustrt {
|
||||||
fn task_sleep(uint time_in_us);
|
fn task_sleep(uint time_in_us);
|
||||||
fn task_yield();
|
fn task_yield();
|
||||||
fn task_join(task t);
|
fn task_join(task t) -> int;
|
||||||
fn task_unsupervise();
|
fn task_unsupervise();
|
||||||
fn pin_task();
|
fn pin_task();
|
||||||
fn unpin_task();
|
fn unpin_task();
|
||||||
@ -20,8 +20,16 @@ fn yield() {
|
|||||||
ret rustrt::task_yield();
|
ret rustrt::task_yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn join(task t) {
|
tag task_result {
|
||||||
ret rustrt::task_join(t);
|
tr_success;
|
||||||
|
tr_failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn join(task t) -> task_result {
|
||||||
|
alt (rustrt::task_join(t)) {
|
||||||
|
0 { tr_success }
|
||||||
|
_ { tr_failure }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unsupervise() {
|
fn unsupervise() {
|
||||||
|
@ -410,7 +410,7 @@ task_yield(rust_task *task) {
|
|||||||
task->yield(1);
|
task->yield(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" CDECL void
|
extern "C" CDECL intptr_t
|
||||||
task_join(rust_task *task, rust_task *join_task) {
|
task_join(rust_task *task, rust_task *join_task) {
|
||||||
// If the other task is already dying, we don't have to wait for it.
|
// If the other task is already dying, we don't have to wait for it.
|
||||||
join_task->lock.lock();
|
join_task->lock.lock();
|
||||||
@ -423,6 +423,11 @@ task_join(rust_task *task, rust_task *join_task) {
|
|||||||
else {
|
else {
|
||||||
join_task->lock.unlock();
|
join_task->lock.unlock();
|
||||||
}
|
}
|
||||||
|
if (!join_task->failed) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" CDECL void
|
extern "C" CDECL void
|
||||||
|
@ -82,7 +82,8 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
|
|||||||
running_on(-1),
|
running_on(-1),
|
||||||
pinned_on(-1),
|
pinned_on(-1),
|
||||||
local_region(&sched->srv->local_region),
|
local_region(&sched->srv->local_region),
|
||||||
_on_wakeup(NULL)
|
_on_wakeup(NULL),
|
||||||
|
failed(false)
|
||||||
{
|
{
|
||||||
LOGPTR(sched, "new task", (uintptr_t)this);
|
LOGPTR(sched, "new task", (uintptr_t)this);
|
||||||
DLOG(sched, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this);
|
DLOG(sched, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this);
|
||||||
@ -230,6 +231,7 @@ rust_task::fail() {
|
|||||||
// FIXME: implement unwinding again.
|
// FIXME: implement unwinding again.
|
||||||
if (this == sched->root_task)
|
if (this == sched->root_task)
|
||||||
sched->fail();
|
sched->fail();
|
||||||
|
failed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -89,6 +89,9 @@ rust_task : public maybe_proxy<rust_task>,
|
|||||||
|
|
||||||
wakeup_callback *_on_wakeup;
|
wakeup_callback *_on_wakeup;
|
||||||
|
|
||||||
|
// Indicates that the task ended in failure
|
||||||
|
bool failed;
|
||||||
|
|
||||||
lock_and_signal lock;
|
lock_and_signal lock;
|
||||||
|
|
||||||
// Only a pointer to 'name' is kept, so it must live as long as this task.
|
// Only a pointer to 'name' is kept, so it must live as long as this task.
|
||||||
|
@ -15,8 +15,27 @@ fn test_unsupervise() {
|
|||||||
spawn f();
|
spawn f();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_join() {
|
||||||
|
fn winner() {
|
||||||
|
}
|
||||||
|
|
||||||
|
auto wintask = spawn winner();
|
||||||
|
|
||||||
|
assert task::join(wintask) == task::tr_success;
|
||||||
|
|
||||||
|
fn failer() {
|
||||||
|
task::unsupervise();
|
||||||
|
fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto failtask = spawn failer();
|
||||||
|
|
||||||
|
assert task::join(failtask) == task::tr_failure;
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// FIXME: Why aren't we running this?
|
// FIXME: Why aren't we running this?
|
||||||
//test_sleep();
|
//test_sleep();
|
||||||
test_unsupervise();
|
test_unsupervise();
|
||||||
|
test_join();
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ use std;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
auto t = spawn child(10);
|
auto t = spawn child(10);
|
||||||
std::task::join(t)
|
std::task::join(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child(int i) {
|
fn child(int i) {
|
||||||
|
Loading…
Reference in New Issue
Block a user