rt: Implement ThreadPerCore scheduling mode

Fixes #3465.
This commit is contained in:
Philipp Brüschweiler 2012-09-13 20:47:35 +02:00
parent 308ca06012
commit 62b51d9152
3 changed files with 22 additions and 5 deletions

View File

@ -1403,11 +1403,9 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
let num_threads = match opts.mode {
SingleThreaded => 1u,
ThreadPerCore => {
fail ~"thread_per_core scheduling mode unimplemented"
}
ThreadPerCore => rustrt::rust_num_threads(),
ThreadPerTask => {
fail ~"thread_per_task scheduling mode unimplemented"
fail ~"ThreadPerTask scheduling mode unimplemented"
}
ManualThreads(threads) => {
if threads == 0u {
@ -1657,6 +1655,8 @@ extern mod rustrt {
fn rust_get_sched_id() -> sched_id;
fn rust_new_sched(num_threads: libc::uintptr_t) -> sched_id;
fn sched_threads() -> libc::size_t;
fn rust_num_threads() -> libc::uintptr_t;
fn get_task_id() -> task_id;
#[rust_stack]
@ -2422,3 +2422,13 @@ fn test_tls_cleanup_on_failure() unsafe {
local_data_set(int_key, @31337);
fail;
}
#[test]
fn test_sched_thread_per_core() {
let cores = rustrt::rust_num_threads();
let mut reported_threads = 0u;
do spawn_sched(ThreadPerCore) {
reported_threads = rustrt::sched_threads();
}
assert(cores == reported_threads);
}

View File

@ -572,6 +572,12 @@ rust_get_sched_id() {
return task->sched->get_id();
}
extern "C" CDECL uintptr_t
rust_num_threads() {
rust_task *task = rust_get_current_task();
return task->kernel->env->num_sched_threads;
}
extern "C" CDECL rust_sched_id
rust_new_sched(uintptr_t threads) {
rust_task *task = rust_get_current_task();
@ -620,7 +626,7 @@ start_task(rust_task *target, fn_env_pair *f) {
target->start(f->f, f->env, NULL);
}
extern "C" CDECL int
extern "C" CDECL size_t
sched_threads() {
rust_task *task = rust_get_current_task();
return task->sched->number_of_threads();

View File

@ -32,6 +32,7 @@ rand_seed
rust_get_sched_id
rust_new_sched
rust_new_task_in_sched
rust_num_threads
rust_path_is_dir
rust_path_exists
rust_getcwd