[Zion] Add a framework for better process exit.
This commit is contained in:
parent
aa2d80b557
commit
308dd6a203
9 changed files with 80 additions and 8 deletions
|
|
@ -12,6 +12,8 @@ class ProcessManager {
|
|||
static void Init();
|
||||
|
||||
void InsertProcess(const glcr::RefPtr<Process>& proc);
|
||||
void RemoveProcess(uint64_t id);
|
||||
|
||||
Process& FromId(uint64_t id);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ void Scheduler::Preempt() {
|
|||
return;
|
||||
}
|
||||
|
||||
ClearDeadThreadsFromFront();
|
||||
|
||||
asm volatile("cli");
|
||||
if (current_thread_ == sleep_thread_) {
|
||||
// Sleep should never be preempted. (We should yield it if another thread
|
||||
|
|
@ -66,9 +68,14 @@ void Scheduler::Preempt() {
|
|||
|
||||
void Scheduler::Yield() {
|
||||
if (!enabled_) {
|
||||
// This is expected to fire once at the start when we enqueue the first
|
||||
// thread before the scheduler is enabled. Maybe we should get rid of it?
|
||||
dbgln("WARN Scheduler skipped yield.");
|
||||
return;
|
||||
}
|
||||
|
||||
ClearDeadThreadsFromFront();
|
||||
|
||||
asm volatile("cli");
|
||||
|
||||
glcr::RefPtr<Thread> prev = current_thread_;
|
||||
|
|
@ -78,7 +85,9 @@ void Scheduler::Yield() {
|
|||
return;
|
||||
} else {
|
||||
current_thread_ = runnable_threads_.PopFront();
|
||||
prev->SetState(Thread::RUNNABLE);
|
||||
if (!prev->IsDying()) {
|
||||
prev->SetState(Thread::RUNNABLE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (runnable_threads_.size() == 0) {
|
||||
|
|
@ -90,3 +99,10 @@ void Scheduler::Yield() {
|
|||
|
||||
SwapToCurrent(*prev);
|
||||
}
|
||||
|
||||
void Scheduler::ClearDeadThreadsFromFront() {
|
||||
while (runnable_threads_.size() > 0 &&
|
||||
runnable_threads_.PeekFront()->IsDying()) {
|
||||
runnable_threads_.PopFront();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ class Scheduler {
|
|||
|
||||
Scheduler();
|
||||
void SwapToCurrent(Thread& prev);
|
||||
|
||||
void ClearDeadThreadsFromFront();
|
||||
};
|
||||
|
||||
extern Scheduler* gScheduler;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue