2
2
#include < stdarg.h>
3
3
#include " rust_internal.h"
4
4
5
- template class ptr_vec <rust_task>;
6
-
7
5
rust_dom::rust_dom (rust_kernel *kernel,
8
6
rust_message_queue *message_queue, rust_srv *srv,
9
7
rust_crate const *root_crate, const char *name) :
@@ -14,9 +12,10 @@ rust_dom::rust_dom(rust_kernel *kernel,
14
12
local_region(&srv->local_region),
15
13
synchronized_region(&srv->synchronized_region),
16
14
name(name),
17
- running_tasks(this ),
18
- blocked_tasks(this ),
19
- dead_tasks(this ),
15
+ newborn_tasks(this , " newborn" ),
16
+ running_tasks(this , " running" ),
17
+ blocked_tasks(this , " blocked" ),
18
+ dead_tasks(this , " dead" ),
20
19
caches(this ),
21
20
root_task(NULL ),
22
21
curr_task(NULL ),
@@ -31,28 +30,16 @@ rust_dom::rust_dom(rust_kernel *kernel,
31
30
pthread_attr_setstacksize (&attr, 1024 * 1024 );
32
31
pthread_attr_setdetachstate (&attr, true );
33
32
#endif
34
- root_task = new (this ) rust_task (this , NULL , name);
35
- }
36
-
37
- static void
38
- del_all_tasks (rust_dom *dom, ptr_vec<rust_task> *v) {
39
- I (dom, v);
40
- while (v->length ()) {
41
- dom->log (rust_log::TASK, " deleting task 0x%" PRIdPTR,
42
- v->length () - 1 );
43
- delete v->pop ();
44
- }
33
+ root_task = create_task (NULL , name);
45
34
}
46
35
47
36
rust_dom::~rust_dom () {
48
37
log (rust_log::MEM | rust_log::DOM,
49
38
" ~rust_dom %s @0x%" PRIxPTR, name, (uintptr_t )this );
50
- log (rust_log::TASK, " deleting all running tasks" );
51
- del_all_tasks (this , &running_tasks);
52
- log (rust_log::TASK, " deleting all blocked tasks" );
53
- del_all_tasks (this , &blocked_tasks);
54
- log (rust_log::TASK, " deleting all dead tasks" );
55
- del_all_tasks (this , &dead_tasks);
39
+ newborn_tasks.delete_all ();
40
+ running_tasks.delete_all ();
41
+ blocked_tasks.delete_all ();
42
+ dead_tasks.delete_all ();
56
43
#ifndef __WIN32__
57
44
pthread_attr_destroy (&attr);
58
45
#endif
@@ -198,42 +185,10 @@ rust_dom::win32_require(LPCTSTR fn, BOOL ok) {
198
185
#endif
199
186
200
187
size_t
201
- rust_dom::n_live_tasks ()
202
- {
188
+ rust_dom::number_of_live_tasks () {
203
189
return running_tasks.length () + blocked_tasks.length ();
204
190
}
205
191
206
- void
207
- rust_dom::add_task_to_state_vec (ptr_vec<rust_task> *v, rust_task *task)
208
- {
209
- log (rust_log::MEM|rust_log::TASK,
210
- " adding task %s @0x%" PRIxPTR " in state '%s' to vec 0x%" PRIxPTR,
211
- task->name , (uintptr_t )task, state_vec_name (v), (uintptr_t )v);
212
- v->push (task);
213
- }
214
-
215
-
216
- void
217
- rust_dom::remove_task_from_state_vec (ptr_vec<rust_task> *v, rust_task *task)
218
- {
219
- log (rust_log::MEM|rust_log::TASK,
220
- " removing task %s @0x%" PRIxPTR " in state '%s' from vec 0x%" PRIxPTR,
221
- task->name , (uintptr_t )task, state_vec_name (v), (uintptr_t )v);
222
- I (this , (*v)[task->idx ] == task);
223
- v->swap_delete (task);
224
- }
225
-
226
- const char *
227
- rust_dom::state_vec_name (ptr_vec<rust_task> *v)
228
- {
229
- if (v == &running_tasks)
230
- return " running" ;
231
- if (v == &blocked_tasks)
232
- return " blocked" ;
233
- I (this , v == &dead_tasks);
234
- return " dead" ;
235
- }
236
-
237
192
/* *
238
193
* Delete any dead tasks.
239
194
*/
@@ -243,7 +198,7 @@ rust_dom::reap_dead_tasks() {
243
198
rust_task *task = dead_tasks[i];
244
199
if (task->ref_count == 0 ) {
245
200
I (this , task->tasks_waiting_to_join .is_empty ());
246
- dead_tasks.swap_delete (task);
201
+ dead_tasks.remove (task);
247
202
log (rust_log::TASK,
248
203
" deleting unreferenced dead task %s @0x%" PRIxPTR,
249
204
task->name , task);
@@ -288,7 +243,6 @@ rust_dom::schedule_task() {
288
243
return (rust_task *)running_tasks[i];
289
244
}
290
245
}
291
- // log(rust_log::DOM|rust_log::TASK, "no schedulable tasks");
292
246
return NULL ;
293
247
}
294
248
@@ -334,16 +288,16 @@ rust_dom::log_state() {
334
288
* drop to zero.
335
289
*/
336
290
int
337
- rust_dom::start_main_loop ()
338
- {
291
+ rust_dom::start_main_loop () {
339
292
// Make sure someone is watching, to pull us out of infinite loops.
340
293
rust_timer timer (this );
341
294
342
- log (rust_log::DOM, " running main-loop on domain %s @0x%" PRIxPTR,
343
- name, this );
344
- logptr (" exit-task glue" , root_crate->get_exit_task_glue ());
295
+ log (rust_log::DOM, " started domain loop" );
296
+ log (rust_log::DOM | rust_log::MEM,
297
+ " activate glue: " PTR " , exit glue: " PTR,
298
+ root_crate->get_activate_glue (), root_crate->get_exit_task_glue ());
345
299
346
- while (n_live_tasks () > 0 ) {
300
+ while (number_of_live_tasks () > 0 ) {
347
301
A (this , kernel->is_deadlocked () == false , " deadlock" );
348
302
349
303
drain_incoming_message_queue (true );
@@ -377,7 +331,7 @@ rust_dom::start_main_loop()
377
331
(uintptr_t )scheduled_task,
378
332
scheduled_task->rust_sp ,
379
333
scheduled_task->ref_count ,
380
- scheduled_task->state_str () );
334
+ scheduled_task->state -> name );
381
335
382
336
interrupt_flag = 0 ;
383
337
@@ -388,7 +342,7 @@ rust_dom::start_main_loop()
388
342
" in state '%s', sp=0x%" PRIxPTR,
389
343
scheduled_task->name ,
390
344
(uintptr_t )scheduled_task,
391
- state_vec_name ( scheduled_task->state ) ,
345
+ scheduled_task->state -> name ,
392
346
scheduled_task->rust_sp );
393
347
394
348
I (this , scheduled_task->rust_sp >=
@@ -443,6 +397,15 @@ rust_dom::get_cache(rust_crate const *crate) {
443
397
return cache;
444
398
}
445
399
400
+ rust_task *
401
+ rust_dom::create_task (rust_task *spawner, const char *name) {
402
+ rust_task *task =
403
+ new (this ) rust_task (this , &newborn_tasks, spawner, name);
404
+ log (rust_log::TASK, " created task: " PTR " , spawner: %s, name: %s" ,
405
+ task, spawner ? spawner->name : " null" , name);
406
+ newborn_tasks.append (task);
407
+ return task;
408
+ }
446
409
447
410
//
448
411
// Local Variables:
0 commit comments