mirror of
https://github.com/PabloMK7/citra.git
synced 2024-12-01 11:49:37 +00:00
Merge pull request #783 from jroweboy/cond-wait
Use condition var to properly pause the CPU thread
This commit is contained in:
commit
1c3cda5d7e
2 changed files with 14 additions and 2 deletions
|
@ -59,6 +59,9 @@ void EmuThread::run() {
|
|||
yieldCurrentThread();
|
||||
|
||||
was_active = false;
|
||||
} else {
|
||||
std::unique_lock<std::mutex> lock(running_mutex);
|
||||
running_cv.wait(lock, [this]{ return IsRunning() || stop_run; });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
#include <QThread>
|
||||
#include <QGLWidget>
|
||||
|
@ -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<std::mutex> 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<bool> stop_run;
|
||||
std::mutex running_mutex;
|
||||
std::condition_variable running_cv;
|
||||
|
||||
GRenderWindow* render_window;
|
||||
|
||||
|
|
Loading…
Reference in a new issue