Skip to content

Choose task thread in rust_scheduler by round robin #2086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/rt/rust_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ rust_scheduler::rust_scheduler(rust_kernel *kernel,
live_threads(num_threads),
live_tasks(0),
num_threads(num_threads),
cur_thread(0),
id(id)
{
isaac_init(kernel, &rctx);
create_task_threads();
}

Expand Down Expand Up @@ -86,9 +86,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++;
thread_no = cur_thread++;
if (cur_thread >= num_threads)
cur_thread = 0;
}
rust_task_thread *thread = threads[thread_no];
return thread->create_task(spawner, name);
Expand All @@ -98,11 +100,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
Expand All @@ -129,10 +131,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);
}
}
4 changes: 2 additions & 2 deletions src/rt/rust_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ class rust_scheduler : public kernel_owned<rust_scheduler> {
rust_srv *srv;
rust_env *env;
private:
// Protects the random number context and live_threads
// Protects live_threads and cur_thread increments
lock_and_signal lock;
// When this hits zero we'll tell the kernel to release us
uintptr_t live_threads;
// When this hits zero we'll tell the threads to exit
uintptr_t live_tasks;
randctx rctx;

array_list<rust_task_thread *> threads;
const size_t num_threads;
size_t cur_thread;

rust_sched_id id;

Expand Down