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:
parent
fc72b48f84
commit
dbc21ed903
@ -93,12 +93,14 @@ Player* ObjectAccessor::FindPlayer(ObjectGuid guid, bool inWorld /*= true*/)
|
|||||||
|
|
||||||
Player* ObjectAccessor::FindPlayerByName(const char* name)
|
Player* ObjectAccessor::FindPlayerByName(const char* name)
|
||||||
{
|
{
|
||||||
HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock());
|
HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock(), true);
|
||||||
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
|
if (g.locked())
|
||||||
for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
|
{
|
||||||
if (iter->second->IsInWorld() && (::strcmp(name, iter->second->GetName()) == 0))
|
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
|
||||||
{ return iter->second; }
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,15 +131,16 @@ void ObjectAccessor::KickPlayer(ObjectGuid guid)
|
|||||||
Corpse*
|
Corpse*
|
||||||
ObjectAccessor::GetCorpseForPlayerGUID(ObjectGuid guid)
|
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())
|
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
|
||||||
{ return NULL; }
|
if (iter == i_player2corpse.end())
|
||||||
|
{ return NULL; }
|
||||||
MANGOS_ASSERT(iter->second->GetType() != CORPSE_BONES);
|
MANGOS_ASSERT(iter->second->GetType() != CORPSE_BONES);
|
||||||
|
return iter->second;
|
||||||
return iter->second;
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -145,19 +148,22 @@ ObjectAccessor::RemoveCorpse(Corpse* corpse)
|
|||||||
{
|
{
|
||||||
MANGOS_ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
|
MANGOS_ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
|
||||||
|
|
||||||
Guard guard(i_corpseGuard);
|
ACE_Guard<LockType> guard(i_corpseGuard, true);
|
||||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGuid());
|
if (guard.locked())
|
||||||
if (iter == i_player2corpse.end())
|
{
|
||||||
{ return; }
|
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGuid());
|
||||||
|
if (iter == i_player2corpse.end())
|
||||||
|
{ return; }
|
||||||
|
|
||||||
// build mapid*cellid -> guid_set map
|
// build mapid*cellid -> guid_set map
|
||||||
CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY());
|
CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY());
|
||||||
uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord;
|
uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord;
|
||||||
|
|
||||||
sObjectMgr.DeleteCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter());
|
sObjectMgr.DeleteCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter());
|
||||||
corpse->RemoveFromWorld();
|
corpse->RemoveFromWorld();
|
||||||
|
|
||||||
i_player2corpse.erase(iter);
|
i_player2corpse.erase(iter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -165,37 +171,43 @@ ObjectAccessor::AddCorpse(Corpse* corpse)
|
|||||||
{
|
{
|
||||||
MANGOS_ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
|
MANGOS_ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
|
||||||
|
|
||||||
Guard guard(i_corpseGuard);
|
ACE_Guard<LockType> guard(i_corpseGuard, true);
|
||||||
MANGOS_ASSERT(i_player2corpse.find(corpse->GetOwnerGuid()) == i_player2corpse.end());
|
if (guard.locked())
|
||||||
i_player2corpse[corpse->GetOwnerGuid()] = corpse;
|
{
|
||||||
|
MANGOS_ASSERT(i_player2corpse.find(corpse->GetOwnerGuid()) == i_player2corpse.end());
|
||||||
|
i_player2corpse[corpse->GetOwnerGuid()] = corpse;
|
||||||
|
|
||||||
// build mapid*cellid -> guid_set map
|
// build mapid*cellid -> guid_set map
|
||||||
CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY());
|
CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY());
|
||||||
uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord;
|
uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord;
|
||||||
|
|
||||||
sObjectMgr.AddCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter(), corpse->GetInstanceId());
|
sObjectMgr.AddCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter(), corpse->GetInstanceId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ObjectAccessor::AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map* map)
|
ObjectAccessor::AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map* map)
|
||||||
{
|
{
|
||||||
Guard guard(i_corpseGuard);
|
ACE_Guard<LockType> guard(i_corpseGuard, true);
|
||||||
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
|
if (guard.locked())
|
||||||
if (iter->second->GetGrid() == gridpair)
|
{
|
||||||
{
|
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
|
||||||
// verify, if the corpse in our instance (add only corpses which are)
|
if (iter->second->GetGrid() == gridpair)
|
||||||
if (map->Instanceable())
|
{
|
||||||
{
|
// verify, if the corpse in our instance (add only corpses which are)
|
||||||
if (iter->second->GetInstanceId() == map->GetInstanceId())
|
if (map->Instanceable())
|
||||||
{
|
{
|
||||||
grid.AddWorldObject(iter->second);
|
if (iter->second->GetInstanceId() == map->GetInstanceId())
|
||||||
}
|
{
|
||||||
}
|
grid.AddWorldObject(iter->second);
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
grid.AddWorldObject(iter->second);
|
else
|
||||||
}
|
{
|
||||||
}
|
grid.AddWorldObject(iter->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Corpse*
|
Corpse*
|
||||||
|
@ -59,21 +59,28 @@ class HashMapHolder
|
|||||||
|
|
||||||
static void Insert(T* o)
|
static void Insert(T* o)
|
||||||
{
|
{
|
||||||
WriteGuard guard(i_lock);
|
WriteGuard guard(i_lock, true);
|
||||||
m_objectMap[o->GetObjectGuid()] = o;
|
if (guard.locked())
|
||||||
|
m_objectMap[o->GetObjectGuid()] = o;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Remove(T* o)
|
static void Remove(T* o)
|
||||||
{
|
{
|
||||||
WriteGuard guard(i_lock);
|
WriteGuard guard(i_lock, true);
|
||||||
m_objectMap.erase(o->GetObjectGuid());
|
if (guard.locked())
|
||||||
|
m_objectMap.erase(o->GetObjectGuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
static T* Find(ObjectGuid guid)
|
static T* Find(ObjectGuid guid)
|
||||||
{
|
{
|
||||||
ReadGuard guard(i_lock);
|
ReadGuard guard(i_lock, true);
|
||||||
typename MapType::iterator itr = m_objectMap.find(guid);
|
if (guard.locked())
|
||||||
return (itr != m_objectMap.end()) ? itr->second : NULL;
|
{
|
||||||
|
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; }
|
static MapType& GetContainer() { return m_objectMap; }
|
||||||
@ -137,7 +144,6 @@ class ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor, MaNGOS::ClassLev
|
|||||||
Player2CorpsesMapType i_player2corpse;
|
Player2CorpsesMapType i_player2corpse;
|
||||||
|
|
||||||
typedef ACE_Thread_Mutex LockType;
|
typedef ACE_Thread_Mutex LockType;
|
||||||
typedef MaNGOS::GeneralLock<LockType > Guard;
|
|
||||||
|
|
||||||
LockType i_playerGuard;
|
LockType i_playerGuard;
|
||||||
LockType i_corpseGuard;
|
LockType i_corpseGuard;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user