diff options
| author | Jon Morton <jonanin@gmail.com> | 2012-03-31 01:57:29 -0500 |
|---|---|---|
| committer | Jon Morton <jonanin@gmail.com> | 2012-03-31 02:14:44 -0500 |
| commit | 8aee42a382eff8fc35d1341be5b307da87a25603 (patch) | |
| tree | 5c8d3dd336a8804a1001408d46a8fa56f13cd8af /src/rt/rust_scheduler.cpp | |
| parent | 0904f255075d3c20f16d4ca2d1db14cac3fbb2de (diff) | |
| download | rust-8aee42a382eff8fc35d1341be5b307da87a25603.tar.gz rust-8aee42a382eff8fc35d1341be5b307da87a25603.zip | |
Choose task thread in rust_scheduler by round robin
Remove the random context from rust_scheduler and use a simple round robin system to choose which thread a new task gets put on. Also, some incorrect tab indents around scoped blocks were fixed.
Diffstat (limited to 'src/rt/rust_scheduler.cpp')
| -rw-r--r-- | src/rt/rust_scheduler.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/rt/rust_scheduler.cpp b/src/rt/rust_scheduler.cpp index 8daee562647..8b50cfa87d2 100644 --- a/src/rt/rust_scheduler.cpp +++ b/src/rt/rust_scheduler.cpp @@ -13,7 +13,6 @@ rust_scheduler::rust_scheduler(rust_kernel *kernel, num_threads(num_threads), id(id) { - isaac_init(kernel, &rctx); create_task_threads(); } @@ -86,9 +85,11 @@ rust_task * rust_scheduler::create_task(rust_task *spawner, const char *name) { size_t thread_no; { - scoped_lock with(lock); - thread_no = isaac_rand(&rctx) % num_threads; - live_tasks++; + scoped_lock with(lock); + live_tasks++; + if (++cur_thread >= num_threads) + cur_thread = 0; + thread_no = cur_thread; } rust_task_thread *thread = threads[thread_no]; return thread->create_task(spawner, name); @@ -98,11 +99,11 @@ void rust_scheduler::release_task() { bool need_exit = false; { - scoped_lock with(lock); - live_tasks--; - if (live_tasks == 0) { - need_exit = true; - } + scoped_lock with(lock); + live_tasks--; + if (live_tasks == 0) { + need_exit = true; + } } if (need_exit) { // There are no more tasks on this scheduler. Time to leave @@ -129,10 +130,10 @@ void rust_scheduler::release_task_thread() { uintptr_t new_live_threads; { - scoped_lock with(lock); - new_live_threads = --live_threads; + scoped_lock with(lock); + new_live_threads = --live_threads; } if (new_live_threads == 0) { - kernel->release_scheduler_id(id); + kernel->release_scheduler_id(id); } } |
