Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't ScheduleEvent from wrong thread when inserting SD card #3989

Merged
merged 1 commit into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand All @@ -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());

This comment was marked as off-topic.

This comment was marked as off-topic.

if (device)
device->EventNotify();
}

static u32 num_devices;

template <typename T>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down