OS Timers part 2

This commit is contained in:
wheremyfoodat 2023-08-13 23:32:07 +03:00
parent 68bb052618
commit fa58c7a7d6
4 changed files with 33 additions and 1 deletions

View file

@ -163,6 +163,17 @@ struct Semaphore {
Semaphore(s32 initialCount, s32 maximumCount) : availableCount(initialCount), maximumCount(maximumCount), waitlist(0) {}
};
struct Timer {
u64 waitlist; // Refer to the getWaitlist function below for documentation
ResetType resetType = ResetType::OneShot;
u64 initialDelay; // Number of ns until the timer fires for the first time
u64 interval; // Number of ns until the timer fires for the second and future times
bool fired; // Has this Timer been signalled?
Timer(ResetType type) : resetType(type), initialDelay(0), interval(0), waitlist(0), fired(false) {}
};
struct MemoryBlock {
u32 addr = 0;
u32 size = 0;

View file

@ -122,6 +122,7 @@ void Kernel::deleteObjectData(KernelObject& object) {
case KernelObjectType::Session: delete object.getData<Session>(); return;
case KernelObjectType::Mutex: delete object.getData<Mutex>(); return;
case KernelObjectType::Semaphore: delete object.getData<Semaphore>(); return;
case KernelObjectType::Timer: delete object.getData<Timer>(); return;
case KernelObjectType::Thread: return;
case KernelObjectType::Dummy: return;
default: [[unlikely]] Helpers::warn("unknown object type"); return;

View file

@ -612,6 +612,9 @@ bool Kernel::shouldWaitOnObject(KernelObject* object) {
case KernelObjectType::Thread: // Waiting on a thread waits until it's dead. If it's dead then no need to wait
return object->getData<Thread>()->status != ThreadStatus::Dead;
case KernelObjectType::Timer: // We should wait on a timer only if it has not been signalled
return !object->getData<Timer>()->fired;
case KernelObjectType::Semaphore: // Wait if the semaphore count <= 0
return object->getData<Semaphore>()->availableCount <= 0;

View file

@ -1,6 +1,23 @@
#include "kernel.hpp"
void Kernel::svcCreateTimer() { Helpers::panic("Kernel::CreateTimer"); }
Handle Kernel::makeTimer(ResetType type) {
Handle ret = makeObject(KernelObjectType::Timer);
objects[ret].data = new Timer(type);
return ret;
}
void Kernel::svcCreateTimer() {
const u32 resetType = regs[1];
if (resetType > 2) {
Helpers::panic("Invalid reset type for event %d", resetType);
}
logSVC("CreateTimer (resetType = %s)\n", resetTypeToString(resetType));
regs[0] = Result::Success;
regs[1] = makeTimer(static_cast<ResetType>(resetType));
}
void Kernel::svcSetTimer() { Helpers::panic("Kernel::SetTimer"); }
void Kernel::svcClearTimer() { Helpers::panic("Kernel::ClearTimer"); }
void Kernel::svcCancelTimer() { Helpers::panic("Kernel::CancelTimer"); }