diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2022-12-20 09:10:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-20 09:10:41 -0500 |
commit | 1b11e0f0d3209603e67b26f3ef22f1d1a493bbdc (patch) | |
tree | e5e99d292065c14dc92605070ee1086675c046a0 /src/yuzu/bootmanager.h | |
parent | fe126f993d7fdef2aa3d2d5b375e3b707e888918 (diff) | |
parent | 92ce241d4d49baaefb610480f65db73271f0c015 (diff) |
Merge pull request #9463 from liamwhite/manager-events
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 b24141fd9..1c2e76369 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); }; |