mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Texts: Fix race conditions in CreatureTextMgr repeat group
Fix race conditions in CreatureTextMgr repeat group happening with MapThreads > 1 reported by helgrind by moving Creature-GUID-base data from CreatureTextMgr to Creature.
Issues added in bbf86641a1
This commit is contained in:
@@ -2635,3 +2635,29 @@ void Creature::StartPickPocketRefillTimer()
|
||||
_pickpocketLootRestore = time(NULL) + sWorld->getIntConfig(CONFIG_CREATURE_PICKPOCKET_REFILL);
|
||||
}
|
||||
|
||||
void Creature::SetTextRepeatId(uint8 textGroup, uint8 id)
|
||||
{
|
||||
CreatureTextRepeatIds& repeats = m_textRepeat[textGroup];
|
||||
if (std::find(repeats.begin(), repeats.end(), id) == repeats.end())
|
||||
repeats.push_back(id);
|
||||
else
|
||||
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: TextGroup %u for Creature(%s) GuidLow %u Entry %u, id %u already added", uint32(textGroup), GetName().c_str(), GetGUIDLow(), GetEntry(), uint32(id));
|
||||
}
|
||||
|
||||
CreatureTextRepeatIds Creature::GetTextRepeatGroup(uint8 textGroup)
|
||||
{
|
||||
CreatureTextRepeatIds ids;
|
||||
|
||||
CreatureTextRepeatGroup::const_iterator groupItr = m_textRepeat.find(textGroup);
|
||||
if (groupItr != m_textRepeat.end())
|
||||
ids = groupItr->second;
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
void Creature::ClearTextRepeatGroup(uint8 textGroup)
|
||||
{
|
||||
CreatureTextRepeatGroup::iterator groupItr = m_textRepeat.find(textGroup);
|
||||
if (groupItr != m_textRepeat.end())
|
||||
groupItr->second.clear();
|
||||
}
|
||||
|
||||
@@ -409,6 +409,10 @@ struct TrainerSpellData
|
||||
|
||||
#define MAX_VENDOR_ITEMS 150 // Limitation in 3.x.x item count in SMSG_LIST_INVENTORY
|
||||
|
||||
//used for handling non-repeatable random texts
|
||||
typedef std::vector<uint8> CreatureTextRepeatIds;
|
||||
typedef std::unordered_map<uint8, CreatureTextRepeatIds> CreatureTextRepeatGroup;
|
||||
|
||||
class Creature : public Unit, public GridObject<Creature>, public MapObject
|
||||
{
|
||||
public:
|
||||
@@ -656,6 +660,10 @@ class Creature : public Unit, public GridObject<Creature>, public MapObject
|
||||
void FocusTarget(Spell const* focusSpell, WorldObject const* target);
|
||||
void ReleaseFocus(Spell const* focusSpell);
|
||||
|
||||
CreatureTextRepeatIds GetTextRepeatGroup(uint8 textGroup);
|
||||
void SetTextRepeatId(uint8 textGroup, uint8 id);
|
||||
void ClearTextRepeatGroup(uint8 textGroup);
|
||||
|
||||
protected:
|
||||
bool CreateFromProto(uint32 guidlow, uint32 entry, CreatureData const* data = nullptr, uint32 vehId = 0);
|
||||
bool InitEntry(uint32 entry, CreatureData const* data = nullptr);
|
||||
@@ -720,6 +728,8 @@ class Creature : public Unit, public GridObject<Creature>, public MapObject
|
||||
bool TriggerJustRespawned;
|
||||
|
||||
Spell const* _focusSpell; ///> Locks the target during spell cast for proper facing
|
||||
|
||||
CreatureTextRepeatGroup m_textRepeat;
|
||||
};
|
||||
|
||||
class AssistDelayEvent : public BasicEvent
|
||||
|
||||
@@ -77,7 +77,7 @@ void CreatureTextMgr::LoadCreatureTexts()
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
mTextMap.clear(); // for reload case
|
||||
mTextRepeatMap.clear(); //reset all currently used temp texts
|
||||
//all currently used temp texts are NOT reset
|
||||
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_TEXT);
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
@@ -224,13 +224,7 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject
|
||||
|
||||
if (tempGroup.empty())
|
||||
{
|
||||
CreatureTextRepeatMap::iterator mapItr = mTextRepeatMap.find(source->GetGUID());
|
||||
if (mapItr != mTextRepeatMap.end())
|
||||
{
|
||||
CreatureTextRepeatGroup::iterator groupItr = mapItr->second.find(textGroup);
|
||||
groupItr->second.clear();
|
||||
}
|
||||
|
||||
source->ClearTextRepeatGroup(textGroup);
|
||||
tempGroup = textGroupContainer;
|
||||
}
|
||||
|
||||
@@ -426,26 +420,14 @@ void CreatureTextMgr::SetRepeatId(Creature* source, uint8 textGroup, uint8 id)
|
||||
if (!source)
|
||||
return;
|
||||
|
||||
CreatureTextRepeatIds& repeats = mTextRepeatMap[source->GetGUID()][textGroup];
|
||||
if (std::find(repeats.begin(), repeats.end(), id) == repeats.end())
|
||||
repeats.push_back(id);
|
||||
else
|
||||
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: TextGroup %u for Creature(%s) GuidLow %u Entry %u, id %u already added", uint32(textGroup), source->GetName().c_str(), source->GetGUIDLow(), source->GetEntry(), uint32(id));
|
||||
source->SetTextRepeatId(textGroup, id);
|
||||
}
|
||||
|
||||
CreatureTextRepeatIds CreatureTextMgr::GetRepeatGroup(Creature* source, uint8 textGroup)
|
||||
{
|
||||
ASSERT(source);//should never happen
|
||||
CreatureTextRepeatIds ids;
|
||||
|
||||
CreatureTextRepeatMap::const_iterator mapItr = mTextRepeatMap.find(source->GetGUID());
|
||||
if (mapItr != mTextRepeatMap.end())
|
||||
{
|
||||
CreatureTextRepeatGroup::const_iterator groupItr = (*mapItr).second.find(textGroup);
|
||||
if (groupItr != mapItr->second.end())
|
||||
ids = groupItr->second;
|
||||
}
|
||||
return ids;
|
||||
return source->GetTextRepeatGroup(textGroup);
|
||||
}
|
||||
|
||||
bool CreatureTextMgr::TextExist(uint32 sourceEntry, uint8 textGroup)
|
||||
|
||||
@@ -75,11 +75,6 @@ typedef std::unordered_map<uint32, CreatureTextHolder> CreatureTextMap; // a
|
||||
|
||||
typedef std::map<CreatureTextId, CreatureTextLocale> LocaleCreatureTextMap;
|
||||
|
||||
//used for handling non-repeatable random texts
|
||||
typedef std::vector<uint8> CreatureTextRepeatIds;
|
||||
typedef std::unordered_map<uint8, CreatureTextRepeatIds> CreatureTextRepeatGroup;
|
||||
typedef std::unordered_map<ObjectGuid, CreatureTextRepeatGroup> CreatureTextRepeatMap;//guid based
|
||||
|
||||
class CreatureTextMgr
|
||||
{
|
||||
private:
|
||||
@@ -115,7 +110,6 @@ class CreatureTextMgr
|
||||
float GetRangeForChatType(ChatMsg msgType) const;
|
||||
|
||||
CreatureTextMap mTextMap;
|
||||
CreatureTextRepeatMap mTextRepeatMap;
|
||||
LocaleCreatureTextMap mLocaleTextMap;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user