summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/thread.h2
-rw-r--r--src/core/hle/service/nvnflinger/nvnflinger.cpp14
-rw-r--r--src/core/hle/service/nvnflinger/nvnflinger.h3
-rw-r--r--src/core/hle/service/server_manager.cpp7
-rw-r--r--src/core/hle/service/server_manager.h4
-rw-r--r--src/video_core/renderer_vulkan/vk_master_semaphore.cpp22
-rw-r--r--src/video_core/renderer_vulkan/vk_master_semaphore.h1
-rw-r--r--src/yuzu/bootmanager.cpp6
-rw-r--r--src/yuzu/bootmanager.h7
9 files changed, 26 insertions, 40 deletions
diff --git a/src/common/thread.h b/src/common/thread.h
index 8ae169b4e..c6976fb6c 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -55,7 +55,7 @@ public:
55 is_set = false; 55 is_set = false;
56 } 56 }
57 57
58 [[nodiscard]] bool IsSet() { 58 [[nodiscard]] bool IsSet() const {
59 return is_set; 59 return is_set;
60 } 60 }
61 61
diff --git a/src/core/hle/service/nvnflinger/nvnflinger.cpp b/src/core/hle/service/nvnflinger/nvnflinger.cpp
index b41c6240c..5f55cd31e 100644
--- a/src/core/hle/service/nvnflinger/nvnflinger.cpp
+++ b/src/core/hle/service/nvnflinger/nvnflinger.cpp
@@ -43,14 +43,10 @@ void Nvnflinger::SplitVSync(std::stop_token stop_token) {
43 Common::SetCurrentThreadPriority(Common::ThreadPriority::High); 43 Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
44 44
45 while (!stop_token.stop_requested()) { 45 while (!stop_token.stop_requested()) {
46 vsync_signal.wait(false); 46 vsync_signal.Wait();
47 vsync_signal.store(false);
48
49 guard->lock();
50 47
48 const auto lock_guard = Lock();
51 Compose(); 49 Compose();
52
53 guard->unlock();
54 } 50 }
55} 51}
56 52
@@ -69,9 +65,8 @@ Nvnflinger::Nvnflinger(Core::System& system_, HosBinderDriverServer& hos_binder_
69 "ScreenComposition", 65 "ScreenComposition",
70 [this](std::uintptr_t, s64 time, 66 [this](std::uintptr_t, s64 time,
71 std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> { 67 std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
72 vsync_signal.store(true);
73 { const auto lock_guard = Lock(); } 68 { const auto lock_guard = Lock(); }
74 vsync_signal.notify_one(); 69 vsync_signal.Set();
75 return std::chrono::nanoseconds(GetNextTicks()); 70 return std::chrono::nanoseconds(GetNextTicks());
76 }); 71 });
77 72
@@ -97,8 +92,7 @@ Nvnflinger::~Nvnflinger() {
97 if (system.IsMulticore()) { 92 if (system.IsMulticore()) {
98 system.CoreTiming().UnscheduleEvent(multi_composition_event, {}); 93 system.CoreTiming().UnscheduleEvent(multi_composition_event, {});
99 vsync_thread.request_stop(); 94 vsync_thread.request_stop();
100 vsync_signal.store(true); 95 vsync_signal.Set();
101 vsync_signal.notify_all();
102 } else { 96 } else {
103 system.CoreTiming().UnscheduleEvent(single_composition_event, {}); 97 system.CoreTiming().UnscheduleEvent(single_composition_event, {});
104 } 98 }
diff --git a/src/core/hle/service/nvnflinger/nvnflinger.h b/src/core/hle/service/nvnflinger/nvnflinger.h
index a043cceb2..ef236303a 100644
--- a/src/core/hle/service/nvnflinger/nvnflinger.h
+++ b/src/core/hle/service/nvnflinger/nvnflinger.h
@@ -12,6 +12,7 @@
12 12
13#include "common/common_types.h" 13#include "common/common_types.h"
14#include "common/polyfill_thread.h" 14#include "common/polyfill_thread.h"
15#include "common/thread.h"
15#include "core/hle/result.h" 16#include "core/hle/result.h"
16#include "core/hle/service/kernel_helpers.h" 17#include "core/hle/service/kernel_helpers.h"
17 18
@@ -143,7 +144,7 @@ private:
143 144
144 Core::System& system; 145 Core::System& system;
145 146
146 std::atomic<bool> vsync_signal; 147 Common::Event vsync_signal;
147 148
148 std::jthread vsync_thread; 149 std::jthread vsync_thread;
149 150
diff --git a/src/core/hle/service/server_manager.cpp b/src/core/hle/service/server_manager.cpp
index 156bc27d8..d1e99b184 100644
--- a/src/core/hle/service/server_manager.cpp
+++ b/src/core/hle/service/server_manager.cpp
@@ -44,7 +44,7 @@ ServerManager::~ServerManager() {
44 m_event->Signal(); 44 m_event->Signal();
45 45
46 // Wait for processing to stop. 46 // Wait for processing to stop.
47 m_stopped.wait(false); 47 m_stopped.Wait();
48 m_threads.clear(); 48 m_threads.clear();
49 49
50 // Clean up ports. 50 // Clean up ports.
@@ -182,10 +182,7 @@ void ServerManager::StartAdditionalHostThreads(const char* name, size_t num_thre
182} 182}
183 183
184Result ServerManager::LoopProcess() { 184Result ServerManager::LoopProcess() {
185 SCOPE_EXIT({ 185 SCOPE_EXIT({ m_stopped.Set(); });
186 m_stopped.store(true);
187 m_stopped.notify_all();
188 });
189 186
190 R_RETURN(this->LoopProcessImpl()); 187 R_RETURN(this->LoopProcessImpl());
191} 188}
diff --git a/src/core/hle/service/server_manager.h b/src/core/hle/service/server_manager.h
index fdb8af2ff..58b0a0832 100644
--- a/src/core/hle/service/server_manager.h
+++ b/src/core/hle/service/server_manager.h
@@ -3,7 +3,6 @@
3 3
4#pragma once 4#pragma once
5 5
6#include <atomic>
7#include <functional> 6#include <functional>
8#include <list> 7#include <list>
9#include <map> 8#include <map>
@@ -12,6 +11,7 @@
12#include <vector> 11#include <vector>
13 12
14#include "common/polyfill_thread.h" 13#include "common/polyfill_thread.h"
14#include "common/thread.h"
15#include "core/hle/result.h" 15#include "core/hle/result.h"
16#include "core/hle/service/mutex.h" 16#include "core/hle/service/mutex.h"
17 17
@@ -82,7 +82,7 @@ private:
82 std::list<RequestState> m_deferrals{}; 82 std::list<RequestState> m_deferrals{};
83 83
84 // Host state tracking 84 // Host state tracking
85 std::atomic<bool> m_stopped{}; 85 Common::Event m_stopped{};
86 std::vector<std::jthread> m_threads{}; 86 std::vector<std::jthread> m_threads{};
87 std::stop_source m_stop_source{}; 87 std::stop_source m_stop_source{};
88}; 88};
diff --git a/src/video_core/renderer_vulkan/vk_master_semaphore.cpp b/src/video_core/renderer_vulkan/vk_master_semaphore.cpp
index 5eeda08d2..6b288b994 100644
--- a/src/video_core/renderer_vulkan/vk_master_semaphore.cpp
+++ b/src/video_core/renderer_vulkan/vk_master_semaphore.cpp
@@ -75,15 +75,9 @@ void MasterSemaphore::Refresh() {
75 75
76void MasterSemaphore::Wait(u64 tick) { 76void MasterSemaphore::Wait(u64 tick) {
77 if (!semaphore) { 77 if (!semaphore) {
78 // If we don't support timeline semaphores, use an atomic wait 78 // If we don't support timeline semaphores, wait for the value normally
79 while (true) { 79 std::unique_lock lk{free_mutex};
80 u64 current_value = gpu_tick.load(std::memory_order_relaxed); 80 free_cv.wait(lk, [&] { return gpu_tick.load(std::memory_order_relaxed) >= tick; });
81 if (current_value >= tick) {
82 return;
83 }
84 gpu_tick.wait(current_value);
85 }
86
87 return; 81 return;
88 } 82 }
89 83
@@ -198,11 +192,13 @@ void MasterSemaphore::WaitThread(std::stop_token token) {
198 192
199 fence.Wait(); 193 fence.Wait();
200 fence.Reset(); 194 fence.Reset();
201 gpu_tick.store(host_tick);
202 gpu_tick.notify_all();
203 195
204 std::scoped_lock lock{free_mutex}; 196 {
205 free_queue.push_front(std::move(fence)); 197 std::scoped_lock lock{free_mutex};
198 free_queue.push_front(std::move(fence));
199 gpu_tick.store(host_tick);
200 }
201 free_cv.notify_one();
206 } 202 }
207} 203}
208 204
diff --git a/src/video_core/renderer_vulkan/vk_master_semaphore.h b/src/video_core/renderer_vulkan/vk_master_semaphore.h
index 1e7c90215..3f599d7bd 100644
--- a/src/video_core/renderer_vulkan/vk_master_semaphore.h
+++ b/src/video_core/renderer_vulkan/vk_master_semaphore.h
@@ -72,6 +72,7 @@ private:
72 std::atomic<u64> current_tick{1}; ///< Current logical tick. 72 std::atomic<u64> current_tick{1}; ///< Current logical tick.
73 std::mutex wait_mutex; 73 std::mutex wait_mutex;
74 std::mutex free_mutex; 74 std::mutex free_mutex;
75 std::condition_variable free_cv;
75 std::condition_variable_any wait_cv; 76 std::condition_variable_any wait_cv;
76 std::queue<Waitable> wait_queue; ///< Queue for the fences to be waited on by the wait thread. 77 std::queue<Waitable> wait_queue; ///< Queue for the fences to be waited on by the wait thread.
77 std::deque<vk::Fence> free_queue; ///< Holds available fences for submission. 78 std::deque<vk::Fence> free_queue; ///< Holds available fences for submission.
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index cc6b6a25a..bdd1497b5 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -105,14 +105,12 @@ void EmuThread::run() {
105 std::unique_lock lk{m_should_run_mutex}; 105 std::unique_lock lk{m_should_run_mutex};
106 if (m_should_run) { 106 if (m_should_run) {
107 m_system.Run(); 107 m_system.Run();
108 m_is_running.store(true); 108 m_stopped.Reset();
109 m_is_running.notify_all();
110 109
111 Common::CondvarWait(m_should_run_cv, lk, stop_token, [&] { return !m_should_run; }); 110 Common::CondvarWait(m_should_run_cv, lk, stop_token, [&] { return !m_should_run; });
112 } else { 111 } else {
113 m_system.Pause(); 112 m_system.Pause();
114 m_is_running.store(false); 113 m_stopped.Set();
115 m_is_running.notify_all();
116 114
117 EmulationPaused(lk); 115 EmulationPaused(lk);
118 Common::CondvarWait(m_should_run_cv, lk, stop_token, [&] { return m_should_run; }); 116 Common::CondvarWait(m_should_run_cv, lk, stop_token, [&] { return m_should_run; });
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h
index b7b9d4141..87b23df12 100644
--- a/src/yuzu/bootmanager.h
+++ b/src/yuzu/bootmanager.h
@@ -3,7 +3,6 @@
3 3
4#pragma once 4#pragma once
5 5
6#include <atomic>
7#include <condition_variable> 6#include <condition_variable>
8#include <cstddef> 7#include <cstddef>
9#include <memory> 8#include <memory>
@@ -88,7 +87,7 @@ public:
88 87
89 // Wait until paused, if pausing. 88 // Wait until paused, if pausing.
90 if (!should_run) { 89 if (!should_run) {
91 m_is_running.wait(true); 90 m_stopped.Wait();
92 } 91 }
93 } 92 }
94 93
@@ -97,7 +96,7 @@ public:
97 * @return True if the emulation thread is running, otherwise false 96 * @return True if the emulation thread is running, otherwise false
98 */ 97 */
99 bool IsRunning() const { 98 bool IsRunning() const {
100 return m_is_running.load() || m_should_run; 99 return m_should_run;
101 } 100 }
102 101
103 /** 102 /**
@@ -118,7 +117,7 @@ private:
118 std::stop_source m_stop_source; 117 std::stop_source m_stop_source;
119 std::mutex m_should_run_mutex; 118 std::mutex m_should_run_mutex;
120 std::condition_variable_any m_should_run_cv; 119 std::condition_variable_any m_should_run_cv;
121 std::atomic<bool> m_is_running{false}; 120 Common::Event m_stopped;
122 bool m_should_run{true}; 121 bool m_should_run{true};
123 122
124signals: 123signals: