[Zion] Move ProcessManager to map as well.

This commit is contained in:
Drew Galbraith 2023-11-16 22:17:11 -08:00
parent 6e227e1cf6
commit aa2d80b557
3 changed files with 11 additions and 15 deletions

View File

@ -28,6 +28,12 @@ void panic(const char* str, Args... args) {
asm volatile("cli; hlt;");
}
#define PANIC_ON_ERR(expr, str) \
{ \
if (expr != glcr::OK) { \
panic(str); \
} \
}
#define UNREACHABLE \
panic("Unreachable {}, {}", __FILE__, __LINE__); \
__builtin_unreachable();

View File

@ -10,19 +10,12 @@ void ProcessManager::Init() {
}
void ProcessManager::InsertProcess(const glcr::RefPtr<Process>& proc) {
proc_list_.PushBack(proc);
PANIC_ON_ERR(proc_map_.Insert(proc->id(), proc), "Reinserting process");
}
Process& ProcessManager::FromId(uint64_t pid) {
if (pid >= proc_list_.size()) {
panic("Bad proc access {}, have {} processes", pid, proc_list_.size());
}
return *proc_list_[pid];
}
void ProcessManager::DumpProcessStates() {
dbgln("Process States: {}", proc_list_.size());
for (uint64_t i = 0; i < proc_list_.size(); i++) {
dbgln("{}: {}", proc_list_[i]->id(), (uint64_t)proc_list_[i]->GetState());
if (!proc_map_.Contains(pid)) {
panic("Bad proc access {}, have {} processes", pid, proc_map_.size());
}
return *proc_map_.at(pid);
}

View File

@ -14,11 +14,8 @@ class ProcessManager {
void InsertProcess(const glcr::RefPtr<Process>& proc);
Process& FromId(uint64_t id);
void DumpProcessStates();
private:
// TODO: This should be a hashmap.
glcr::Vector<glcr::RefPtr<Process>> proc_list_;
glcr::HashMap<uint64_t, glcr::RefPtr<Process>> proc_map_;
};
extern ProcessManager* gProcMan;