More robust checks on mutex acquire.

- When using ACE_xxx_Guard, the caller must ensure the internal lock is really acquired before entering the critical section
(see http://www.dre.vanderbilt.edu/Doxygen/6.0.1/html/libace-doc/a00186.html#_details - Warnings paragraph)
This commit is contained in:
H0zen 2016-03-04 14:30:48 +02:00
parent fc72b48f84
commit dbc21ed903
2 changed files with 75 additions and 57 deletions

View File

@ -93,12 +93,14 @@ Player* ObjectAccessor::FindPlayer(ObjectGuid guid, bool inWorld /*= true*/)
Player* ObjectAccessor::FindPlayerByName(const char* name)
{
HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock());
HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock(), true);
if (g.locked())
{
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
if (iter->second->IsInWorld() && (::strcmp(name, iter->second->GetName()) == 0))
{ return iter->second; }
}
return NULL;
}
@ -129,23 +131,26 @@ void ObjectAccessor::KickPlayer(ObjectGuid guid)
Corpse*
ObjectAccessor::GetCorpseForPlayerGUID(ObjectGuid guid)
{
Guard guard(i_corpseGuard);
ACE_Guard<LockType> guard(i_corpseGuard, true);
if (guard.locked())
{
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
if (iter == i_player2corpse.end())
{ return NULL; }
MANGOS_ASSERT(iter->second->GetType() != CORPSE_BONES);
return iter->second;
}
return NULL;
}
void
ObjectAccessor::RemoveCorpse(Corpse* corpse)
{
MANGOS_ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
Guard guard(i_corpseGuard);
ACE_Guard<LockType> guard(i_corpseGuard, true);
if (guard.locked())
{
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGuid());
if (iter == i_player2corpse.end())
{ return; }
@ -159,13 +164,16 @@ ObjectAccessor::RemoveCorpse(Corpse* corpse)
i_player2corpse.erase(iter);
}
}
void
ObjectAccessor::AddCorpse(Corpse* corpse)
{
MANGOS_ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
Guard guard(i_corpseGuard);
ACE_Guard<LockType> guard(i_corpseGuard, true);
if (guard.locked())
{
MANGOS_ASSERT(i_player2corpse.find(corpse->GetOwnerGuid()) == i_player2corpse.end());
i_player2corpse[corpse->GetOwnerGuid()] = corpse;
@ -175,11 +183,14 @@ ObjectAccessor::AddCorpse(Corpse* corpse)
sObjectMgr.AddCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter(), corpse->GetInstanceId());
}
}
void
ObjectAccessor::AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map* map)
{
Guard guard(i_corpseGuard);
ACE_Guard<LockType> guard(i_corpseGuard, true);
if (guard.locked())
{
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
if (iter->second->GetGrid() == gridpair)
{
@ -197,6 +208,7 @@ ObjectAccessor::AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map*
}
}
}
}
Corpse*
ObjectAccessor::ConvertCorpseForPlayer(ObjectGuid player_guid, bool insignia)

View File

@ -59,22 +59,29 @@ class HashMapHolder
static void Insert(T* o)
{
WriteGuard guard(i_lock);
WriteGuard guard(i_lock, true);
if (guard.locked())
m_objectMap[o->GetObjectGuid()] = o;
}
static void Remove(T* o)
{
WriteGuard guard(i_lock);
WriteGuard guard(i_lock, true);
if (guard.locked())
m_objectMap.erase(o->GetObjectGuid());
}
static T* Find(ObjectGuid guid)
{
ReadGuard guard(i_lock);
ReadGuard guard(i_lock, true);
if (guard.locked())
{
typename MapType::iterator itr = m_objectMap.find(guid);
return (itr != m_objectMap.end()) ? itr->second : NULL;
}
else
return NULL;
}
static MapType& GetContainer() { return m_objectMap; }
@ -137,7 +144,6 @@ class ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor, MaNGOS::ClassLev
Player2CorpsesMapType i_player2corpse;
typedef ACE_Thread_Mutex LockType;
typedef MaNGOS::GeneralLock<LockType > Guard;
LockType i_playerGuard;
LockType i_corpseGuard;