@@ -182,6 +182,7 @@ rust_sched_loop::log_state() {
182
182
}
183
183
}
184
184
}
185
+
185
186
/* *
186
187
* Starts the main scheduler loop which performs task scheduling for this
187
188
* domain.
@@ -191,11 +192,29 @@ rust_sched_loop::log_state() {
191
192
*/
192
193
void
193
194
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 () {
194
212
lock.lock ();
195
213
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" );
197
217
198
- while (!should_exit) {
199
218
DLOG (this , dom, " worker %d, number_of_live_tasks = %d" ,
200
219
id, number_of_live_tasks ());
201
220
@@ -206,12 +225,9 @@ rust_sched_loop::start_main_loop() {
206
225
DLOG (this , task,
207
226
" all tasks are blocked, scheduler id %d yielding ..." ,
208
227
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;
215
231
}
216
232
217
233
I (this , scheduled_task->running ());
@@ -239,23 +255,27 @@ rust_sched_loop::start_main_loop() {
239
255
id);
240
256
241
257
reap_dead_tasks ();
242
- }
243
258
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" );
247
265
248
- DLOG (this , dom, " finished main-loop %d" , id);
266
+ DLOG (this , dom, " finished main-loop %d" , id);
249
267
250
- lock.unlock ();
268
+ lock.unlock ();
251
269
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
+ }
257
275
258
- sched->release_task_thread ();
276
+ sched->release_task_thread ();
277
+ return sched_loop_state_exit;
278
+ }
259
279
}
260
280
261
281
rust_task *
@@ -360,6 +380,7 @@ rust_sched_loop::place_task_in_tls(rust_task *task) {
360
380
void
361
381
rust_sched_loop::exit () {
362
382
scoped_lock with (lock);
383
+ DLOG (this , dom, " Requesting exit for thread %d" , id);
363
384
should_exit = true ;
364
385
lock.signal ();
365
386
}
0 commit comments