From 762c1a9ff5406afc4c6b1a3eb74dae2dc2fb0daf Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 16 Apr 2015 18:35:09 -0400 Subject: Qt: Move EmuThread ownership from render window to main window. --- src/citra_qt/bootmanager.cpp | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'src/citra_qt/bootmanager.cpp') diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index b81bd6167..50c8fed1e 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -10,6 +10,7 @@ #include "common/common.h" #include "bootmanager.h" +#include "main.h" #include "core/core.h" #include "core/settings.h" @@ -30,6 +31,7 @@ EmuThread::EmuThread(GRenderWindow* render_window) : filename(""), exec_cpu_step(false), cpu_running(false), stop_run(false), render_window(render_window) { + connect(this, SIGNAL(started()), render_window, SLOT(moveContext())); } void EmuThread::SetFilename(std::string filename) @@ -133,13 +135,9 @@ private: GRenderWindow* parent; }; -EmuThread& GRenderWindow::GetEmuThread() -{ - return emu_thread; -} +GRenderWindow::GRenderWindow(QWidget* parent, GMainWindow& main_window) : + QWidget(parent), main_window(main_window), keyboard_id(0) { -GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this), keyboard_id(0) -{ std::string window_title = Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc); setWindowTitle(QString::fromStdString(window_title)); @@ -160,7 +158,6 @@ GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this layout->addWidget(child); layout->setMargin(0); setLayout(layout); - connect(&emu_thread, SIGNAL(started()), this, SLOT(moveContext())); OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size); @@ -180,29 +177,17 @@ void GRenderWindow::moveContext() // We need to move GL context to the swapping thread in Qt5 #if QT_VERSION > QT_VERSION_CHECK(5, 0, 0) // If the thread started running, move the GL Context to the new thread. Otherwise, move it back. - child->context()->moveToThread((QThread::currentThread() == qApp->thread()) ? &emu_thread : qApp->thread()); + auto thread = QThread::currentThread() == qApp->thread() ? main_window.GetEmuThread() : qApp->thread(); + child->context()->moveToThread(thread); #endif } -GRenderWindow::~GRenderWindow() -{ - if (emu_thread.isRunning()) - emu_thread.Stop(); -} - void GRenderWindow::SwapBuffers() { // MakeCurrent is already called in renderer_opengl child->swapBuffers(); } -void GRenderWindow::closeEvent(QCloseEvent* event) -{ - if (emu_thread.isRunning()) - emu_thread.Stop(); - QWidget::closeEvent(event); -} - void GRenderWindow::MakeCurrent() { child->makeCurrent(); -- cgit v1.2.3 From d5665fea89dc2684e145e82a1b07086f11a13a65 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 16 Apr 2015 19:19:05 -0400 Subject: EmuThread: Remove unused filename attribute. --- src/citra_qt/bootmanager.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/citra_qt/bootmanager.cpp') diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 50c8fed1e..c2b7ba0e2 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -28,15 +28,9 @@ #define COPYRIGHT "Copyright (C) 2013-2014 Citra Team" EmuThread::EmuThread(GRenderWindow* render_window) : - filename(""), exec_cpu_step(false), cpu_running(false), - stop_run(false), render_window(render_window) -{ - connect(this, SIGNAL(started()), render_window, SLOT(moveContext())); -} + exec_cpu_step(false), cpu_running(false), stop_run(false), render_window(render_window) { -void EmuThread::SetFilename(std::string filename) -{ - this->filename = filename; + connect(this, SIGNAL(started()), render_window, SLOT(moveContext())); } void EmuThread::run() -- cgit v1.2.3 From 28df8dbfeb17cf5a002a5504a6bd2ba5091bf07c Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 16 Apr 2015 23:31:14 -0400 Subject: Qt: Create emu thread on bootup, kill it on shutdown. --- src/citra_qt/bootmanager.cpp | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'src/citra_qt/bootmanager.cpp') diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index c2b7ba0e2..fa4e976f4 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -30,21 +30,19 @@ EmuThread::EmuThread(GRenderWindow* render_window) : exec_cpu_step(false), cpu_running(false), stop_run(false), render_window(render_window) { + shutdown_event.Reset(); connect(this, SIGNAL(started()), render_window, SLOT(moveContext())); } -void EmuThread::run() -{ +void EmuThread::run() { stop_run = false; // holds whether the cpu was running during the last iteration, // so that the DebugModeLeft signal can be emitted before the // next execution step bool was_active = false; - while (!stop_run) - { - if (cpu_running) - { + while (!stop_run) { + if (cpu_running) { if (!was_active) emit DebugModeLeft(); @@ -53,9 +51,7 @@ void EmuThread::run() was_active = cpu_running || exec_cpu_step; if (!was_active) emit DebugModeEntered(); - } - else if (exec_cpu_step) - { + } else if (exec_cpu_step) { if (!was_active) emit DebugModeLeft(); @@ -67,15 +63,14 @@ void EmuThread::run() was_active = false; } } + render_window->moveContext(); - Core::Stop(); + shutdown_event.Set(); } -void EmuThread::Stop() -{ - if (!isRunning()) - { +void EmuThread::Stop() { + if (!isRunning()) { LOG_WARNING(Frontend, "EmuThread::Stop called while emu thread wasn't running, returning..."); return; } @@ -88,23 +83,19 @@ void EmuThread::Stop() // TODO: Waiting here is just a bad workaround for retarded shutdown logic. wait(1000); - if (isRunning()) - { + if (isRunning()) { LOG_WARNING(Frontend, "EmuThread still running, terminating..."); quit(); // TODO: Waiting 50 seconds can be necessary if the logging subsystem has a lot of spam // queued... This should be fixed. wait(50000); - if (isRunning()) - { + if (isRunning()) { LOG_CRITICAL(Frontend, "EmuThread STILL running, something is wrong here..."); terminate(); } } LOG_INFO(Frontend, "EmuThread stopped"); - - System::Shutdown(); } -- cgit v1.2.3 From e4ea133717a5292339c134160da984ba186d3de8 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 28 Apr 2015 19:03:01 -0400 Subject: Qt: Restructured to remove unnecessary shutdown event and various cleanups. --- src/citra_qt/bootmanager.cpp | 43 +++++-------------------------------------- 1 file changed, 5 insertions(+), 38 deletions(-) (limited to 'src/citra_qt/bootmanager.cpp') diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index fa4e976f4..1e902a8b6 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -28,9 +28,8 @@ #define COPYRIGHT "Copyright (C) 2013-2014 Citra Team" EmuThread::EmuThread(GRenderWindow* render_window) : - exec_cpu_step(false), cpu_running(false), stop_run(false), render_window(render_window) { + exec_step(false), running(false), stop_run(false), render_window(render_window) { - shutdown_event.Reset(); connect(this, SIGNAL(started()), render_window, SLOT(moveContext())); } @@ -42,20 +41,20 @@ void EmuThread::run() { // next execution step bool was_active = false; while (!stop_run) { - if (cpu_running) { + if (running) { if (!was_active) emit DebugModeLeft(); Core::RunLoop(); - was_active = cpu_running || exec_cpu_step; + was_active = running || exec_step; if (!was_active) emit DebugModeEntered(); - } else if (exec_cpu_step) { + } else if (exec_step) { if (!was_active) emit DebugModeLeft(); - exec_cpu_step = false; + exec_step = false; Core::SingleStep(); emit DebugModeEntered(); yieldCurrentThread(); @@ -65,40 +64,8 @@ void EmuThread::run() { } render_window->moveContext(); - - shutdown_event.Set(); } -void EmuThread::Stop() { - if (!isRunning()) { - LOG_WARNING(Frontend, "EmuThread::Stop called while emu thread wasn't running, returning..."); - return; - } - stop_run = true; - - // Release emu threads from any breakpoints, so that this doesn't hang forever. - Pica::g_debug_context->ClearBreakpoints(); - - //core::g_state = core::SYS_DIE; - - // TODO: Waiting here is just a bad workaround for retarded shutdown logic. - wait(1000); - if (isRunning()) { - LOG_WARNING(Frontend, "EmuThread still running, terminating..."); - quit(); - - // TODO: Waiting 50 seconds can be necessary if the logging subsystem has a lot of spam - // queued... This should be fixed. - wait(50000); - if (isRunning()) { - LOG_CRITICAL(Frontend, "EmuThread STILL running, something is wrong here..."); - terminate(); - } - } - LOG_INFO(Frontend, "EmuThread stopped"); -} - - // This class overrides paintEvent and resizeEvent to prevent the GUI thread from stealing GL context. // The corresponding functionality is handled in EmuThread instead class GGLWidgetInternal : public QGLWidget -- cgit v1.2.3 From 43cf42490730d8a1b980aa1fe9ebbbe1249232ef Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 29 Apr 2015 00:01:41 -0400 Subject: Qt: Use signals for emu_thread start/stop and fix disasm widget. --- src/citra_qt/bootmanager.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/citra_qt/bootmanager.cpp') diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 1e902a8b6..4be410fe0 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -87,8 +87,8 @@ private: GRenderWindow* parent; }; -GRenderWindow::GRenderWindow(QWidget* parent, GMainWindow& main_window) : - QWidget(parent), main_window(main_window), keyboard_id(0) { +GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) : + QWidget(parent), emu_thread(emu_thread), keyboard_id(0) { std::string window_title = Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc); setWindowTitle(QString::fromStdString(window_title)); @@ -129,7 +129,7 @@ void GRenderWindow::moveContext() // We need to move GL context to the swapping thread in Qt5 #if QT_VERSION > QT_VERSION_CHECK(5, 0, 0) // If the thread started running, move the GL Context to the new thread. Otherwise, move it back. - auto thread = QThread::currentThread() == qApp->thread() ? main_window.GetEmuThread() : qApp->thread(); + auto thread = (QThread::currentThread() == qApp->thread() && emu_thread != nullptr) ? emu_thread : qApp->thread(); child->context()->moveToThread(thread); #endif } @@ -272,3 +272,11 @@ void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair& minimal_size) { setMinimumSize(minimal_size.first, minimal_size.second); } + +void GRenderWindow::OnEmulationStarted(EmuThread* emu_thread) { + this->emu_thread = emu_thread; +} + +void GRenderWindow::OnEmulationStopped() { + emu_thread = nullptr; +} -- cgit v1.2.3 From bc41de2131728192e3fd4c8c83e8b2d6e5ba4530 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 30 Apr 2015 19:46:50 -0400 Subject: Qt: Fixed a bug in shutdown procedure, various cleanups. --- src/citra_qt/bootmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/citra_qt/bootmanager.cpp') diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 4be410fe0..66a9e6fba 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -48,7 +48,7 @@ void EmuThread::run() { Core::RunLoop(); was_active = running || exec_step; - if (!was_active) + if (!was_active && !stop_run) emit DebugModeEntered(); } else if (exec_step) { if (!was_active) @@ -273,10 +273,10 @@ void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pairemu_thread = emu_thread; } -void GRenderWindow::OnEmulationStopped() { +void GRenderWindow::OnEmulationStopping() { emu_thread = nullptr; } -- cgit v1.2.3