From 8fdc8af1cb83381228c04c60021eb9d2abe30761 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Tue, 1 Jan 2013 19:24:00 +1300 Subject: [PATCH] Thread safe enq_reply. --- Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp | 25 +++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp index 9a47e97d0c..fc2118ea20 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp @@ -83,6 +83,7 @@ IWII_IPC_HLE_Device* es_handles[ES_MAX_COUNT]; typedef std::deque 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() { @@ -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 lk(s_reply_queue); + reply_queue.clear(); + } } void Shutdown() @@ -241,6 +247,8 @@ IWII_IPC_HLE_Device* CreateFileIO(u32 _DeviceID, const std::string& _rDeviceName void DoState(PointerWrap &p) { + std::lock_guard lk(s_reply_queue); + p.Do(request_queue); p.Do(reply_queue); @@ -536,6 +544,7 @@ void EnqRequest(u32 _Address) // Called when IOS module has some reply void EnqReply(u32 _Address) { + std::lock_guard lk(s_reply_queue); reply_queue.push_back(_Address); } @@ -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 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(); + } } }