[Zion] Add a proc/thread cleanup thread for future use.
This commit is contained in:
parent
8e4cd1562f
commit
cb590c96b8
9 changed files with 95 additions and 0 deletions
32
zion/scheduler/cleanup.cpp
Normal file
32
zion/scheduler/cleanup.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include "scheduler/cleanup.h"
|
||||
|
||||
void ProcessCleanup::CleanupLoop() {
|
||||
while (true) {
|
||||
while (process_list_.empty() && thread_list_.empty()) {
|
||||
semaphore_.Wait();
|
||||
}
|
||||
// TODO: I think we need to protect these lists with a mutex as well.
|
||||
while (!process_list_.empty()) {
|
||||
auto proc = process_list_.PopFront();
|
||||
dbgln("CLEANUP Proc {}", proc->id());
|
||||
}
|
||||
while (!thread_list_.empty()) {
|
||||
auto thread = thread_list_.PopFront();
|
||||
dbgln("CLEANUP Thread {}.{}", thread->pid(), thread->tid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessCleanup::CleanupProcess(glcr::RefPtr<Process> process) {
|
||||
process_list_.PushBack(process);
|
||||
semaphore_.Signal();
|
||||
}
|
||||
void ProcessCleanup::CleanupThread(glcr::RefPtr<Thread> thread) {
|
||||
thread_list_.PushBack(thread);
|
||||
semaphore_.Signal();
|
||||
}
|
||||
|
||||
void CleanupThreadEntry(ProcessCleanup* cleanup) {
|
||||
cleanup->CleanupLoop();
|
||||
UNREACHABLE;
|
||||
}
|
||||
25
zion/scheduler/cleanup.h
Normal file
25
zion/scheduler/cleanup.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/container/linked_list.h>
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
|
||||
#include "object/process.h"
|
||||
#include "object/semaphore.h"
|
||||
#include "object/thread.h"
|
||||
|
||||
class ProcessCleanup {
|
||||
public:
|
||||
ProcessCleanup() {}
|
||||
|
||||
void CleanupLoop();
|
||||
|
||||
void CleanupProcess(glcr::RefPtr<Process> process);
|
||||
void CleanupThread(glcr::RefPtr<Thread> thread);
|
||||
|
||||
private:
|
||||
Semaphore semaphore_;
|
||||
glcr::LinkedList<glcr::RefPtr<Thread>> thread_list_;
|
||||
glcr::LinkedList<glcr::RefPtr<Process>> process_list_;
|
||||
};
|
||||
|
||||
void CleanupThreadEntry(ProcessCleanup* cleanup);
|
||||
|
|
@ -19,3 +19,21 @@ Process& ProcessManager::FromId(uint64_t pid) {
|
|||
}
|
||||
return *proc_map_.at(pid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <glacier/memory/ref_ptr.h>
|
||||
|
||||
#include "object/process.h"
|
||||
#include "scheduler/cleanup.h"
|
||||
|
||||
class ProcessManager {
|
||||
public:
|
||||
|
|
@ -16,8 +17,14 @@ class ProcessManager {
|
|||
|
||||
Process& FromId(uint64_t id);
|
||||
|
||||
void InitCleanup();
|
||||
|
||||
void CleanupProcess(uint64_t pid);
|
||||
void CleanupThread(glcr::RefPtr<Thread> thread);
|
||||
|
||||
private:
|
||||
glcr::HashMap<uint64_t, glcr::RefPtr<Process>> proc_map_;
|
||||
ProcessCleanup cleanup;
|
||||
};
|
||||
|
||||
extern ProcessManager* gProcMan;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue