diff options
| author | Matthew Parlane <parlane@gmail.com> | 2016-07-13 18:44:50 +1200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-13 18:44:50 +1200 |
| commit | 4d2df0a8cee1b11a3dca8f41edaafda69ee262dc (patch) | |
| tree | 3bad14a4c1d604149841e0903d5ef3ec00774fee /Source | |
| parent | cb63bacd65d1eabce58e913f0f188620fc6141f3 (diff) | |
| parent | b960b5677b2cb876e41368472e65790e1b818344 (diff) | |
Merge pull request #3989 from JosJuice/insert-sd-thread
Don't ScheduleEvent from wrong thread when inserting SD card
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp | 19 | ||||
| -rw-r--r-- | Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp | 2 |
2 files changed, 17 insertions, 4 deletions
diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp index faf2895799..776ecd1132 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp @@ -32,6 +32,7 @@ They will also generate a true or false return for UpdateInterrupts() in WII_IPC #include "Common/Thread.h" #include "Core/ConfigManager.h" +#include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/Debugger/Debugger_SymbolMap.h" #include "Core/HW/CPU.h" @@ -76,6 +77,7 @@ static ipc_msg_queue reply_queue; // arm -> ppc static ipc_msg_queue ack_queue; // arm -> ppc static int event_enqueue; +static int event_sdio_notify; static u64 last_reply_time; @@ -98,6 +100,14 @@ static void EnqueueEvent(u64 userdata, s64 cycles_late = 0) Update(); } +void SDIO_EventNotify_CPUThread(u64 userdata, s64 cycles_late) +{ + auto device = + static_cast<CWII_IPC_HLE_Device_sdio_slot0*>(GetDeviceByName("/dev/sdio/slot0").get()); + if (device) + device->EventNotify(); +} + static u32 num_devices; template <typename T> @@ -148,6 +158,7 @@ void Init() AddDevice<IWII_IPC_HLE_Device>("_Unimplemented_Device_"); event_enqueue = CoreTiming::RegisterEvent("IPCEvent", EnqueueEvent); + event_sdio_notify = CoreTiming::RegisterEvent("SDIO_EventNotify", SDIO_EventNotify_CPUThread); } void Reset(bool _bHard) @@ -212,10 +223,10 @@ void ES_DIVerify(const std::vector<u8>& tmd) void SDIO_EventNotify() { - auto pDevice = - static_cast<CWII_IPC_HLE_Device_sdio_slot0*>(GetDeviceByName("/dev/sdio/slot0").get()); - if (pDevice) - pDevice->EventNotify(); + // TODO: Potential race condition: If IsRunning() becomes false after + // it's checked, an event may be scheduled after CoreTiming shuts down. + if (SConfig::GetInstance().bWii && Core::IsRunning()) + CoreTiming::ScheduleEvent_Threadsafe(0, event_sdio_notify); } int getFreeDeviceId() diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp index 734f95e324..1f22d6c722 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp @@ -49,6 +49,8 @@ void CWII_IPC_HLE_Device_sdio_slot0::DoState(PointerWrap& p) void CWII_IPC_HLE_Device_sdio_slot0::EventNotify() { + // Accessing SConfig variables like this isn't really threadsafe, + // but this is how it's done all over the place... if ((SConfig::GetInstance().m_WiiSDCard && m_event.type == EVENT_INSERT) || (!SConfig::GetInstance().m_WiiSDCard && m_event.type == EVENT_REMOVE)) { |
