rt: Protect rust_task::killed with a lock

This commit is contained in:
Brian Anderson 2012-03-02 20:55:40 -08:00
parent 8a4c8bab84
commit d7298a797b
2 changed files with 13 additions and 4 deletions

View file

@ -155,9 +155,12 @@ cleanup_task(cleanup_args *args) {
task->die();
if (task->killed && !threw_exception) {
LOG(task, task, "Task killed during termination");
threw_exception = true;
{
scoped_lock with(task->kill_lock);
if (task->killed && !threw_exception) {
LOG(task, task, "Task killed during termination");
threw_exception = true;
}
}
task->notify(!threw_exception);
@ -244,6 +247,7 @@ void rust_task::start()
bool
rust_task::must_fail_from_being_killed() {
scoped_lock with(kill_lock);
return killed && !reentered_rust_stack;
}
@ -275,7 +279,10 @@ rust_task::kill() {
// If you want to fail yourself you do self->fail().
LOG(this, task, "killing task %s @0x%" PRIxPTR, name, this);
// When the task next goes to yield or resume it will fail
killed = true;
{
scoped_lock with(kill_lock);
killed = true;
}
// Unblock the task so it can unwind.
unblock();

View file

@ -107,6 +107,8 @@ rust_task : public kernel_owned<rust_task>, rust_cond
private:
// Protects the killed flag
lock_and_signal kill_lock;
// Indicates that the task was killed and needs to unwind
bool killed;
// Indicates that we've called back into Rust from C