diff options
| author | 2020-06-27 18:20:06 -0400 | |
|---|---|---|
| committer | 2020-06-27 18:20:06 -0400 | |
| commit | 2f8947583f2f0af4058600243d6c1d244e3c4890 (patch) | |
| tree | a0e7a10c6131efb23d6fdb3ee7fc0de4bd4163af /src/core/core_timing.cpp | |
| parent | NvFlinger: Clang Format. (diff) | |
| download | yuzu-2f8947583f2f0af4058600243d6c1d244e3c4890.tar.gz yuzu-2f8947583f2f0af4058600243d6c1d244e3c4890.tar.xz yuzu-2f8947583f2f0af4058600243d6c1d244e3c4890.zip | |
Core/Common: Address Feedback.
Diffstat (limited to 'src/core/core_timing.cpp')
| -rw-r--r-- | src/core/core_timing.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 1aa89a1cc..5c83c41a4 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp | |||
| @@ -45,9 +45,9 @@ CoreTiming::CoreTiming() { | |||
| 45 | CoreTiming::~CoreTiming() = default; | 45 | CoreTiming::~CoreTiming() = default; |
| 46 | 46 | ||
| 47 | void CoreTiming::ThreadEntry(CoreTiming& instance) { | 47 | void CoreTiming::ThreadEntry(CoreTiming& instance) { |
| 48 | std::string name = "yuzu:HostTiming"; | 48 | constexpr char name[] = "yuzu:HostTiming"; |
| 49 | MicroProfileOnThreadCreate(name.c_str()); | 49 | MicroProfileOnThreadCreate(name); |
| 50 | Common::SetCurrentThreadName(name.c_str()); | 50 | Common::SetCurrentThreadName(name); |
| 51 | Common::SetCurrentThreadPriority(Common::ThreadPriority::VeryHigh); | 51 | Common::SetCurrentThreadPriority(Common::ThreadPriority::VeryHigh); |
| 52 | instance.on_thread_init(); | 52 | instance.on_thread_init(); |
| 53 | instance.ThreadLoop(); | 53 | instance.ThreadLoop(); |
| @@ -108,18 +108,19 @@ bool CoreTiming::HasPendingEvents() const { | |||
| 108 | 108 | ||
| 109 | void CoreTiming::ScheduleEvent(s64 ns_into_future, const std::shared_ptr<EventType>& event_type, | 109 | void CoreTiming::ScheduleEvent(s64 ns_into_future, const std::shared_ptr<EventType>& event_type, |
| 110 | u64 userdata) { | 110 | u64 userdata) { |
| 111 | basic_lock.lock(); | 111 | { |
| 112 | const u64 timeout = static_cast<u64>(GetGlobalTimeNs().count() + ns_into_future); | 112 | std::scoped_lock scope{basic_lock}; |
| 113 | const u64 timeout = static_cast<u64>(GetGlobalTimeNs().count() + ns_into_future); | ||
| 113 | 114 | ||
| 114 | event_queue.emplace_back(Event{timeout, event_fifo_id++, userdata, event_type}); | 115 | event_queue.emplace_back(Event{timeout, event_fifo_id++, userdata, event_type}); |
| 115 | 116 | ||
| 116 | std::push_heap(event_queue.begin(), event_queue.end(), std::greater<>()); | 117 | std::push_heap(event_queue.begin(), event_queue.end(), std::greater<>()); |
| 117 | basic_lock.unlock(); | 118 | } |
| 118 | event.Set(); | 119 | event.Set(); |
| 119 | } | 120 | } |
| 120 | 121 | ||
| 121 | void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, u64 userdata) { | 122 | void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, u64 userdata) { |
| 122 | basic_lock.lock(); | 123 | std::scoped_lock scope{basic_lock}; |
| 123 | const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { | 124 | const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { |
| 124 | return e.type.lock().get() == event_type.get() && e.userdata == userdata; | 125 | return e.type.lock().get() == event_type.get() && e.userdata == userdata; |
| 125 | }); | 126 | }); |
| @@ -129,7 +130,6 @@ void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, u | |||
| 129 | event_queue.erase(itr, event_queue.end()); | 130 | event_queue.erase(itr, event_queue.end()); |
| 130 | std::make_heap(event_queue.begin(), event_queue.end(), std::greater<>()); | 131 | std::make_heap(event_queue.begin(), event_queue.end(), std::greater<>()); |
| 131 | } | 132 | } |
| 132 | basic_lock.unlock(); | ||
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | void CoreTiming::AddTicks(u64 ticks) { | 135 | void CoreTiming::AddTicks(u64 ticks) { |
| @@ -187,8 +187,8 @@ void CoreTiming::RemoveEvent(const std::shared_ptr<EventType>& event_type) { | |||
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | std::optional<s64> CoreTiming::Advance() { | 189 | std::optional<s64> CoreTiming::Advance() { |
| 190 | advance_lock.lock(); | 190 | std::scoped_lock advance_scope{advance_lock}; |
| 191 | basic_lock.lock(); | 191 | std::scoped_lock basic_scope{basic_lock}; |
| 192 | global_timer = GetGlobalTimeNs().count(); | 192 | global_timer = GetGlobalTimeNs().count(); |
| 193 | 193 | ||
| 194 | while (!event_queue.empty() && event_queue.front().time <= global_timer) { | 194 | while (!event_queue.empty() && event_queue.front().time <= global_timer) { |
| @@ -207,12 +207,8 @@ std::optional<s64> CoreTiming::Advance() { | |||
| 207 | 207 | ||
| 208 | if (!event_queue.empty()) { | 208 | if (!event_queue.empty()) { |
| 209 | const s64 next_time = event_queue.front().time - global_timer; | 209 | const s64 next_time = event_queue.front().time - global_timer; |
| 210 | basic_lock.unlock(); | ||
| 211 | advance_lock.unlock(); | ||
| 212 | return next_time; | 210 | return next_time; |
| 213 | } else { | 211 | } else { |
| 214 | basic_lock.unlock(); | ||
| 215 | advance_lock.unlock(); | ||
| 216 | return std::nullopt; | 212 | return std::nullopt; |
| 217 | } | 213 | } |
| 218 | } | 214 | } |