summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/core_timing.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index 18dfa07f5..ac117161c 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -72,7 +72,7 @@ void CoreTiming::Shutdown() {
72 is_paused = true; 72 is_paused = true;
73 shutting_down = true; 73 shutting_down = true;
74 { 74 {
75 std::unique_lock<std::mutex> main_lock(event_mutex); 75 std::unique_lock main_lock(event_mutex);
76 event_cv.notify_all(); 76 event_cv.notify_all();
77 wait_pause_cv.notify_all(); 77 wait_pause_cv.notify_all();
78 } 78 }
@@ -85,7 +85,7 @@ void CoreTiming::Shutdown() {
85} 85}
86 86
87void CoreTiming::Pause(bool is_paused_) { 87void CoreTiming::Pause(bool is_paused_) {
88 std::unique_lock<std::mutex> main_lock(event_mutex); 88 std::unique_lock main_lock(event_mutex);
89 if (is_paused_ == paused_state.load(std::memory_order_relaxed)) { 89 if (is_paused_ == paused_state.load(std::memory_order_relaxed)) {
90 return; 90 return;
91 } 91 }
@@ -100,7 +100,7 @@ void CoreTiming::Pause(bool is_paused_) {
100} 100}
101 101
102void CoreTiming::SyncPause(bool is_paused_) { 102void CoreTiming::SyncPause(bool is_paused_) {
103 std::unique_lock<std::mutex> main_lock(event_mutex); 103 std::unique_lock main_lock(event_mutex);
104 if (is_paused_ == paused_state.load(std::memory_order_relaxed)) { 104 if (is_paused_ == paused_state.load(std::memory_order_relaxed)) {
105 return; 105 return;
106 } 106 }
@@ -127,7 +127,7 @@ bool CoreTiming::IsRunning() const {
127} 127}
128 128
129bool CoreTiming::HasPendingEvents() const { 129bool CoreTiming::HasPendingEvents() const {
130 std::unique_lock<std::mutex> main_lock(event_mutex); 130 std::unique_lock main_lock(event_mutex);
131 return !event_queue.empty(); 131 return !event_queue.empty();
132} 132}
133 133
@@ -135,7 +135,7 @@ void CoreTiming::ScheduleEvent(std::chrono::nanoseconds ns_into_future,
135 const std::shared_ptr<EventType>& event_type, 135 const std::shared_ptr<EventType>& event_type,
136 std::uintptr_t user_data) { 136 std::uintptr_t user_data) {
137 137
138 std::unique_lock<std::mutex> main_lock(event_mutex); 138 std::unique_lock main_lock(event_mutex);
139 const u64 timeout = static_cast<u64>((GetGlobalTimeNs() + ns_into_future).count()); 139 const u64 timeout = static_cast<u64>((GetGlobalTimeNs() + ns_into_future).count());
140 140
141 event_queue.emplace_back(Event{timeout, event_fifo_id++, user_data, event_type}); 141 event_queue.emplace_back(Event{timeout, event_fifo_id++, user_data, event_type});
@@ -149,7 +149,7 @@ void CoreTiming::ScheduleEvent(std::chrono::nanoseconds ns_into_future,
149 149
150void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, 150void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type,
151 std::uintptr_t user_data) { 151 std::uintptr_t user_data) {
152 std::unique_lock<std::mutex> main_lock(event_mutex); 152 std::unique_lock main_lock(event_mutex);
153 const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { 153 const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) {
154 return e.type.lock().get() == event_type.get() && e.user_data == user_data; 154 return e.type.lock().get() == event_type.get() && e.user_data == user_data;
155 }); 155 });
@@ -197,12 +197,12 @@ u64 CoreTiming::GetClockTicks() const {
197} 197}
198 198
199void CoreTiming::ClearPendingEvents() { 199void CoreTiming::ClearPendingEvents() {
200 std::unique_lock<std::mutex> main_lock(event_mutex); 200 std::unique_lock main_lock(event_mutex);
201 event_queue.clear(); 201 event_queue.clear();
202} 202}
203 203
204void CoreTiming::RemoveEvent(const std::shared_ptr<EventType>& event_type) { 204void CoreTiming::RemoveEvent(const std::shared_ptr<EventType>& event_type) {
205 std::unique_lock<std::mutex> main_lock(event_mutex); 205 std::unique_lock main_lock(event_mutex);
206 206
207 const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { 207 const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) {
208 return e.type.lock().get() == event_type.get(); 208 return e.type.lock().get() == event_type.get();
@@ -218,7 +218,7 @@ void CoreTiming::RemoveEvent(const std::shared_ptr<EventType>& event_type) {
218std::optional<s64> CoreTiming::Advance() { 218std::optional<s64> CoreTiming::Advance() {
219 global_timer = GetGlobalTimeNs().count(); 219 global_timer = GetGlobalTimeNs().count();
220 220
221 std::unique_lock<std::mutex> main_lock(event_mutex); 221 std::unique_lock main_lock(event_mutex);
222 while (!event_queue.empty() && event_queue.front().time <= global_timer) { 222 while (!event_queue.empty() && event_queue.front().time <= global_timer) {
223 Event evt = std::move(event_queue.front()); 223 Event evt = std::move(event_queue.front());
224 std::pop_heap(event_queue.begin(), event_queue.end(), std::greater<>()); 224 std::pop_heap(event_queue.begin(), event_queue.end(), std::greater<>());
@@ -226,7 +226,7 @@ std::optional<s64> CoreTiming::Advance() {
226 event_mutex.unlock(); 226 event_mutex.unlock();
227 227
228 if (const auto event_type{evt.type.lock()}) { 228 if (const auto event_type{evt.type.lock()}) {
229 std::unique_lock<std::mutex> lk(event_type->guard); 229 std::unique_lock lk(event_type->guard);
230 event_type->callback(evt.user_data, std::chrono::nanoseconds{static_cast<s64>( 230 event_type->callback(evt.user_data, std::chrono::nanoseconds{static_cast<s64>(
231 GetGlobalTimeNs().count() - evt.time)}); 231 GetGlobalTimeNs().count() - evt.time)});
232 } 232 }
@@ -252,15 +252,15 @@ void CoreTiming::ThreadLoop() {
252 if (next_time) { 252 if (next_time) {
253 if (*next_time > 0) { 253 if (*next_time > 0) {
254 std::chrono::nanoseconds next_time_ns = std::chrono::nanoseconds(*next_time); 254 std::chrono::nanoseconds next_time_ns = std::chrono::nanoseconds(*next_time);
255 std::unique_lock<std::mutex> main_lock(event_mutex); 255 std::unique_lock main_lock(event_mutex);
256 event_cv.wait_for(main_lock, next_time_ns, predicate); 256 event_cv.wait_for(main_lock, next_time_ns, predicate);
257 } 257 }
258 } else { 258 } else {
259 std::unique_lock<std::mutex> main_lock(event_mutex); 259 std::unique_lock main_lock(event_mutex);
260 event_cv.wait(main_lock, predicate); 260 event_cv.wait(main_lock, predicate);
261 } 261 }
262 } 262 }
263 std::unique_lock<std::mutex> main_lock(event_mutex); 263 std::unique_lock main_lock(event_mutex);
264 pause_count++; 264 pause_count++;
265 if (pause_count == worker_threads.size()) { 265 if (pause_count == worker_threads.size()) {
266 clock->Pause(true); 266 clock->Pause(true);