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

@ -73,7 +73,7 @@ void Kernel::waitSynchronization1() {
const auto object = getObject(handle);
if (object == nullptr) [[unlikely]] {
Helpers::panic("WaitSynchronization1: Bad event handle");
Helpers::panic("WaitSynchronization1: Bad event handle %X\n", handle);
regs[0] = SVCResult::BadHandle;
return;
}
@ -104,7 +104,7 @@ void Kernel::waitSynchronizationN() {
s32 pointer = regs[5];
s64 ns = s64(ns1) | (s64(ns2) << 32);
logSVC("WaitSynchronizationN (handle pointer: %08X, count: %d)\n", handles, handleCount);
logSVC("WaitSynchronizationN (handle pointer: %08X, count: %d, timeout = %lld)\n", handles, handleCount, ns);
ThreadStatus newStatus = waitAll ? ThreadStatus::WaitSyncAll : ThreadStatus::WaitSync1;
auto& t = threads[currentThreadIndex];
@ -118,7 +118,7 @@ void Kernel::waitSynchronizationN() {
auto object = getObject(handle);
if (object == nullptr) [[unlikely]] {
Helpers::panic("WaitSynchronizationN: Bad object handle");
Helpers::panic("WaitSynchronizationN: Bad object handle %X\n", handle);
regs[0] = SVCResult::BadHandle;
return;
}
@ -131,5 +131,6 @@ void Kernel::waitSynchronizationN() {
regs[0] = SVCResult::Success;
t.status = newStatus;
t.waitingNanoseconds = ns;
t.sleepTick = cpu.getTicks();
switchToNextThread();
}

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;