Merge pull request #3487 from Blei/fix-3465
rt: Implement ThreadPerCore scheduling mode
This commit is contained in:
commit
6f9539a15c
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user