Skip to content

Commit

Permalink
coreinit: Fix calculation of thread total awake time
Browse files Browse the repository at this point in the history
  • Loading branch information
Exzap committed Nov 17, 2024
1 parent 39cd95f commit 750376f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,13 +1114,13 @@ namespace coreinit
thread->requestFlags = (OSThread_t::REQUEST_FLAG_BIT)(thread->requestFlags & OSThread_t::REQUEST_FLAG_CANCEL); // remove all flags except cancel flag

// update total cycles
uint64 remainingCycles = std::min((uint64)hCPU->remainingCycles, (uint64)thread->quantumTicks);
uint64 executedCycles = thread->quantumTicks - remainingCycles;
if (executedCycles < hCPU->skippedCycles)
sint64 executedCycles = (sint64)thread->quantumTicks - (sint64)hCPU->remainingCycles;
executedCycles = std::max<sint64>(executedCycles, 0);
if (executedCycles < (sint64)hCPU->skippedCycles)
executedCycles = 0;
else
executedCycles -= hCPU->skippedCycles;
thread->totalCycles += executedCycles;
thread->totalCycles += (uint64)executedCycles;
// store context and set current thread to null
__OSThreadStoreContext(hCPU, thread);
OSSetCurrentThread(OSGetCoreId(), nullptr);
Expand Down

0 comments on commit 750376f

Please sign in to comment.