about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-05-15 14:03:59 -0700
committerBrian Anderson <banderson@mozilla.com>2012-05-15 16:13:42 -0700
commit5d625af9f944c7b6567c443a6f796e30dbb01bf2 (patch)
tree469e7cf76a36fa85f92c37f632e0a3fe4e42c7bc
parentc424b7f847bbec50d01b00a89e044d80b8eb59f8 (diff)
downloadrust-5d625af9f944c7b6567c443a6f796e30dbb01bf2.tar.gz
rust-5d625af9f944c7b6567c443a6f796e30dbb01bf2.zip
rt: Make task killing synchronization possibly more correct
I could not come up with a test but this looks better to me.
-rw-r--r--src/rt/rust_task.cpp4
-rw-r--r--src/rt/rust_task.h12
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