[windows] Use condvar wait to reduce sched contention
All checks were successful
eden-license / license-header (pull_request) Successful in 25s

Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie 2025-10-06 09:09:34 +00:00
parent bc1d093fe9
commit ee4d944340
Signed by: Lizzie
GPG key ID: 00287378CADCAB13

View file

@ -288,28 +288,8 @@ void CoreTiming::ThreadLoop() {
const auto next_time = Advance(); const auto next_time = Advance();
if (next_time) { if (next_time) {
// There are more events left in the queue, wait until the next event. // There are more events left in the queue, wait until the next event.
auto wait_time = *next_time - GetGlobalTimeNs().count(); if (auto wait_time = *next_time - GetGlobalTimeNs().count(); wait_time > 0) {
if (wait_time > 0) {
#ifdef _WIN32
while (!paused && !event.IsSet() && wait_time > 0) {
wait_time = *next_time - GetGlobalTimeNs().count();
if (wait_time >= timer_resolution_ns) {
Common::Windows::SleepForOneTick();
} else {
#ifdef ARCHITECTURE_x86_64
Common::X64::MicroSleep();
#else
std::this_thread::yield();
#endif
}
}
if (event.IsSet()) {
event.Reset();
}
#else
event.WaitFor(std::chrono::nanoseconds(wait_time)); event.WaitFor(std::chrono::nanoseconds(wait_time));
#endif
} }
} else { } else {
// Queue is empty, wait until another event is scheduled and signals us to // Queue is empty, wait until another event is scheduled and signals us to