Skip to content

Commit 3d9d998

Browse files
committed
---
yaml --- r: 12238 b: refs/heads/master c: 8aee42a h: refs/heads/master v: v3
1 parent 2140a44 commit 3d9d998

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0904f255075d3c20f16d4ca2d1db14cac3fbb2de
2+
refs/heads/master: 8aee42a382eff8fc35d1341be5b307da87a25603
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rt/rust_scheduler.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ rust_scheduler::rust_scheduler(rust_kernel *kernel,
1313
num_threads(num_threads),
1414
id(id)
1515
{
16-
isaac_init(kernel, &rctx);
1716
create_task_threads();
1817
}
1918

@@ -86,9 +85,11 @@ rust_task *
8685
rust_scheduler::create_task(rust_task *spawner, const char *name) {
8786
size_t thread_no;
8887
{
89-
scoped_lock with(lock);
90-
thread_no = isaac_rand(&rctx) % num_threads;
91-
live_tasks++;
88+
scoped_lock with(lock);
89+
live_tasks++;
90+
if (++cur_thread >= num_threads)
91+
cur_thread = 0;
92+
thread_no = cur_thread;
9293
}
9394
rust_task_thread *thread = threads[thread_no];
9495
return thread->create_task(spawner, name);
@@ -98,11 +99,11 @@ void
9899
rust_scheduler::release_task() {
99100
bool need_exit = false;
100101
{
101-
scoped_lock with(lock);
102-
live_tasks--;
103-
if (live_tasks == 0) {
104-
need_exit = true;
105-
}
102+
scoped_lock with(lock);
103+
live_tasks--;
104+
if (live_tasks == 0) {
105+
need_exit = true;
106+
}
106107
}
107108
if (need_exit) {
108109
// There are no more tasks on this scheduler. Time to leave
@@ -129,10 +130,10 @@ void
129130
rust_scheduler::release_task_thread() {
130131
uintptr_t new_live_threads;
131132
{
132-
scoped_lock with(lock);
133-
new_live_threads = --live_threads;
133+
scoped_lock with(lock);
134+
new_live_threads = --live_threads;
134135
}
135136
if (new_live_threads == 0) {
136-
kernel->release_scheduler_id(id);
137+
kernel->release_scheduler_id(id);
137138
}
138139
}

trunk/src/rt/rust_scheduler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ class rust_scheduler : public kernel_owned<rust_scheduler> {
1010
rust_srv *srv;
1111
rust_env *env;
1212
private:
13-
// Protects the random number context and live_threads
13+
// Protects live_threads and cur_thread increments
1414
lock_and_signal lock;
1515
// When this hits zero we'll tell the kernel to release us
1616
uintptr_t live_threads;
1717
// When this hits zero we'll tell the threads to exit
1818
uintptr_t live_tasks;
19-
randctx rctx;
2019

2120
array_list<rust_task_thread *> threads;
2221
const size_t num_threads;
22+
size_t cur_thread;
2323

2424
rust_sched_id id;
2525

0 commit comments

Comments
 (0)