about summary refs log tree commit diff
path: root/src/rt/rust_task.cpp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-03-02 23:40:27 -0800
committerBrian Anderson <banderson@mozilla.com>2012-03-05 19:39:55 -0800
commit237652299ec5fa3529ac7bd1bfddc52b7526bb82 (patch)
tree005becc9376cdc71633bba87edbe78c8912efcc1 /src/rt/rust_task.cpp
parent0432030c2727183f3cbda0263de2ca2b90c37353 (diff)
downloadrust-237652299ec5fa3529ac7bd1bfddc52b7526bb82.tar.gz
rust-237652299ec5fa3529ac7bd1bfddc52b7526bb82.zip
rt: Protect cond and cond_name with the state_lock
Diffstat (limited to 'src/rt/rust_task.cpp')
-rw-r--r--src/rt/rust_task.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp
index 7b5b528782b..3c375f0b4c3 100644
--- a/src/rt/rust_task.cpp
+++ b/src/rt/rust_task.cpp
@@ -74,8 +74,6 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
     cache(NULL),
     kernel(thread->kernel),
     name(name),
-    cond(NULL),
-    cond_name("none"),
     list_index(-1),
     next_port_id(0),
     rendezvous_ptr(0),
@@ -87,6 +85,8 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
     cc_counter(0),
     total_stack_sz(0),
     state(state),
+    cond(NULL),
+    cond_name("none"),
     killed(false),
     reentered_rust_stack(false),
     c_stack(NULL),
@@ -242,7 +242,7 @@ rust_task::start(spawn_fn spawnee_fn,
 
 void rust_task::start()
 {
-    transition(&thread->newborn_tasks, &thread->running_tasks);
+    transition(&thread->newborn_tasks, &thread->running_tasks, NULL, "none");
 }
 
 bool
@@ -369,7 +369,8 @@ rust_task::blocked()
 bool
 rust_task::blocked_on(rust_cond *on)
 {
-    return blocked() && cond == on;
+    scoped_lock with(state_lock);
+    return cond == on;
 }
 
 bool
@@ -398,7 +399,8 @@ rust_task::free(void *p)
 }
 
 void
-rust_task::transition(rust_task_list *src, rust_task_list *dst) {
+rust_task::transition(rust_task_list *src, rust_task_list *dst,
+                      rust_cond *cond, const char* cond_name) {
     bool unlock = false;
     if(!thread->lock.lock_held_by_current_thread()) {
         unlock = true;
@@ -413,6 +415,8 @@ rust_task::transition(rust_task_list *src, rust_task_list *dst) {
     {
         scoped_lock with(state_lock);
         state = dst;
+        this->cond = cond;
+        this->cond_name = cond_name;
     }
     thread->lock.signal();
     if(unlock)
@@ -426,9 +430,7 @@ rust_task::block(rust_cond *on, const char* name) {
     A(thread, cond == NULL, "Cannot block an already blocked task.");
     A(thread, on != NULL, "Cannot block on a NULL object.");
 
-    transition(&thread->running_tasks, &thread->blocked_tasks);
-    cond = on;
-    cond_name = name;
+    transition(&thread->running_tasks, &thread->blocked_tasks, on, name);
 }
 
 void
@@ -438,14 +440,12 @@ rust_task::wakeup(rust_cond *from) {
                         (uintptr_t) cond, (uintptr_t) from);
     A(thread, cond == from, "Cannot wake up blocked task on wrong condition.");
 
-    cond = NULL;
-    cond_name = "none";
-    transition(&thread->blocked_tasks, &thread->running_tasks);
+    transition(&thread->blocked_tasks, &thread->running_tasks, NULL, "none");
 }
 
 void
 rust_task::die() {
-    transition(&thread->running_tasks, &thread->dead_tasks);
+    transition(&thread->running_tasks, &thread->dead_tasks, NULL, "none");
 }
 
 void