Handout
This commit is contained in:
36
kernel/thread/thread.cc
Normal file
36
kernel/thread/thread.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
// vim: set noet ts=4 sw=4:
|
||||
|
||||
#include "thread.h"
|
||||
|
||||
#include "../debug/kernelpanic.h"
|
||||
#include "../interrupt/guard.h"
|
||||
#include "debug/output.h"
|
||||
|
||||
// counter for ID
|
||||
static size_t idCounter = 1;
|
||||
|
||||
void Thread::kickoff(uintptr_t param1, uintptr_t param2, uintptr_t param3) {
|
||||
Thread *thread = reinterpret_cast<Thread *>(param1);
|
||||
assert(thread != nullptr && "Kickoff got nullptr pointer to Thread");
|
||||
(void)param2; // will be used later
|
||||
(void)param3; // will be used later
|
||||
// The core must have entered level 1/2 to cause a thread to be scheduled.
|
||||
Guard::leave();
|
||||
|
||||
thread->action();
|
||||
}
|
||||
|
||||
Thread::Thread() : queue_link(nullptr), id(idCounter++), kill_flag(false) {
|
||||
void *tos = reinterpret_cast<void *>(reserved_stack_space + STACK_SIZE);
|
||||
prepareContext(tos, context, kickoff, reinterpret_cast<uintptr_t>(this), 0,
|
||||
0);
|
||||
}
|
||||
|
||||
void Thread::resume(Thread *next) {
|
||||
assert(next != nullptr && "Pointer to next Thread must not be nullptr!");
|
||||
context_switch(&next->context, &context);
|
||||
}
|
||||
|
||||
void Thread::go() { context_launch(&context); }
|
||||
|
||||
void Thread::action() { kernelpanic("Wrong entry / missing action in Thread"); }
|
||||
Reference in New Issue
Block a user