Skip to content

Commit 5c3c8d4

Browse files
committed
rt: Do all signalling while holding a lock
This will matter once the scheduler is changed to not wake up on a timer
1 parent 5449b88 commit 5c3c8d4

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/rt/rust_kernel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ rust_kernel::release_task_id(rust_task_id id) {
191191

192192
void rust_kernel::wakeup_schedulers() {
193193
for(size_t i = 0; i < num_threads; ++i) {
194-
threads[i]->lock.signal_all();
194+
rust_scheduler *sched = threads[i];
195+
scoped_lock with(sched->lock);
196+
sched->lock.signal_all();
195197
}
196198
}
197199

src/rt/rust_task.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ rust_task::start(spawn_fn spawnee_fn,
394394
void rust_task::start()
395395
{
396396
transition(&sched->newborn_tasks, &sched->running_tasks);
397-
sched->lock.signal();
398397
}
399398

400399
// Only run this on the rust stack
@@ -429,8 +428,6 @@ rust_task::kill() {
429428
// Unblock the task so it can unwind.
430429
unblock();
431430

432-
sched->lock.signal();
433-
434431
LOG(this, task, "preparing to unwind task: 0x%" PRIxPTR, this);
435432
// run_on_resume(rust_unwind_glue);
436433
}
@@ -551,6 +548,7 @@ rust_task::transition(rust_task_list *src, rust_task_list *dst) {
551548
src->remove(this);
552549
dst->append(this);
553550
state = dst;
551+
sched->lock.signal();
554552
if(unlock)
555553
sched->lock.unlock();
556554
}
@@ -578,20 +576,16 @@ rust_task::wakeup(rust_cond *from) {
578576
(uintptr_t) cond, (uintptr_t) from);
579577
A(sched, cond == from, "Cannot wake up blocked task on wrong condition.");
580578

581-
transition(&sched->blocked_tasks, &sched->running_tasks);
582-
I(sched, cond == from);
583579
cond = NULL;
584580
cond_name = "none";
585-
586-
sched->lock.signal();
581+
transition(&sched->blocked_tasks, &sched->running_tasks);
587582
}
588583

589584
void
590585
rust_task::die() {
591586
I(sched, !lock.lock_held_by_current_thread());
592587
scoped_lock with(lock);
593588
transition(&sched->running_tasks, &sched->dead_tasks);
594-
sched->lock.signal();
595589
}
596590

597591
void

0 commit comments

Comments
 (0)