about summary refs log tree commit diff
path: root/src/rt/rust.cpp
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-06-20 18:01:38 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-06-27 09:58:39 -0700
commitcb00befff050e69565d2862b458bbd56f20b7cd3 (patch)
tree659f2b8f8d7bbe114e75ab6a6695b1ced3ab3243 /src/rt/rust.cpp
parent4bc773465fe95da37b8c867979786b190de6197c (diff)
downloadrust-cb00befff050e69565d2862b458bbd56f20b7cd3.tar.gz
rust-cb00befff050e69565d2862b458bbd56f20b7cd3.zip
Added an environment variable to control how many threads to use.
Diffstat (limited to 'src/rt/rust.cpp')
-rw-r--r--src/rt/rust.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/rt/rust.cpp b/src/rt/rust.cpp
index f1666b2e7a7..62cb6fe3bf3 100644
--- a/src/rt/rust.cpp
+++ b/src/rt/rust.cpp
@@ -71,6 +71,19 @@ command_line_args : public dom_owned<command_line_args>
     }
 };
 
+int get_num_threads()
+{
+    char *env = getenv("RUST_THREADS");
+    if(env) {
+        int num = atoi(env);
+        if(num > 0)
+            return num;
+    }
+    // TODO: in this case, determine the number of CPUs present on the
+    // machine.
+    return 1;
+}
+
 /**
  * Main entry point into the Rust runtime. Here we create a Rust service,
  * initialize the kernel, create the root domain and run it.
@@ -95,7 +108,11 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
 
     dom->root_task->start(main_fn, (uintptr_t)args->args);
 
-    int ret = dom->start_main_loops(8);
+    int num_threads = get_num_threads();
+
+    DLOG(dom, dom, "Using %d worker threads.", num_threads);
+
+    int ret = dom->start_main_loops(num_threads);
     delete args;
     kernel->destroy_domain(dom);
     kernel->join_all_domains();