@@ -27,6 +27,7 @@ rust_task_thread::rust_task_thread(rust_scheduler *sched,
27
27
id(id),
28
28
should_exit(false ),
29
29
cached_c_stack(NULL ),
30
+ dead_task(NULL ),
30
31
kernel(sched->kernel),
31
32
sched(sched),
32
33
srv(srv),
@@ -108,23 +109,18 @@ rust_task_thread::number_of_live_tasks() {
108
109
*/
109
110
void
110
111
rust_task_thread::reap_dead_tasks () {
111
- if (dead_tasks. length () == 0 ) {
112
+ if (dead_task == NULL ) {
112
113
return ;
113
114
}
114
115
115
- A (this , dead_tasks.length () == 1 ,
116
- " Only one task should die during a single turn of the event loop" );
117
-
118
- // First make a copy of the dead_task list with the lock held
119
- rust_task *dead_task = dead_tasks.pop_value ();
120
-
121
116
// Dereferencing the task will probably cause it to be released
122
117
// from the scheduler, which may end up trying to take this lock
123
118
lock.unlock ();
124
119
125
120
dead_task->delete_all_stacks ();
126
121
// Deref the task, which may cause it to request us to release it
127
122
dead_task->deref ();
123
+ dead_task = NULL ;
128
124
129
125
lock.lock ();
130
126
}
@@ -187,14 +183,6 @@ rust_task_thread::log_state() {
187
183
blocked_tasks[i]->get_cond_name ());
188
184
}
189
185
}
190
-
191
- if (!dead_tasks.is_empty ()) {
192
- log (NULL , log_debug, " dead tasks:" );
193
- for (size_t i = 0 ; i < dead_tasks.length (); i++) {
194
- log (NULL , log_debug, " \t task: %s 0x%" PRIxPTR,
195
- dead_tasks[i]->name , dead_tasks[i]);
196
- }
197
- }
198
186
}
199
187
/* *
200
188
* Starts the main scheduler loop which performs task scheduling for this
@@ -221,7 +209,7 @@ rust_task_thread::start_main_loop() {
221
209
" all tasks are blocked, scheduler id %d yielding ..." ,
222
210
id);
223
211
lock.wait ();
224
- A (this , dead_tasks. length () == 0 ,
212
+ A (this , dead_task == NULL ,
225
213
" Tasks should only die after running" );
226
214
DLOG (this , task,
227
215
" scheduler %d resuming ..." , id);
@@ -257,7 +245,7 @@ rust_task_thread::start_main_loop() {
257
245
258
246
A (this , running_tasks.is_empty (), " Should have no running tasks" );
259
247
A (this , blocked_tasks.is_empty (), " Should have no blocked tasks" );
260
- A (this , dead_tasks. is_empty () , " Should have no dead tasks" );
248
+ A (this , dead_task == NULL , " Should have no dead tasks" );
261
249
262
250
DLOG (this , dom, " finished main-loop %d" , id);
263
251
@@ -290,8 +278,6 @@ rust_task_thread::state_list(rust_task_state state) {
290
278
return &running_tasks;
291
279
case task_state_blocked:
292
280
return &blocked_tasks;
293
- case task_state_dead:
294
- return &dead_tasks;
295
281
default :
296
282
return NULL ;
297
283
}
@@ -332,6 +318,10 @@ rust_task_thread::transition(rust_task *task,
332
318
if (dst_list) {
333
319
dst_list->append (task);
334
320
}
321
+ if (dst == task_state_dead) {
322
+ I (this , dead_task == NULL );
323
+ dead_task = task;
324
+ }
335
325
task->set_state (dst, cond, cond_name);
336
326
337
327
lock.signal ();
0 commit comments