diff options
| author | 2023-01-18 15:13:38 -0800 | |
|---|---|---|
| committer | 2023-01-18 15:13:38 -0800 | |
| commit | 413df0811d589fb147f24e29caab5285d62e1a6a (patch) | |
| tree | fcd0e4cb6696dfc1964d3169a7db1a63348efdbf /src/core/core_timing.cpp | |
| parent | Merge pull request #9615 from merryhime/upsample-ob1 (diff) | |
| parent | timing: wait for completion on unregister (diff) | |
| download | yuzu-413df0811d589fb147f24e29caab5285d62e1a6a.tar.gz yuzu-413df0811d589fb147f24e29caab5285d62e1a6a.tar.xz yuzu-413df0811d589fb147f24e29caab5285d62e1a6a.zip | |
Merge pull request #9619 from liamwhite/timing-spaghetti
timing: wait for completion on unregister
Diffstat (limited to 'src/core/core_timing.cpp')
| -rw-r--r-- | src/core/core_timing.cpp | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 0e7b5f943..6bac6722f 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp | |||
| @@ -142,16 +142,24 @@ void CoreTiming::ScheduleLoopingEvent(std::chrono::nanoseconds start_time, | |||
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, | 144 | void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, |
| 145 | std::uintptr_t user_data) { | 145 | std::uintptr_t user_data, bool wait) { |
| 146 | std::scoped_lock scope{basic_lock}; | 146 | { |
| 147 | const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { | 147 | std::scoped_lock lk{basic_lock}; |
| 148 | return e.type.lock().get() == event_type.get() && e.user_data == user_data; | 148 | const auto itr = |
| 149 | }); | 149 | std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { |
| 150 | 150 | return e.type.lock().get() == event_type.get() && e.user_data == user_data; | |
| 151 | // Removing random items breaks the invariant so we have to re-establish it. | 151 | }); |
| 152 | if (itr != event_queue.end()) { | 152 | |
| 153 | event_queue.erase(itr, event_queue.end()); | 153 | // Removing random items breaks the invariant so we have to re-establish it. |
| 154 | std::make_heap(event_queue.begin(), event_queue.end(), std::greater<>()); | 154 | if (itr != event_queue.end()) { |
| 155 | event_queue.erase(itr, event_queue.end()); | ||
| 156 | std::make_heap(event_queue.begin(), event_queue.end(), std::greater<>()); | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 160 | // Force any in-progress events to finish | ||
| 161 | if (wait) { | ||
| 162 | std::scoped_lock lk{advance_lock}; | ||
| 155 | } | 163 | } |
| 156 | } | 164 | } |
| 157 | 165 | ||
| @@ -190,20 +198,6 @@ u64 CoreTiming::GetClockTicks() const { | |||
| 190 | return CpuCyclesToClockCycles(ticks); | 198 | return CpuCyclesToClockCycles(ticks); |
| 191 | } | 199 | } |
| 192 | 200 | ||
| 193 | void CoreTiming::RemoveEvent(const std::shared_ptr<EventType>& event_type) { | ||
| 194 | std::scoped_lock lock{basic_lock}; | ||
| 195 | |||
| 196 | const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { | ||
| 197 | return e.type.lock().get() == event_type.get(); | ||
| 198 | }); | ||
| 199 | |||
| 200 | // Removing random items breaks the invariant so we have to re-establish it. | ||
| 201 | if (itr != event_queue.end()) { | ||
| 202 | event_queue.erase(itr, event_queue.end()); | ||
| 203 | std::make_heap(event_queue.begin(), event_queue.end(), std::greater<>()); | ||
| 204 | } | ||
| 205 | } | ||
| 206 | |||
| 207 | std::optional<s64> CoreTiming::Advance() { | 201 | std::optional<s64> CoreTiming::Advance() { |
| 208 | std::scoped_lock lock{advance_lock, basic_lock}; | 202 | std::scoped_lock lock{advance_lock, basic_lock}; |
| 209 | global_timer = GetGlobalTimeNs().count(); | 203 | global_timer = GetGlobalTimeNs().count(); |