Handout
This commit is contained in:
26
kernel/thread/dispatcher.cc
Normal file
26
kernel/thread/dispatcher.cc
Normal file
@@ -0,0 +1,26 @@
|
||||
// vim: set noet ts=4 sw=4:
|
||||
|
||||
#include "dispatcher.h"
|
||||
|
||||
#include "../arch/core.h"
|
||||
#include "../debug/output.h" // IWYU pragma: keep
|
||||
|
||||
Dispatcher::Dispatcher() : life(nullptr) {}
|
||||
|
||||
Thread *Dispatcher::active() const { return life; }
|
||||
|
||||
void Dispatcher::go(Thread *first) {
|
||||
assert(active() == nullptr);
|
||||
setActive(first);
|
||||
first->go();
|
||||
}
|
||||
|
||||
void Dispatcher::dispatch(Thread *next) {
|
||||
Thread *current = active();
|
||||
assert(current != nullptr);
|
||||
if (current != next) {
|
||||
setActive(next);
|
||||
|
||||
current->resume(next);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user