Skip to content

Commit

Permalink
Thread safe enq_reply.
Browse files Browse the repository at this point in the history
  • Loading branch information
Parlane committed Jan 1, 2013
1 parent d3f1992 commit 8fdc8af
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp
Expand Up @@ -83,6 +83,7 @@ IWII_IPC_HLE_Device* es_handles[ES_MAX_COUNT];
typedef std::deque<u32> ipc_msg_queue;
static ipc_msg_queue request_queue; // ppc -> arm
static ipc_msg_queue reply_queue; // arm -> ppc
static std::mutex s_reply_queue;

void Init()
{
Expand Down Expand Up @@ -159,7 +160,12 @@ void Reset(bool _bHard)
g_DeviceMap.erase(g_DeviceMap.begin(), g_DeviceMap.end());
}
request_queue.clear();
reply_queue.clear();

// lock due to using reply_queue
{
std::lock_guard<std::mutex> lk(s_reply_queue);
reply_queue.clear();
}
}

void Shutdown()
Expand Down Expand Up @@ -241,6 +247,8 @@ IWII_IPC_HLE_Device* CreateFileIO(u32 _DeviceID, const std::string& _rDeviceName

void DoState(PointerWrap &p)
{
std::lock_guard<std::mutex> lk(s_reply_queue);

p.Do(request_queue);
p.Do(reply_queue);

Expand Down Expand Up @@ -536,6 +544,7 @@ void EnqRequest(u32 _Address)
// Called when IOS module has some reply
void EnqReply(u32 _Address)
{
std::lock_guard<std::mutex> lk(s_reply_queue);
reply_queue.push_back(_Address);
}

Expand All @@ -560,12 +569,16 @@ void Update()
Dolphin_Debugger::PrintCallstack(LogTypes::WII_IPC_HLE, LogTypes::LDEBUG);
#endif
}

if (reply_queue.size())
// lock due to using reply_queue
{
WII_IPCInterface::GenerateReply(reply_queue.front());
INFO_LOG(WII_IPC_HLE, "<<-- Reply to IPC Request @ 0x%08x", reply_queue.front());
reply_queue.pop_front();
std::lock_guard<std::mutex> lk(s_reply_queue);
if (reply_queue.size())
{
WII_IPCInterface::GenerateReply(reply_queue.front());
INFO_LOG(WII_IPC_HLE, "<<-- Reply to IPC Request @ 0x%08x", reply_queue.front());
reply_queue.pop_front();
}
}
}

Expand Down

0 comments on commit 8fdc8af

Please sign in to comment.