diff options
| author | 2015-05-16 11:56:00 -0600 | |
|---|---|---|
| committer | 2015-05-18 08:15:57 -0600 | |
| commit | a406207cd81c9fc3218f29394e11e7711817c458 (patch) | |
| tree | 87bf96769c74b48468144e9ab238688ee9370434 | |
| parent | Merge pull request #781 from archshift/delete (diff) | |
| download | yuzu-a406207cd81c9fc3218f29394e11e7711817c458.tar.gz yuzu-a406207cd81c9fc3218f29394e11e7711817c458.tar.xz yuzu-a406207cd81c9fc3218f29394e11e7711817c458.zip | |
Use condition var to properly pause the CPU thread
Adds support for threaded pausing so citra doesn't spin wait on pause
| -rw-r--r-- | src/citra_qt/bootmanager.cpp | 3 | ||||
| -rw-r--r-- | src/citra_qt/bootmanager.h | 13 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index d3df289f8..ab9403007 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp | |||
| @@ -59,6 +59,9 @@ void EmuThread::run() { | |||
| 59 | yieldCurrentThread(); | 59 | yieldCurrentThread(); |
| 60 | 60 | ||
| 61 | was_active = false; | 61 | was_active = false; |
| 62 | } else { | ||
| 63 | std::unique_lock<std::mutex> lock(running_mutex); | ||
| 64 | running_cv.wait(lock, [this]{ return IsRunning() || stop_run; }); | ||
| 62 | } | 65 | } |
| 63 | } | 66 | } |
| 64 | 67 | ||
diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h index d5d74c949..16809eaae 100644 --- a/src/citra_qt/bootmanager.h +++ b/src/citra_qt/bootmanager.h | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <atomic> | 5 | #include <atomic> |
| 6 | #include <condition_variable> | ||
| 7 | #include <mutex> | ||
| 6 | 8 | ||
| 7 | #include <QThread> | 9 | #include <QThread> |
| 8 | #include <QGLWidget> | 10 | #include <QGLWidget> |
| @@ -40,7 +42,12 @@ public: | |||
| 40 | * @param running Boolean value, set the emulation thread to running if true | 42 | * @param running Boolean value, set the emulation thread to running if true |
| 41 | * @note This function is thread-safe | 43 | * @note This function is thread-safe |
| 42 | */ | 44 | */ |
| 43 | void SetRunning(bool running) { this->running = running; } | 45 | void SetRunning(bool running) { |
| 46 | std::unique_lock<std::mutex> lock(running_mutex); | ||
| 47 | this->running = running; | ||
| 48 | lock.unlock(); | ||
| 49 | running_cv.notify_all(); | ||
| 50 | } | ||
| 44 | 51 | ||
| 45 | /** | 52 | /** |
| 46 | * Check if the emulation thread is running or not | 53 | * Check if the emulation thread is running or not |
| @@ -54,13 +61,15 @@ public: | |||
| 54 | */ | 61 | */ |
| 55 | void RequestStop() { | 62 | void RequestStop() { |
| 56 | stop_run = true; | 63 | stop_run = true; |
| 57 | running = false; | 64 | SetRunning(false); |
| 58 | }; | 65 | }; |
| 59 | 66 | ||
| 60 | private: | 67 | private: |
| 61 | bool exec_step; | 68 | bool exec_step; |
| 62 | bool running; | 69 | bool running; |
| 63 | std::atomic<bool> stop_run; | 70 | std::atomic<bool> stop_run; |
| 71 | std::mutex running_mutex; | ||
| 72 | std::condition_variable running_cv; | ||
| 64 | 73 | ||
| 65 | GRenderWindow* render_window; | 74 | GRenderWindow* render_window; |
| 66 | 75 | ||