From 4353e39668d56e4e76ad2f388459f3d9b2ef1dd5 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 7 Feb 2021 22:46:15 -0800 Subject: [PATCH] Debugger: Prevent thread errors on mem alloc info. --- Core/Debugger/MemBlockInfo.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Core/Debugger/MemBlockInfo.cpp b/Core/Debugger/MemBlockInfo.cpp index 8ce39e0f9e75..3997a553fd23 100644 --- a/Core/Debugger/MemBlockInfo.cpp +++ b/Core/Debugger/MemBlockInfo.cpp @@ -15,6 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include #include "Common/Log.h" #include "Common/Serialize/Serializer.h" #include "Common/Serialize/SerializeFuncs.h" @@ -80,6 +81,7 @@ static MemSlabMap suballocMap; static MemSlabMap writeMap; static MemSlabMap textureMap; static std::vector pendingNotifies; +static std::mutex pendingMutex; MemSlabMap::MemSlabMap() { Reset(); @@ -322,6 +324,7 @@ void MemSlabMap::FillHeads(Slab *slab) { } void FlushPendingMemInfo() { + std::lock_guard guard(pendingMutex); for (auto info : pendingNotifies) { if (info.flags & MemBlockFlags::ALLOC) { allocMap.Mark(info.start, info.size, info.ticks, info.pc, true, info.tag); @@ -361,9 +364,15 @@ void NotifyMemInfoPC(MemBlockFlags flags, uint32_t start, uint32_t size, uint32_ info.ticks = CoreTiming::GetTicks(); info.pc = pc; info.tag = tag; - pendingNotifies.push_back(info); - if (pendingNotifies.size() > MAX_PENDING_NOTIFIES) { + bool needFlush = false; + { + std::lock_guard guard(pendingMutex); + pendingNotifies.push_back(info); + needFlush = pendingNotifies.size() > MAX_PENDING_NOTIFIES; + } + + if (needFlush) { FlushPendingMemInfo(); } @@ -403,10 +412,12 @@ std::vector FindMemInfoByFlag(MemBlockFlags flags, uint32_t start, } void MemBlockInfoInit() { + std::lock_guard guard(pendingMutex); pendingNotifies.reserve(MAX_PENDING_NOTIFIES); } void MemBlockInfoShutdown() { + std::lock_guard guard(pendingMutex); allocMap.Reset(); suballocMap.Reset(); writeMap.Reset();