@@ -114,7 +114,7 @@ cleanup_task(cleanup_args *args) {
114
114
rust_task *task = a->task;
115
115
116
116
{
117
- scoped_lock with(task->lifecycle_lock );
117
+ scoped_lock with(task->kill_lock );
118
118
if (task->killed && !threw_exception) {
119
119
LOG(task, task, "Task killed during termination");
120
120
threw_exception = true;
@@ -230,25 +230,21 @@ void rust_task::start()
230
230
231
231
bool
232
232
rust_task::must_fail_from_being_killed() {
233
- scoped_lock with(lifecycle_lock );
233
+ scoped_lock with(kill_lock );
234
234
return must_fail_from_being_killed_unlocked();
235
235
}
236
236
237
237
bool
238
238
rust_task::must_fail_from_being_killed_unlocked() {
239
- lifecycle_lock .must_have_lock();
239
+ kill_lock .must_have_lock();
240
240
return killed && !reentered_rust_stack && disallow_kill == 0;
241
241
}
242
242
243
243
// Only run this on the rust stack
244
244
void
245
245
rust_task::yield(bool *killed) {
246
- // FIXME (#2787): clean this up
247
246
if (must_fail_from_being_killed()) {
248
- {
249
- scoped_lock with(lifecycle_lock);
250
- assert(!(state == task_state_blocked));
251
- }
247
+ assert(!blocked());
252
248
*killed = true;
253
249
}
254
250
@@ -262,7 +258,7 @@ rust_task::yield(bool *killed) {
262
258
263
259
void
264
260
rust_task::kill() {
265
- scoped_lock with(lifecycle_lock );
261
+ scoped_lock with(kill_lock );
266
262
267
263
// XXX: bblum: kill/kill race
268
264
@@ -274,9 +270,8 @@ rust_task::kill() {
274
270
killed = true;
275
271
// Unblock the task so it can unwind.
276
272
277
- if (state == task_state_blocked &&
278
- must_fail_from_being_killed_unlocked()) {
279
- wakeup_locked(cond);
273
+ if (blocked() && must_fail_from_being_killed_unlocked()) {
274
+ wakeup(cond);
280
275
}
281
276
282
277
LOG(this, task, "preparing to unwind task: 0x%" PRIxPTR, this);
@@ -340,21 +335,34 @@ rust_task::get_frame_glue_fns(uintptr_t fp) {
340
335
return *((frame_glue_fns**) fp);
341
336
}
342
337
343
- void rust_task::assert_is_running()
338
+ bool
339
+ rust_task::running()
340
+ {
341
+ scoped_lock with(state_lock);
342
+ return state == task_state_running;
343
+ }
344
+
345
+ bool
346
+ rust_task::blocked()
344
347
{
345
- scoped_lock with(lifecycle_lock );
346
- assert( state == task_state_running) ;
348
+ scoped_lock with(state_lock );
349
+ return state == task_state_blocked ;
347
350
}
348
351
349
- // FIXME (#2851, #2787): This is only used by rust_port/rust_port selector,
350
- // and is inherently racy. Get rid of it.
351
352
bool
352
353
rust_task::blocked_on(rust_cond *on)
353
354
{
354
- scoped_lock with(lifecycle_lock );
355
+ scoped_lock with(state_lock );
355
356
return cond == on;
356
357
}
357
358
359
+ bool
360
+ rust_task::dead()
361
+ {
362
+ scoped_lock with(state_lock);
363
+ return state == task_state_dead;
364
+ }
365
+
358
366
void *
359
367
rust_task::malloc(size_t sz, const char *tag, type_desc *td)
360
368
{
@@ -376,28 +384,28 @@ rust_task::free(void *p)
376
384
void
377
385
rust_task::transition(rust_task_state src, rust_task_state dst,
378
386
rust_cond *cond, const char* cond_name) {
379
- scoped_lock with(lifecycle_lock );
387
+ scoped_lock with(state_lock );
380
388
transition_locked(src, dst, cond, cond_name);
381
389
}
382
390
383
391
void rust_task::transition_locked(rust_task_state src, rust_task_state dst,
384
392
rust_cond *cond, const char* cond_name) {
385
- lifecycle_lock .must_have_lock();
393
+ state_lock .must_have_lock();
386
394
sched_loop->transition(this, src, dst, cond, cond_name);
387
395
}
388
396
389
397
void
390
398
rust_task::set_state(rust_task_state state,
391
399
rust_cond *cond, const char* cond_name) {
392
- lifecycle_lock .must_have_lock();
400
+ state_lock .must_have_lock();
393
401
this->state = state;
394
402
this->cond = cond;
395
403
this->cond_name = cond_name;
396
404
}
397
405
398
406
bool
399
407
rust_task::block(rust_cond *on, const char* name) {
400
- scoped_lock with(lifecycle_lock );
408
+ scoped_lock with(kill_lock );
401
409
return block_locked(on, name);
402
410
}
403
411
@@ -420,7 +428,7 @@ rust_task::block_locked(rust_cond *on, const char* name) {
420
428
421
429
void
422
430
rust_task::wakeup(rust_cond *from) {
423
- scoped_lock with(lifecycle_lock );
431
+ scoped_lock with(state_lock );
424
432
wakeup_locked(from);
425
433
}
426
434
@@ -668,27 +676,26 @@ rust_task::on_rust_stack() {
668
676
669
677
void
670
678
rust_task::inhibit_kill() {
671
- scoped_lock with(lifecycle_lock);
672
- // FIXME (#1868) Check here if we have to die
679
+ scoped_lock with(kill_lock);
673
680
disallow_kill++;
674
681
}
675
682
676
683
void
677
684
rust_task::allow_kill() {
678
- scoped_lock with(lifecycle_lock );
685
+ scoped_lock with(kill_lock );
679
686
assert(disallow_kill > 0 && "Illegal allow_kill(): already killable!");
680
687
disallow_kill--;
681
688
}
682
689
683
690
void *
684
691
rust_task::wait_event(bool *killed) {
685
- scoped_lock with(lifecycle_lock );
692
+ scoped_lock with(state_lock );
686
693
687
694
if(!event_reject) {
688
695
block_locked(&event_cond, "waiting on event");
689
- lifecycle_lock .unlock();
696
+ state_lock .unlock();
690
697
yield(killed);
691
- lifecycle_lock .lock();
698
+ state_lock .lock();
692
699
}
693
700
694
701
event_reject = false;
@@ -697,7 +704,7 @@ rust_task::wait_event(bool *killed) {
697
704
698
705
void
699
706
rust_task::signal_event(void *event) {
700
- scoped_lock with(lifecycle_lock );
707
+ scoped_lock with(state_lock );
701
708
702
709
this->event = event;
703
710
event_reject = true;
0 commit comments