Browse Source
[windows] Use condvar wait to reduce sched contention
Signed-off-by: lizzie <lizzie@eden-emu.dev>
pull/2686/head
lizzie
5 months ago
No known key found for this signature in database
GPG Key ID: 287378CADCAB13
1 changed files with
1 additions and
21 deletions
-
src/core/core_timing.cpp
|
|
|
@ -288,28 +288,8 @@ void CoreTiming::ThreadLoop() { |
|
|
|
const auto next_time = Advance(); |
|
|
|
if (next_time) { |
|
|
|
// There are more events left in the queue, wait until the next event.
|
|
|
|
auto wait_time = *next_time - GetGlobalTimeNs().count(); |
|
|
|
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
|
|
|
|
if (auto wait_time = *next_time - GetGlobalTimeNs().count(); wait_time > 0) { |
|
|
|
event.WaitFor(std::chrono::nanoseconds(wait_time)); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
} else { |
|
|
|
// Queue is empty, wait until another event is scheduled and signals us to
|
|
|
|
|