|
|
|
@ -42,7 +42,7 @@ CoreTiming::CoreTiming() { |
|
|
|
CoreTiming::~CoreTiming() = default; |
|
|
|
|
|
|
|
void CoreTiming::ThreadEntry(CoreTiming& instance) { |
|
|
|
instance.Advance(); |
|
|
|
instance.ThreadLoop(); |
|
|
|
} |
|
|
|
|
|
|
|
void CoreTiming::Initialize() { |
|
|
|
@ -137,11 +137,8 @@ void CoreTiming::RemoveEvent(const std::shared_ptr<EventType>& event_type) { |
|
|
|
basic_lock.unlock(); |
|
|
|
} |
|
|
|
|
|
|
|
void CoreTiming::Advance() { |
|
|
|
has_started = true; |
|
|
|
while (!shutting_down) { |
|
|
|
while (!paused) { |
|
|
|
paused_set = false; |
|
|
|
std::optional<u64> CoreTiming::Advance() { |
|
|
|
advance_lock.lock(); |
|
|
|
basic_lock.lock(); |
|
|
|
global_timer = GetGlobalTimeNs().count(); |
|
|
|
|
|
|
|
@ -159,16 +156,30 @@ void CoreTiming::Advance() { |
|
|
|
} |
|
|
|
|
|
|
|
if (!event_queue.empty()) { |
|
|
|
std::chrono::nanoseconds next_time = |
|
|
|
std::chrono::nanoseconds(event_queue.front().time - global_timer); |
|
|
|
const u64 next_time = event_queue.front().time - global_timer; |
|
|
|
basic_lock.unlock(); |
|
|
|
event.WaitFor(next_time); |
|
|
|
advance_lock.unlock(); |
|
|
|
return next_time; |
|
|
|
} else { |
|
|
|
basic_lock.unlock(); |
|
|
|
advance_lock.unlock(); |
|
|
|
return std::nullopt; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void CoreTiming::ThreadLoop() { |
|
|
|
has_started = true; |
|
|
|
while (!shutting_down) { |
|
|
|
while (!paused) { |
|
|
|
paused_set = false; |
|
|
|
const auto next_time = Advance(); |
|
|
|
if (next_time) { |
|
|
|
std::chrono::nanoseconds next_time_ns = std::chrono::nanoseconds(*next_time); |
|
|
|
event.WaitFor(next_time_ns); |
|
|
|
} else { |
|
|
|
wait_set = true; |
|
|
|
event.Wait(); |
|
|
|
} |
|
|
|
|
|
|
|
wait_set = false; |
|
|
|
} |
|
|
|
paused_set = true; |
|
|
|
|