diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 5d6836f45..6992173f3 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -13,6 +13,7 @@ #include "qtutils.h" #include #include +#include #include #include Log_SetChannel(QtHostInterface); @@ -374,6 +375,8 @@ void QtHostInterface::pauseSystem(bool paused) m_paused = paused; m_audio_stream->PauseOutput(paused); + if (!paused) + wakeThread(); emit emulationPaused(paused); } @@ -436,6 +439,7 @@ void QtHostInterface::doBootSystem(QString initial_filename, QString initial_sav return; } + wakeThread(); m_audio_stream->PauseOutput(false); emit emulationStarted(); } @@ -478,12 +482,13 @@ void QtHostInterface::doStopThread() void QtHostInterface::threadEntryPoint() { + m_worker_thread_event_loop = new QEventLoop(); while (!m_shutdown_flag.load()) { - if (!m_system) + if (!m_system || m_paused) { // wait until we have a system before running - QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + m_worker_thread_event_loop->exec(); continue; } @@ -516,15 +521,25 @@ void QtHostInterface::threadEntryPoint() UpdatePerformanceCounters(); } - QCoreApplication::processEvents(QEventLoop::AllEvents, m_paused ? 16 : 0); + m_worker_thread_event_loop->processEvents(QEventLoop::AllEvents); } m_system.reset(); + delete m_worker_thread_event_loop; + m_worker_thread_event_loop = nullptr; // move back to UI thread moveToThread(m_original_thread); } +void QtHostInterface::wakeThread() +{ + if (isOnWorkerThread()) + m_worker_thread_event_loop->quit(); + else + QMetaObject::invokeMethod(m_worker_thread_event_loop, "quit", Qt::QueuedConnection); +} + QtHostInterface::Thread::Thread(QtHostInterface* parent) : QThread(parent), m_parent(parent) {} QtHostInterface::Thread::~Thread() = default; diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index 48711179d..c0a677cb4 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -14,6 +14,7 @@ class ByteStream; +class QEventLoop; class QWidget; class GameList; @@ -116,6 +117,7 @@ private: void createThread(); void stopThread(); void threadEntryPoint(); + void wakeThread(); QSettings m_qsettings; @@ -124,6 +126,7 @@ private: QtDisplayWindow* m_display_window = nullptr; QThread* m_original_thread = nullptr; Thread* m_worker_thread = nullptr; + QEventLoop* m_worker_thread_event_loop = nullptr; std::atomic_bool m_shutdown_flag{false};