about summary refs log tree commit diff
path: root/src/rt/rust_kernel.cpp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-04-01 00:13:59 -0700
committerBrian Anderson <banderson@mozilla.com>2012-04-01 00:15:04 -0700
commite78396850d8e27138dd06e723de5ad3de0e65950 (patch)
tree3768b6007a00186902b099efe24bf5ee82195cb3 /src/rt/rust_kernel.cpp
parent21064637ed8b8259d1305f21ace12c40b9561706 (diff)
parentde47fcfdf9404d53940099f5e7810bdb2bf37af3 (diff)
downloadrust-e78396850d8e27138dd06e723de5ad3de0e65950.tar.gz
rust-e78396850d8e27138dd06e723de5ad3de0e65950.zip
Merge remote-tracking branch 'brson/mainthread'
Conflicts:
	src/rt/rust_sched_loop.cpp
	src/rt/rust_shape.cpp
	src/rt/rust_task.cpp
Diffstat (limited to 'src/rt/rust_kernel.cpp')
-rw-r--r--src/rt/rust_kernel.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp
index 896a4de660b..c7625537f40 100644
--- a/src/rt/rust_kernel.cpp
+++ b/src/rt/rust_kernel.cpp
@@ -17,6 +17,7 @@ rust_kernel::rust_kernel(rust_srv *srv) :
     max_port_id(0),
     rval(0),
     max_sched_id(0),
+    sched_reaper(this),
     env(srv->env)
 {
 }
@@ -62,6 +63,9 @@ rust_kernel::create_scheduler(size_t num_threads) {
     rust_scheduler *sched;
     {
         scoped_lock with(sched_lock);
+        // If this is the first scheduler then we need to launch
+        // the scheduler reaper.
+        bool start_reaper = sched_table.empty();
         id = max_sched_id++;
         K(srv, id != INTPTR_MAX, "Hit the maximum scheduler id");
         sched = new (this, "rust_scheduler")
@@ -70,6 +74,9 @@ rust_kernel::create_scheduler(size_t num_threads) {
             .insert(std::pair<rust_sched_id,
                               rust_scheduler*>(id, sched)).second;
         A(this, is_new, "Reusing a sched id?");
+        if (start_reaper) {
+            sched_reaper.start();
+        }
     }
     sched->start_task_threads();
     return id;
@@ -97,12 +104,12 @@ rust_kernel::release_scheduler_id(rust_sched_id id) {
 }
 
 /*
-Called on the main thread to wait for the kernel to exit. This function is
-also used to join on every terminating scheduler thread, so that we can be
-sure they have completely exited before the process exits.  If we don't join
-them then we can see valgrind errors due to un-freed pthread memory.
+Called by rust_sched_reaper to join every every terminating scheduler thread,
+so that we can be sure they have completely exited before the process exits.
+If we don't join them then we can see valgrind errors due to un-freed pthread
+memory.
  */
-int
+void
 rust_kernel::wait_for_schedulers()
 {
     scoped_lock with(sched_lock);
@@ -121,6 +128,12 @@ rust_kernel::wait_for_schedulers()
             sched_lock.wait();
         }
     }
+}
+
+/* Called on the main thread to wait for the kernel to exit */
+int
+rust_kernel::wait_for_exit() {
+    sched_reaper.join();
     return rval;
 }