| 258 | } |
| 259 | |
| 260 | auto TaskManager::ReapTask(TaskControlBlock* task) -> void { |
| 261 | if (!task) { |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | // 确保任务处于僵尸或退出状态 |
| 266 | if (task->GetStatus() != TaskStatus::kZombie && |
| 267 | task->GetStatus() != TaskStatus::kExited) { |
| 268 | klog::Warn("ReapTask: Task {} is not in zombie/exited state", task->pid); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | // Capture pid before erase (unique_ptr deletes on erase) |
| 273 | Pid pid = task->pid; |
| 274 | |
| 275 | // 从全局任务表中移除 (unique_ptr auto-deletes TCB) |
| 276 | { |
| 277 | LockGuard lock_guard{task_table_lock_}; |
| 278 | task_table_.erase(pid); |
| 279 | } |
| 280 | |
| 281 | klog::Debug("ReapTask: Task {} resources freed", pid); |
| 282 | } |
| 283 | |
| 284 | auto TaskManager::ReparentChildren(TaskControlBlock* parent) -> void { |
| 285 | if (!parent) { |