Skip to content

Commit

Permalink
Debugger: Prevent thread errors on mem alloc info.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Feb 15, 2021
1 parent c52c955 commit 4353e39
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Core/Debugger/MemBlockInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mutex>
#include "Common/Log.h"
#include "Common/Serialize/Serializer.h"
#include "Common/Serialize/SerializeFuncs.h"
Expand Down Expand Up @@ -80,6 +81,7 @@ static MemSlabMap suballocMap;
static MemSlabMap writeMap;
static MemSlabMap textureMap;
static std::vector<PendingNotifyMem> pendingNotifies;
static std::mutex pendingMutex;

MemSlabMap::MemSlabMap() {
Reset();
Expand Down Expand Up @@ -322,6 +324,7 @@ void MemSlabMap::FillHeads(Slab *slab) {
}

void FlushPendingMemInfo() {
std::lock_guard<std::mutex> guard(pendingMutex);
for (auto info : pendingNotifies) {
if (info.flags & MemBlockFlags::ALLOC) {
allocMap.Mark(info.start, info.size, info.ticks, info.pc, true, info.tag);
Expand Down Expand Up @@ -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<std::mutex> guard(pendingMutex);
pendingNotifies.push_back(info);
needFlush = pendingNotifies.size() > MAX_PENDING_NOTIFIES;
}

if (needFlush) {
FlushPendingMemInfo();
}

Expand Down Expand Up @@ -403,10 +412,12 @@ std::vector<MemBlockInfo> FindMemInfoByFlag(MemBlockFlags flags, uint32_t start,
}

void MemBlockInfoInit() {
std::lock_guard<std::mutex> guard(pendingMutex);
pendingNotifies.reserve(MAX_PENDING_NOTIFIES);
}

void MemBlockInfoShutdown() {
std::lock_guard<std::mutex> guard(pendingMutex);
allocMap.Reset();
suballocMap.Reset();
writeMap.Reset();
Expand Down

0 comments on commit 4353e39

Please sign in to comment.