[Kernel] Implement thread sleeping

This commit is contained in:
wheremyfoodat 2022-10-11 22:45:25 +03:00
parent db0adc55c1
commit 2a4709dcfa
6 changed files with 60 additions and 7 deletions

View file

@ -107,6 +107,8 @@ class CPU {
Memory& mem;
public:
static constexpr u64 ticksPerSec = 268111856;
CPU(Memory& mem, Kernel& kernel);
void reset();
@ -161,7 +163,7 @@ public:
}
void runFrame() {
env.ticksLeft = 268111856 / 60;
env.ticksLeft = ticksPerSec / 60;
const auto exitReason = jit->Run();
if (static_cast<u32>(exitReason) != 0) [[unlikely]] {

View file

@ -66,6 +66,7 @@ class Kernel {
Handle makeThread(u32 entrypoint, u32 initialSP, u32 priority, s32 id, u32 arg,ThreadStatus status = ThreadStatus::Dormant);
void signalArbiter(u32 waitingAddress, s32 threadCount);
void sleepThread(s64 ns);
void sleepThreadOnArbiter(u32 waitingAddress);
void switchThread(int newThreadIndex);
void sortThreads();
@ -116,6 +117,7 @@ class Kernel {
void sendSyncRequest();
void signalEvent();
void svcCloseHandle();
void svcSleepThread();
void connectToPort();
void outputDebugString();
void waitSynchronization1();

View file

@ -116,6 +116,11 @@ struct Thread {
// The waiting address for threads that are waiting on an AddressArbiter
u32 waitingAddress;
// The nanoseconds until a thread wakes up from being asleep or from timing out while waiting on an arbiter
s64 waitingNanoseconds;
// The tick this thread went to sleep on
u64 sleepTick;
// Thread context used for switching between threads
std::array<u32, 16> gprs;
std::array<u32, 32> fprs; // Stored as u32 because dynarmic does it