From 5d625af9f944c7b6567c443a6f796e30dbb01bf2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 15 May 2012 14:03:59 -0700 Subject: [PATCH] rt: Make task killing synchronization possibly more correct I could not come up with a test but this looks better to me. --- src/rt/rust_task.cpp | 4 +++- src/rt/rust_task.h | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index 823937443b5..2331cccd590 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -248,7 +248,7 @@ rust_task::kill() { killed = true; // Unblock the task so it can unwind. - if (blocked()) { + if (blocked() && must_fail_from_being_killed_unlocked()) { wakeup(cond); } @@ -648,11 +648,13 @@ rust_task::on_rust_stack() { void rust_task::inhibit_kill() { + scoped_lock with(kill_lock); disallow_kill = true; } void rust_task::allow_kill() { + scoped_lock with(kill_lock); disallow_kill = false; } diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index 1867c8f4ed8..69a56e425de 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -149,7 +149,7 @@ private: rust_cond *cond; const char *cond_name; - // Protects the killed flag + // Protects the killed flag, disallow_kill flag, reentered_rust_stack lock_and_signal kill_lock; // Indicates that the task was killed and needs to unwind bool killed; @@ -372,7 +372,10 @@ rust_task::call_on_rust_stack(void *args, void *fn_ptr) { assert(next_rust_sp); bool had_reentered_rust_stack = reentered_rust_stack; - reentered_rust_stack = true; + { + scoped_lock with(kill_lock); + reentered_rust_stack = true; + } uintptr_t prev_c_sp = next_c_sp; next_c_sp = get_sp(); @@ -384,7 +387,10 @@ rust_task::call_on_rust_stack(void *args, void *fn_ptr) { __morestack(args, fn_ptr, sp); next_c_sp = prev_c_sp; - reentered_rust_stack = had_reentered_rust_stack; + { + scoped_lock with(kill_lock); + reentered_rust_stack = had_reentered_rust_stack; + } } inline void