13 auto& cpu_sched = GetCurrentCpuSched();
14 auto* current = GetCurrentTask();
15 assert(current !=
nullptr &&
"Exit: No current task to exit");
17 "Exit: current task status must be kRunning");
23 current->aux->exit_code = exit_code;
26 bool is_group_leader = current->IsThreadGroupLeader();
29 if (is_group_leader && current->GetThreadGroupSize() > 1) {
31 "Exit: Thread group leader (pid={}, tgid={}) exiting, but group "
32 "still has {} threads",
33 current->pid, current->aux->tgid, current->GetThreadGroupSize());
37 current->LeaveThreadGroup();
40 if (is_group_leader) {
41 ReparentChildren(current);
44 if (current->aux->parent_pid != 0) {
47 current->fsm.Receive(
MsgExit{exit_code,
true});
51 auto wait_resource_id =
53 Wakeup(wait_resource_id);
57 klog::Debug(
"Exit: pid={} waking up parent={} on resource={}",
58 current->pid, current->aux->parent_pid,
59 wait_resource_id.GetTypeName());
63 current->fsm.Receive(
MsgExit{exit_code,
false});
71 klog::Err(
"Exit: Task {} should not return from Schedule()", current->pid);
74 __builtin_unreachable();