about summary refs log tree commit diff
path: root/src/rt/rust_scheduler.cpp
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-07-25 18:00:37 -0700
committerEric Holk <eholk@mozilla.com>2011-07-28 10:47:28 -0700
commit5302cde188bba80dd38c58eaafa792d621b0818c (patch)
tree663ca3e81a7254548e756ea0dfef66d4362f971a /src/rt/rust_scheduler.cpp
parente697a52359874c2b7387be96e664b1f94b14255b (diff)
downloadrust-5302cde188bba80dd38c58eaafa792d621b0818c.tar.gz
rust-5302cde188bba80dd38c58eaafa792d621b0818c.zip
Made task threads wait instead of sleep, so they can be woken up. This appears to give us much better parallel performance.
Also, commented out one more unsafe log and updated rust_kernel.cpp to compile under g++
Diffstat (limited to 'src/rt/rust_scheduler.cpp')
-rw-r--r--src/rt/rust_scheduler.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/rt/rust_scheduler.cpp b/src/rt/rust_scheduler.cpp
index 437be04e272..4f19b0c681b 100644
--- a/src/rt/rust_scheduler.cpp
+++ b/src/rt/rust_scheduler.cpp
@@ -87,6 +87,7 @@ rust_scheduler::reap_dead_tasks(int id) {
     I(this, lock.lock_held_by_current_thread());
     for (size_t i = 0; i < dead_tasks.length(); ) {
         rust_task *task = dead_tasks[i];
+        task->lock.lock();
         // Make sure this task isn't still running somewhere else...
         if (task->ref_count == 0 && task->can_schedule(id)) {
             I(this, task->tasks_waiting_to_join.is_empty());
@@ -94,10 +95,13 @@ rust_scheduler::reap_dead_tasks(int id) {
             DLOG(this, task,
                 "deleting unreferenced dead task %s @0x%" PRIxPTR,
                 task->name, task);
+            task->lock.unlock();
             delete task;
             sync::decrement(kernel->live_tasks);
+            kernel->wakeup_schedulers();
             continue;
         }
+        task->lock.unlock();
         ++i;
     }
 }
@@ -206,21 +210,15 @@ rust_scheduler::start_main_loop() {
 
         rust_task *scheduled_task = schedule_task(id);
 
-        // The scheduler busy waits until a task is available for scheduling.
-        // Eventually we'll want a smarter way to do this, perhaps sleep
-        // for a minimum amount of time.
-
         if (scheduled_task == NULL) {
             log_state();
             DLOG(this, task,
                  "all tasks are blocked, scheduler id %d yielding ...",
                  id);
-            lock.unlock();
-            sync::sleep(100);
-            lock.lock();
-            DLOG(this, task,
-                "scheduler resuming ...");
+            lock.timed_wait(100000);
             reap_dead_tasks(id);
+            DLOG(this, task,
+                 "scheduler %d resuming ...", id);
             continue;
         }