Debugger: Reduce meminfo block check hazard.

If a debugger (i.e. the memory view) checks for memory block info while a
save state is being loaded, it can crash.  This was already rare, but this
change makes it significantly rarer.

Of course, it's still possible without a mutex, but I'm wanting to avoid
slowing down the lookups as they are used at runtime within emulation.
This commit is contained in:
Unknown W. Brackets
2021-12-04 14:51:02 -08:00
parent e2425a1e00
commit 9155cd7491
+10 -2
View File
@@ -162,7 +162,9 @@ void MemSlabMap::DoState(PointerWrap &p) {
int count = 0;
if (p.mode == p.MODE_READ) {
Clear();
// Since heads_ is a static size, let's avoid clearing it.
// This helps in case a debugger call happens concurrently.
Slab *old = first_;
Do(p, count);
first_ = new Slab();
@@ -170,7 +172,6 @@ void MemSlabMap::DoState(PointerWrap &p) {
lastFind_ = first_;
--count;
heads_.resize(SLICES, nullptr);
FillHeads(first_);
Slab *slab = first_;
@@ -183,6 +184,13 @@ void MemSlabMap::DoState(PointerWrap &p) {
FillHeads(slab);
}
// Now that it's entirely disconnected, delete the old slabs.
while (old != nullptr) {
Slab *next = old->next;
delete old;
old = next;
}
} else {
for (Slab *slab = first_; slab != nullptr; slab = slab->next)
++count;