about summary refs log tree commit diff
path: root/src/rt/rust_scheduler.cpp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-02-04 14:54:10 -0800
committerBrian Anderson <banderson@mozilla.com>2012-02-08 15:33:40 -0800
commitf39e64d56ab4929be5985d4a64020d2223706d96 (patch)
tree0c3c810c87372216986d47eadd9476a0d9150117 /src/rt/rust_scheduler.cpp
parent6eafe5d772131c644a40ae1013a6016dcba037c4 (diff)
downloadrust-f39e64d56ab4929be5985d4a64020d2223706d96.tar.gz
rust-f39e64d56ab4929be5985d4a64020d2223706d96.zip
rt: Change the scheme used for terminating the kernel
Instead of joining on the scheduler threads, instead keep a count of active
schedulers. When there are no more schedulers raise a signal for the main
thread to continue.

This will be required once schedulers can be added and removed from the
running kernel.
Diffstat (limited to 'src/rt/rust_scheduler.cpp')
-rw-r--r--src/rt/rust_scheduler.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/rt/rust_scheduler.cpp b/src/rt/rust_scheduler.cpp
index 3e306cc418d..904eb5cafcb 100644
--- a/src/rt/rust_scheduler.cpp
+++ b/src/rt/rust_scheduler.cpp
@@ -7,6 +7,7 @@ rust_scheduler::rust_scheduler(rust_kernel *kernel,
     kernel(kernel),
     srv(srv),
     env(srv->env),
+    live_threads(num_threads),
     num_threads(num_threads)
 {
     isaac_init(kernel, &rctx);
@@ -59,11 +60,6 @@ rust_scheduler::start_task_threads()
         rust_task_thread *thread = threads[i];
         thread->start();
     }
-
-    for(size_t i = 0; i < num_threads; ++i) {
-        rust_task_thread *thread = threads[i];
-        thread->join();
-    }
 }
 
 void
@@ -102,3 +98,16 @@ size_t
 rust_scheduler::number_of_threads() {
     return num_threads;
 }
+
+void
+rust_scheduler::release_task_thread() {
+    I(this, !lock.lock_held_by_current_thread());
+    uintptr_t new_live_threads;
+    {
+	scoped_lock with(lock);
+	new_live_threads = --live_threads;
+    }
+    if (new_live_threads == 0) {
+	kernel->release_scheduler();
+    }
+}