From a406207cd81c9fc3218f29394e11e7711817c458 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Sat, 16 May 2015 11:56:00 -0600 Subject: Use condition var to properly pause the CPU thread Adds support for threaded pausing so citra doesn't spin wait on pause --- src/citra_qt/bootmanager.cpp | 3 +++ src/citra_qt/bootmanager.h | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src/citra_qt') diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index d3df289f..ab940300 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -59,6 +59,9 @@ void EmuThread::run() { yieldCurrentThread(); was_active = false; + } else { + std::unique_lock lock(running_mutex); + running_cv.wait(lock, [this]{ return IsRunning() || stop_run; }); } } diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h index d5d74c94..16809eaa 100644 --- a/src/citra_qt/bootmanager.h +++ b/src/citra_qt/bootmanager.h @@ -3,6 +3,8 @@ // Refer to the license.txt file included. #include +#include +#include #include #include @@ -40,7 +42,12 @@ public: * @param running Boolean value, set the emulation thread to running if true * @note This function is thread-safe */ - void SetRunning(bool running) { this->running = running; } + void SetRunning(bool running) { + std::unique_lock lock(running_mutex); + this->running = running; + lock.unlock(); + running_cv.notify_all(); + } /** * Check if the emulation thread is running or not @@ -54,13 +61,15 @@ public: */ void RequestStop() { stop_run = true; - running = false; + SetRunning(false); }; private: bool exec_step; bool running; std::atomic stop_run; + std::mutex running_mutex; + std::condition_variable running_cv; GRenderWindow* render_window; -- cgit v1.2.3