Semaphores v0.1

This commit is contained in:
wheremyfoodat 2022-11-17 22:14:56 +02:00
parent 3c55d88fab
commit 7b8cac8d43
6 changed files with 44 additions and 11 deletions

View file

@ -82,7 +82,8 @@ void Kernel::switchToNextThread() {
std::optional<int> newThreadIndex = getNextThread();
if (!newThreadIndex.has_value()) {
Helpers::panic("Kernel tried to switch to the next thread but none found");
Helpers::warn("Kernel tried to switch to the next thread but none found. Switching to thread 0\n");
switchThread(0);
} else {
switchThread(newThreadIndex.value());
}
@ -149,6 +150,13 @@ Handle Kernel::makeMutex(bool locked) {
return ret;
}
Handle Kernel::makeSemaphore(u32 initialCount, u32 maximumCount) {
Handle ret = makeObject(KernelObjectType::Semaphore);
objects[ret].data = new Semaphore(initialCount, maximumCount);
return ret;
}
void Kernel::sleepThreadOnArbiter(u32 waitingAddress) {
Thread& t = threads[currentThreadIndex];
t.status = ThreadStatus::WaitArbiter;