rt: Change the lifecycle of tasks and schedulers for various reasons
This is in preparation for giving schedulers their own life cycle separate from the kernel. Tasks must be deleted before their scheduler thread, so we can't let the scheduler exit before all its tasks have been cleaned up. In this scheme, the scheduler will unregister tasks with the kernel when they are reaped, then drop their ref on the task (there may still be others). When the task ref count hits zero, the task will request to be unregistered from the scheduler, which is responsible for deleting the task. Instead of having the kernel tell the scheduler to exit, let the scheduler decide when to exit. For now it will exit when all of its tasks are unregistered.
This commit is contained in:
@@ -136,16 +136,30 @@ rust_task_thread::reap_dead_tasks() {
|
||||
|
||||
for (size_t i = 0; i < dead_tasks_len; ++i) {
|
||||
rust_task *task = dead_tasks_copy[i];
|
||||
if (task) {
|
||||
kernel->release_task_id(task->user.id);
|
||||
task->deref();
|
||||
}
|
||||
// Release the task from the kernel so nobody else can get at it
|
||||
kernel->release_task_id(task->user.id);
|
||||
// Deref the task, which may cause it to request us to release it
|
||||
task->deref();
|
||||
}
|
||||
srv->free(dead_tasks_copy);
|
||||
|
||||
lock.lock();
|
||||
}
|
||||
|
||||
void
|
||||
rust_task_thread::release_task(rust_task *task) {
|
||||
// Nobody should have a ref to the task at this point
|
||||
I(this, task->ref_count == 0);
|
||||
// Kernel should not know about the task any more
|
||||
I(this, kernel->get_task_by_id(task->user.id) == NULL);
|
||||
// Now delete the task, which will require using this thread's
|
||||
// memory region.
|
||||
delete task;
|
||||
// Now release the task from the scheduler, which may trigger this
|
||||
// thread to exit
|
||||
sched->release_task();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a running task for execution. Only running tasks can be
|
||||
* activated. Blocked tasks have to be unblocked before they can be
|
||||
|
||||
Reference in New Issue
Block a user