2023-05-29 23:35:44 -07:00
|
|
|
#include "scheduler/process_manager.h"
|
|
|
|
|
2023-06-26 15:01:55 -07:00
|
|
|
#include "debug/debug.h"
|
|
|
|
|
2023-05-29 23:35:44 -07:00
|
|
|
ProcessManager* gProcMan = nullptr;
|
|
|
|
|
|
|
|
void ProcessManager::Init() {
|
|
|
|
gProcMan = new ProcessManager();
|
|
|
|
gProcMan->InsertProcess(Process::RootProcess());
|
|
|
|
}
|
|
|
|
|
2023-06-21 15:07:40 -07:00
|
|
|
void ProcessManager::InsertProcess(const glcr::RefPtr<Process>& proc) {
|
2023-11-16 22:17:11 -08:00
|
|
|
PANIC_ON_ERR(proc_map_.Insert(proc->id(), proc), "Reinserting process");
|
2023-05-29 23:35:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Process& ProcessManager::FromId(uint64_t pid) {
|
2023-11-16 22:17:11 -08:00
|
|
|
if (!proc_map_.Contains(pid)) {
|
|
|
|
panic("Bad proc access {}, have {} processes", pid, proc_map_.size());
|
2023-05-29 23:35:44 -07:00
|
|
|
}
|
2023-11-16 22:17:11 -08:00
|
|
|
return *proc_map_.at(pid);
|
2023-05-29 23:35:44 -07:00
|
|
|
}
|
2023-11-24 15:04:03 -08:00
|
|
|
|
|
|
|
void ProcessManager::InitCleanup() {
|
|
|
|
auto cleanup_thread = FromId(0).CreateThread();
|
|
|
|
cleanup_thread->SetKernel();
|
|
|
|
cleanup_thread->Start(reinterpret_cast<uint64_t>(CleanupThreadEntry),
|
|
|
|
reinterpret_cast<uint64_t>(&gProcMan->cleanup), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessManager::CleanupProcess(uint64_t pid) {
|
|
|
|
if (!proc_map_.Contains(pid)) {
|
|
|
|
panic("Bad proc access {}, have {} processes", pid, proc_map_.size());
|
|
|
|
}
|
|
|
|
cleanup.CleanupProcess(proc_map_.at(pid));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessManager::CleanupThread(glcr::RefPtr<Thread> thread) {
|
|
|
|
cleanup.CleanupThread(thread);
|
|
|
|
}
|