From c05cb75d6c889489543663101fa1285159900f1c Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 2 Apr 2026 10:21:38 -0500 Subject: [PATCH] HW/GBACore: Use mCoreSync to make runLoop exit sooner than what setting earlyExit does, particularly when not in GBA mode. --- Source/Core/Core/HW/GBACore.cpp | 22 ++++++++++++++++------ Source/Core/Core/HW/GBACore.h | 6 ++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/HW/GBACore.cpp b/Source/Core/Core/HW/GBACore.cpp index 10ec4f62d7..1c270281aa 100644 --- a/Source/Core/Core/HW/GBACore.cpp +++ b/Source/Core/Core/HW/GBACore.cpp @@ -163,11 +163,23 @@ Core::Core(::Core::System& system, int device_number) : m_device_number(device_number), m_system(system) { mLogSetDefaultLogger(&s_stub_logger); + + MutexInit(&m_core_sync.videoFrameMutex); + ConditionInit(&m_core_sync.videoFrameAvailableCond); + ConditionInit(&m_core_sync.videoFrameRequiredCond); + ConditionInit(&m_core_sync.audioRequiredCond); + MutexInit(&m_core_sync.audioBufferMutex); } Core::~Core() { Stop(); + + MutexDeinit(&m_core_sync.videoFrameMutex); + ConditionDeinit(&m_core_sync.videoFrameAvailableCond); + ConditionDeinit(&m_core_sync.videoFrameRequiredCond); + ConditionDeinit(&m_core_sync.audioRequiredCond); + MutexDeinit(&m_core_sync.audioBufferMutex); } bool Core::Start(u64 gc_ticks) @@ -258,6 +270,8 @@ bool Core::Start(u64 gc_ticks) AddCallbacks(); SetupEvent(); + m_core->setSync(m_core, &m_core_sync); + m_core->reset(m_core); m_started = true; start_guard.Dismiss(); @@ -498,12 +512,8 @@ void Core::SetupEvent() { m_event.context = this; m_event.name = "Dolphin Sync"; - m_event.callback = [](mTiming* timing, void* context, u32 cycles_late) { - Core* core = static_cast(context); - if (core->m_core->platform(core->m_core) == mPLATFORM_GBA) - static_cast<::GBA*>(core->m_core->board)->earlyExit = true; - else if (core->m_core->platform(core->m_core) == mPLATFORM_GB) - static_cast<::GB*>(core->m_core->board)->earlyExit = true; + m_event.callback = [](mTiming* /*timing*/, void* context, u32 /*cycles_late*/) { + auto* const core = static_cast(context); core->m_waiting_for_event = false; }; m_event.priority = 0x80; diff --git a/Source/Core/Core/HW/GBACore.h b/Source/Core/Core/HW/GBACore.h index 133b5e83b1..109416e1de 100644 --- a/Source/Core/Core/HW/GBACore.h +++ b/Source/Core/Core/HW/GBACore.h @@ -16,6 +16,11 @@ #include #undef PYCPARSE #include +#if !defined(_WIN32) +#define USE_PTHREADS // Required for Mutex/Condition in mCoreSync. +#endif +#include +#undef USE_PTHREADS #include #include "Common/CommonTypes.h" @@ -134,6 +139,7 @@ private: std::string m_game_title; mCore* m_core{}; + mCoreSync m_core_sync{}; mTimingEvent m_event{}; bool m_waiting_for_event = false; SIODriver m_sio_driver{};