Fix some potential threading probs with SymbolMap.

Got some strange crashes.
This commit is contained in:
Unknown W. Brackets 2013-08-10 20:54:55 -07:00
parent e0f699fd5f
commit 8786ec74ca
2 changed files with 18 additions and 4 deletions

View File

@ -52,6 +52,7 @@ static u32 ComputeHash(u32 start, u32 size)
void SymbolMap::SortSymbols()
{
lock_guard guard(lock_);
std::sort(entries.begin(), entries.end());
}
@ -104,6 +105,7 @@ void SymbolMap::AnalyzeBackwards()
void SymbolMap::ResetSymbolMap()
{
lock_guard guard(lock_);
#ifdef BWLINKS
for (int i=0; i<numEntries; i++)
{
@ -118,6 +120,7 @@ void SymbolMap::ResetSymbolMap()
void SymbolMap::AddSymbol(const char *symbolname, unsigned int vaddress, size_t size, SymbolType st)
{
lock_guard guard(lock_);
MapEntry e;
strncpy(e.name, symbolname, 127);
e.name[127] = '\0';
@ -134,6 +137,7 @@ void SymbolMap::AddSymbol(const char *symbolname, unsigned int vaddress, size_t
bool SymbolMap::LoadSymbolMap(const char *filename)
{
lock_guard guard(lock_);
SymbolMap::ResetSymbolMap();
FILE *f = fopen(filename,"r");
if (!f)
@ -207,6 +211,7 @@ bool SymbolMap::LoadSymbolMap(const char *filename)
void SymbolMap::SaveSymbolMap(const char *filename) const
{
lock_guard guard(lock_);
FILE *f = fopen(filename,"w");
if (!f)
return;
@ -221,6 +226,7 @@ void SymbolMap::SaveSymbolMap(const char *filename) const
bool SymbolMap::LoadNocashSym(const char *filename)
{
lock_guard guard(lock_);
FILE *f = fopen(filename,"r");
if (!f)
return false;
@ -389,6 +395,8 @@ void SymbolMap::FillSymbolListBox(HWND listbox,SymbolType symmask) const
}
}
lock_guard guard(lock_);
SendMessage(listbox, WM_SETREDRAW, FALSE, 0);
SendMessage(listbox, LB_INITSTORAGE, (WPARAM)entries.size(), (LPARAM)entries.size() * 30);
for (auto it = entries.begin(), end = entries.end(); it != end; ++it)
@ -427,11 +435,13 @@ void SymbolMap::FillSymbolComboBox(HWND listbox,SymbolType symmask) const
//ListBox_AddString(listbox,"(0x80002000)");
//ListBox_SetItemData(listbox,1,0x80002000);
lock_guard guard(lock_);
SendMessage(listbox, WM_SETREDRAW, FALSE, 0);
SendMessage(listbox, CB_INITSTORAGE, (WPARAM)entries.size(), (LPARAM)entries.size() * 30);
for (auto it = entries.begin(), end = entries.end(); it != end; ++it)
for (size_t i = 0, end = entries.size(); i < end; ++i)
{
const MapEntry &entry = *it;
const MapEntry &entry = entries[i];
if (entry.type & symmask)
{
char temp[256];
@ -450,6 +460,8 @@ void SymbolMap::FillListBoxBLinks(HWND listbox, int num) const
{
ListBox_ResetContent(listbox);
lock_guard guard(lock_);
int style = GetWindowLong(listbox,GWL_STYLE);
const MapEntry &e = entries[num];

View File

@ -17,7 +17,8 @@
#pragma once
#include "../../Globals.h"
#include "Globals.h"
#include "native/base/mutex.h"
#include <vector>
#include <set>
#include <map>
@ -106,6 +107,7 @@ private:
std::set<MapEntryUniqueInfo> uniqueEntries;
std::vector<MapEntry> entries;
std::map<u32, u32> entryRanges;
mutable recursive_mutex lock_;
};
extern SymbolMap symbolMap;