all repos — mgba @ 26dc21177a2cdf707f6ea70626a5c6cf0b5a8c5d

mGBA Game Boy Advance Emulator

Qt: Flesh out Interrupter some
Vicki Pfau vi@endrift.com
Sat, 12 Dec 2020 23:07:37 -0800
commit

26dc21177a2cdf707f6ea70626a5c6cf0b5a8c5d

parent

425baa17737ed51ee8c02715b1403f1ea8ab9391

2 files changed, 58 insertions(+), 19 deletions(-)

jump to
M src/platform/qt/CoreController.cppsrc/platform/qt/CoreController.cpp

@@ -1096,25 +1096,57 @@ }

#endif } +CoreController::Interrupter::Interrupter() + : m_parent(nullptr) +{ +} + CoreController::Interrupter::Interrupter(CoreController* parent) : m_parent(parent) { - if (!m_parent->thread()->impl) { - return; - } - if (mCoreThreadGet() != m_parent->thread()) { - mCoreThreadInterrupt(m_parent->thread()); - } else { - mCoreThreadInterruptFromThread(m_parent->thread()); - } + interrupt(); } CoreController::Interrupter::Interrupter(std::shared_ptr<CoreController> parent) : m_parent(parent.get()) { - if (!m_parent->thread()->impl) { + interrupt(); +} + +CoreController::Interrupter::Interrupter(const Interrupter& other) + : m_parent(other.m_parent) +{ + interrupt(); +} + +CoreController::Interrupter::~Interrupter() { + resume(); +} + +CoreController::Interrupter& CoreController::Interrupter::operator=(const Interrupter& other) +{ + interrupt(other.m_parent); + return *this; +} + +void CoreController::Interrupter::interrupt(CoreController* controller) { + if (m_parent != controller) { + CoreController* old = m_parent; + m_parent = controller; + interrupt(); + resume(old); + } +} + +void CoreController::Interrupter::interrupt(std::shared_ptr<CoreController> controller) { + interrupt(controller.get()); +} + +void CoreController::Interrupter::interrupt() { + if (!m_parent || !m_parent->thread()->impl) { return; } + if (mCoreThreadGet() != m_parent->thread()) { mCoreThreadInterrupt(m_parent->thread()); } else {

@@ -1122,18 +1154,15 @@ mCoreThreadInterruptFromThread(m_parent->thread());

} } -CoreController::Interrupter::Interrupter(const Interrupter& other) - : m_parent(other.m_parent) -{ - if (!m_parent->thread()->impl) { - return; - } - mCoreThreadInterrupt(m_parent->thread()); +void CoreController::Interrupter::resume() { + resume(m_parent); + m_parent = nullptr; } -CoreController::Interrupter::~Interrupter() { - if (!m_parent->thread()->impl) { +void CoreController::Interrupter::resume(CoreController* controller) { + if (!controller || !controller->thread()->impl) { return; } - mCoreThreadContinue(m_parent->thread()); + + mCoreThreadContinue(controller->thread()); }
M src/platform/qt/CoreController.hsrc/platform/qt/CoreController.h

@@ -53,12 +53,22 @@ };

class Interrupter { public: + Interrupter(); Interrupter(CoreController*); Interrupter(std::shared_ptr<CoreController>); Interrupter(const Interrupter&); ~Interrupter(); + Interrupter& operator=(const Interrupter&); + + void interrupt(CoreController*); + void interrupt(std::shared_ptr<CoreController>); + void resume(); + private: + void interrupt(); + void resume(CoreController*); + CoreController* m_parent; };