mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-06 22:25:41 +12:00
OS Timers part 2
This commit is contained in:
parent
68bb052618
commit
fa58c7a7d6
4 changed files with 33 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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"); }
|
Loading…
Add table
Reference in a new issue