Skip to content

Commit 4063b3d

Browse files
committed
---
yaml --- r: 12243 b: refs/heads/master c: 771c1be h: refs/heads/master i: 12241: 83f274e 12239: 4c190f5 v: v3
1 parent c0d689f commit 4063b3d

File tree

3 files changed

+54
-21
lines changed

3 files changed

+54
-21
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: 243790836a40fd3f23d8bd16d8f45430d19aae61
2+
refs/heads/master: 771c1be6a64225d416ad99a860f1c8d34ce3a18b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rt/rust_sched_loop.cpp

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ rust_sched_loop::log_state() {
182182
}
183183
}
184184
}
185+
185186
/**
186187
* Starts the main scheduler loop which performs task scheduling for this
187188
* domain.
@@ -191,11 +192,29 @@ rust_sched_loop::log_state() {
191192
*/
192193
void
193194
rust_sched_loop::start_main_loop() {
195+
DLOG(this, dom, "started domain loop %d", id);
196+
197+
rust_sched_loop_state state = sched_loop_state_keep_going;
198+
while (state != sched_loop_state_exit) {
199+
state = run_single_turn();
200+
201+
scoped_lock with(lock);
202+
if (!should_exit && running_tasks.length() == 0) {
203+
lock.wait();
204+
}
205+
DLOG(this, task,
206+
"scheduler %d resuming ...", id);
207+
}
208+
}
209+
210+
rust_sched_loop_state
211+
rust_sched_loop::run_single_turn() {
194212
lock.lock();
195213

196-
DLOG(this, dom, "started domain loop %d", id);
214+
if (!should_exit) {
215+
A(this, dead_task == NULL,
216+
"Tasks should only die after running");
197217

198-
while (!should_exit) {
199218
DLOG(this, dom, "worker %d, number_of_live_tasks = %d",
200219
id, number_of_live_tasks());
201220

@@ -206,12 +225,9 @@ rust_sched_loop::start_main_loop() {
206225
DLOG(this, task,
207226
"all tasks are blocked, scheduler id %d yielding ...",
208227
id);
209-
lock.wait();
210-
A(this, dead_task == NULL,
211-
"Tasks should only die after running");
212-
DLOG(this, task,
213-
"scheduler %d resuming ...", id);
214-
continue;
228+
229+
lock.unlock();
230+
return sched_loop_state_block;
215231
}
216232

217233
I(this, scheduled_task->running());
@@ -239,23 +255,27 @@ rust_sched_loop::start_main_loop() {
239255
id);
240256

241257
reap_dead_tasks();
242-
}
243258

244-
A(this, running_tasks.is_empty(), "Should have no running tasks");
245-
A(this, blocked_tasks.is_empty(), "Should have no blocked tasks");
246-
A(this, dead_task == NULL, "Should have no dead tasks");
259+
lock.unlock();
260+
return sched_loop_state_keep_going;
261+
} else {
262+
A(this, running_tasks.is_empty(), "Should have no running tasks");
263+
A(this, blocked_tasks.is_empty(), "Should have no blocked tasks");
264+
A(this, dead_task == NULL, "Should have no dead tasks");
247265

248-
DLOG(this, dom, "finished main-loop %d", id);
266+
DLOG(this, dom, "finished main-loop %d", id);
249267

250-
lock.unlock();
268+
lock.unlock();
251269

252-
I(this, !extra_c_stack);
253-
if (cached_c_stack) {
254-
destroy_stack(kernel->region(), cached_c_stack);
255-
cached_c_stack = NULL;
256-
}
270+
I(this, !extra_c_stack);
271+
if (cached_c_stack) {
272+
destroy_stack(kernel->region(), cached_c_stack);
273+
cached_c_stack = NULL;
274+
}
257275

258-
sched->release_task_thread();
276+
sched->release_task_thread();
277+
return sched_loop_state_exit;
278+
}
259279
}
260280

261281
rust_task *
@@ -360,6 +380,7 @@ rust_sched_loop::place_task_in_tls(rust_task *task) {
360380
void
361381
rust_sched_loop::exit() {
362382
scoped_lock with(lock);
383+
DLOG(this, dom, "Requesting exit for thread %d", id);
363384
should_exit = true;
364385
lock.signal();
365386
}

trunk/src/rt/rust_sched_loop.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ enum rust_task_state {
1212
task_state_dead
1313
};
1414

15+
/*
16+
The result of every turn of the scheduler loop. Instructs the loop
17+
driver how to proceed.
18+
*/
19+
enum rust_sched_loop_state {
20+
sched_loop_state_keep_going,
21+
sched_loop_state_block,
22+
sched_loop_state_exit
23+
};
24+
1525
typedef indexed_list<rust_task> rust_task_list;
1626

1727
struct rust_sched_loop
@@ -49,6 +59,8 @@ struct rust_sched_loop
4959
rust_task_list *state_list(rust_task_state state);
5060
const char *state_name(rust_task_state state);
5161

62+
rust_sched_loop_state run_single_turn();
63+
5264
public:
5365
rust_kernel *kernel;
5466
rust_scheduler *sched;

0 commit comments

Comments
 (0)