Kernel: Free the last spawned thread's PID on exit
This commit is contained in:
parent
aebd860947
commit
1938a059a2
@ -262,46 +262,40 @@ void Scheduler::reap_task(Task* task)
|
|||||||
Interrupts::pop();
|
Interrupts::pop();
|
||||||
}
|
}
|
||||||
for (int i = 0; i < TASK_MAX_FDS; i++) { exiting_task->files[i].close(); }
|
for (int i = 0; i < TASK_MAX_FDS; i++) { exiting_task->files[i].close(); }
|
||||||
|
if (exiting_task->id == (free_tid - 1)) free_tid--; // If we are the last spawned thread, free our PID.
|
||||||
delete exiting_task;
|
delete exiting_task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sched_common_exit(Context* context, int64_t status)
|
||||||
|
{
|
||||||
|
if (sched_current_task->id == 1) sched_current_task->state = sched_current_task->Exited;
|
||||||
|
else
|
||||||
|
sched_current_task->state = sched_current_task->Dying;
|
||||||
|
sched_current_task->exit_status = status;
|
||||||
|
if (sched_current_task->id != 1)
|
||||||
|
{
|
||||||
|
sched_for_each_child(sched_current_task, [](Task* child) {
|
||||||
|
if (child->state != child->Exited) child->ppid = 1;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else { reboot(); }
|
||||||
|
Scheduler::task_yield(context);
|
||||||
|
}
|
||||||
|
|
||||||
void Scheduler::task_exit(Context* context, int64_t status)
|
void Scheduler::task_exit(Context* context, int64_t status)
|
||||||
{
|
{
|
||||||
ASSERT(Interrupts::is_in_handler());
|
ASSERT(Interrupts::is_in_handler());
|
||||||
kdbgln("exit: task %ld finished running, used %ld ms of cpu time", sched_current_task->id,
|
kdbgln("exit: task %ld finished running, used %ld ms of cpu time", sched_current_task->id,
|
||||||
sched_current_task->cpu_time);
|
sched_current_task->cpu_time);
|
||||||
if (sched_current_task->id == 1) sched_current_task->state = sched_current_task->Exited;
|
sched_common_exit(context, status);
|
||||||
else
|
|
||||||
sched_current_task->state = sched_current_task->Dying;
|
|
||||||
sched_current_task->exit_status = status;
|
|
||||||
if (sched_current_task->id != 1)
|
|
||||||
{
|
|
||||||
sched_for_each_child(sched_current_task, [](Task* child) {
|
|
||||||
if (child->state != child->Exited) child->ppid = 1;
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else { reboot(); }
|
|
||||||
task_yield(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::task_misbehave(Context* context, int64_t status)
|
void Scheduler::task_misbehave(Context* context, int64_t status)
|
||||||
{
|
{
|
||||||
ASSERT(Interrupts::is_in_handler());
|
ASSERT(Interrupts::is_in_handler());
|
||||||
kdbgln("exit: task %ld misbehaved, used %ld ms of cpu time", sched_current_task->id, sched_current_task->cpu_time);
|
kdbgln("exit: task %ld misbehaved, used %ld ms of cpu time", sched_current_task->id, sched_current_task->cpu_time);
|
||||||
if (sched_current_task->id == 1) sched_current_task->state = sched_current_task->Exited;
|
sched_common_exit(context, status);
|
||||||
else
|
|
||||||
sched_current_task->state = sched_current_task->Dying;
|
|
||||||
sched_current_task->exit_status = status;
|
|
||||||
if (sched_current_task->id != 1)
|
|
||||||
{
|
|
||||||
sched_for_each_child(sched_current_task, [](Task* child) {
|
|
||||||
if (child->state != child->Exited) child->ppid = 1;
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else { reboot(); }
|
|
||||||
task_yield(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::reap_tasks()
|
void Scheduler::reap_tasks()
|
||||||
|
Loading…
Reference in New Issue
Block a user