diff options
author | Liam <byteslice@airmail.cc> | 2022-12-17 14:34:03 -0500 |
---|---|---|
committer | Liam <byteslice@airmail.cc> | 2022-12-17 16:26:24 -0500 |
commit | d3123079e887710580b622b444a642ae298ddec0 (patch) | |
tree | 2bad10cc78ddb74f851a572dc69704154ea63b69 /src/yuzu/bootmanager.h | |
parent | 5da72a891fb4c4ddddbeefc0b235079fa3830743 (diff) |
EmuThread: refactor
Diffstat (limited to 'src/yuzu/bootmanager.h')
-rw-r--r-- | src/yuzu/bootmanager.h | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index 5bbcf61f7..52867d628 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h @@ -47,7 +47,7 @@ class EmuThread final : public QThread { Q_OBJECT public: - explicit EmuThread(Core::System& system_); + explicit EmuThread(Core::System& system); ~EmuThread() override; /** @@ -57,30 +57,30 @@ public: void run() override; /** - * Sets whether the emulation thread is running or not - * @param running_ Boolean value, set the emulation thread to running if true - * @note This function is thread-safe + * Sets whether the emulation thread should run or not + * @param should_run Boolean value, set the emulation thread to running if true */ - void SetRunning(bool running_) { - std::unique_lock lock{running_mutex}; - running = running_; - lock.unlock(); - running_cv.notify_all(); - if (!running) { - running_wait.Set(); - /// Wait until effectively paused - while (running_guard) - ; + void SetRunning(bool should_run) { + // TODO: Prevent other threads from modifying the state until we finish. + { + // Notify the running thread to change state. + std::unique_lock run_lk{m_should_run_mutex}; + m_should_run = should_run; + m_should_run_cv.notify_one(); + } + + // Wait until paused, if pausing. + if (!should_run) { + m_is_running.wait(true); } } /** * Check if the emulation thread is running or not * @return True if the emulation thread is running, otherwise false - * @note This function is thread-safe */ bool IsRunning() const { - return running; + return m_is_running.load(); } /** @@ -88,18 +88,17 @@ public: */ void ForceStop() { LOG_WARNING(Frontend, "Force stopping EmuThread"); - stop_source.request_stop(); - SetRunning(false); + m_stop_source.request_stop(); } private: - bool running = false; - std::stop_source stop_source; - std::mutex running_mutex; - std::condition_variable_any running_cv; - Common::Event running_wait{}; - std::atomic_bool running_guard{false}; - Core::System& system; + Core::System& m_system; + + std::stop_source m_stop_source; + std::mutex m_should_run_mutex; + std::condition_variable_any m_should_run_cv; + std::atomic<bool> m_is_running{false}; + bool m_should_run{true}; signals: /** @@ -120,8 +119,6 @@ signals: */ void DebugModeLeft(); - void ErrorThrown(Core::SystemResultStatus, std::string); - void LoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total); }; |