Use read/write thread mx guard instead of general guard for HashMapHolder.
This commit is contained in:
@@ -2671,7 +2671,7 @@ bool ChatHandler::HandleResetAllCommand(const char * args)
|
|||||||
|
|
||||||
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'", atLogin, atLogin);
|
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'", atLogin, atLogin);
|
||||||
|
|
||||||
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, *HashMapHolder<Player>::GetLock(), true);
|
ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, guard, *HashMapHolder<Player>::GetLock(), true);
|
||||||
HashMapHolder<Player>::MapType const& plist = sObjectAccessor->GetPlayers();
|
HashMapHolder<Player>::MapType const& plist = sObjectAccessor->GetPlayers();
|
||||||
for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
|
for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
|
||||||
itr->second->SetAtLoginFlag(atLogin);
|
itr->second->SetAtLoginFlag(atLogin);
|
||||||
|
|||||||
@@ -165,9 +165,9 @@ Unit* ObjectAccessor::FindUnit(uint64 guid)
|
|||||||
|
|
||||||
Player* ObjectAccessor::FindPlayerByName(const char* name)
|
Player* ObjectAccessor::FindPlayerByName(const char* name)
|
||||||
{
|
{
|
||||||
ACE_GUARD_RETURN(LockType, g, *HashMapHolder<Player>::GetLock(), NULL);
|
ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, g, *HashMapHolder<Player>::GetLock(), NULL);
|
||||||
HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer();
|
HashMapHolder<Player>::MapType const& m = GetPlayers();
|
||||||
for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
|
for (HashMapHolder<Player>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||||
if (iter->second->IsInWorld() && strcmp(name, iter->second->GetName()) == 0)
|
if (iter->second->IsInWorld() && strcmp(name, iter->second->GetName()) == 0)
|
||||||
return iter->second;
|
return iter->second;
|
||||||
|
|
||||||
@@ -176,9 +176,9 @@ Player* ObjectAccessor::FindPlayerByName(const char* name)
|
|||||||
|
|
||||||
void ObjectAccessor::SaveAllPlayers()
|
void ObjectAccessor::SaveAllPlayers()
|
||||||
{
|
{
|
||||||
ACE_GUARD(LockType, g, *HashMapHolder<Player>::GetLock());
|
ACE_READ_GUARD(HashMapHolder<Player>::LockType, g, *HashMapHolder<Player>::GetLock());
|
||||||
HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer();
|
HashMapHolder<Player>::MapType const& m = GetPlayers();
|
||||||
for (HashMapHolder<Player>::MapType::iterator itr = m.begin(); itr != m.end(); ++itr)
|
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||||
itr->second->SaveToDB();
|
itr->second->SaveToDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +380,7 @@ void ObjectAccessor::UnloadAll()
|
|||||||
/// Define the static members of HashMapHolder
|
/// Define the static members of HashMapHolder
|
||||||
|
|
||||||
template <class T> UNORDERED_MAP< uint64, T* > HashMapHolder<T>::m_objectMap;
|
template <class T> UNORDERED_MAP< uint64, T* > HashMapHolder<T>::m_objectMap;
|
||||||
template <class T> ACE_Thread_Mutex HashMapHolder<T>::i_lock;
|
template <class T> typename HashMapHolder<T>::LockType HashMapHolder<T>::i_lock;
|
||||||
|
|
||||||
/// Global definitions for the hashmap storage
|
/// Global definitions for the hashmap storage
|
||||||
|
|
||||||
|
|||||||
@@ -48,23 +48,23 @@ class HashMapHolder
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
typedef UNORDERED_MAP<uint64, T*> MapType;
|
typedef UNORDERED_MAP<uint64, T*> MapType;
|
||||||
typedef ACE_Thread_Mutex LockType;
|
typedef ACE_RW_Thread_Mutex LockType;
|
||||||
|
|
||||||
static void Insert(T* o)
|
static void Insert(T* o)
|
||||||
{
|
{
|
||||||
ACE_GUARD(LockType, Guard, i_lock);
|
ACE_WRITE_GUARD(LockType, Guard, i_lock);
|
||||||
m_objectMap[o->GetGUID()] = o;
|
m_objectMap[o->GetGUID()] = o;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Remove(T* o)
|
static void Remove(T* o)
|
||||||
{
|
{
|
||||||
ACE_GUARD(LockType, Guard, i_lock);
|
ACE_WRITE_GUARD(LockType, Guard, i_lock);
|
||||||
m_objectMap.erase(o->GetGUID());
|
m_objectMap.erase(o->GetGUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
static T* Find(uint64 guid)
|
static T* Find(uint64 guid)
|
||||||
{
|
{
|
||||||
ACE_GUARD_RETURN(LockType, Guard, i_lock, NULL);
|
ACE_READ_GUARD_RETURN(LockType, Guard, i_lock, NULL);
|
||||||
typename MapType::iterator itr = m_objectMap.find(guid);
|
typename MapType::iterator itr = m_objectMap.find(guid);
|
||||||
return (itr != m_objectMap.end()) ? itr->second : NULL;
|
return (itr != m_objectMap.end()) ? itr->second : NULL;
|
||||||
}
|
}
|
||||||
@@ -198,22 +198,22 @@ class ObjectAccessor
|
|||||||
Player* FindPlayerByName(const char* name);
|
Player* FindPlayerByName(const char* name);
|
||||||
|
|
||||||
// when using this, you must use the hashmapholder's lock
|
// when using this, you must use the hashmapholder's lock
|
||||||
HashMapHolder<Player>::MapType& GetPlayers()
|
HashMapHolder<Player>::MapType const& GetPlayers() const
|
||||||
{
|
{
|
||||||
return HashMapHolder<Player>::GetContainer();
|
return HashMapHolder<Player>::GetContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// when using this, you must use the hashmapholder's lock
|
// when using this, you must use the hashmapholder's lock
|
||||||
HashMapHolder<Creature>::MapType& GetCreatures()
|
//HashMapHolder<Creature>::MapType& GetCreatures()
|
||||||
{
|
//{
|
||||||
return HashMapHolder<Creature>::GetContainer();
|
// return HashMapHolder<Creature>::GetContainer();
|
||||||
}
|
//}
|
||||||
|
|
||||||
// when using this, you must use the hashmapholder's lock
|
//// when using this, you must use the hashmapholder's lock
|
||||||
HashMapHolder<GameObject>::MapType& GetGameObjects()
|
//HashMapHolder<GameObject>::MapType& GetGameObjects()
|
||||||
{
|
//{
|
||||||
return HashMapHolder<GameObject>::GetContainer();
|
// return HashMapHolder<GameObject>::GetContainer();
|
||||||
}
|
//}
|
||||||
|
|
||||||
template<class T> void AddObject(T* object)
|
template<class T> void AddObject(T* object)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -239,8 +239,8 @@ void WorldSession::HandleWhoOpcode(WorldPacket & recv_data)
|
|||||||
data << uint32(matchcount); // placeholder, count of players matching criteria
|
data << uint32(matchcount); // placeholder, count of players matching criteria
|
||||||
data << uint32(displaycount); // placeholder, count of players displayed
|
data << uint32(displaycount); // placeholder, count of players displayed
|
||||||
|
|
||||||
ACE_GUARD(ACE_Thread_Mutex, g, *HashMapHolder<Player>::GetLock());
|
ACE_READ_GUARD(HashMapHolder<Player>::LockType, g, *HashMapHolder<Player>::GetLock());
|
||||||
HashMapHolder<Player>::MapType& m = sObjectAccessor->GetPlayers();
|
HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
|
||||||
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||||
{
|
{
|
||||||
if (AccountMgr::IsPlayerAccount(security))
|
if (AccountMgr::IsPlayerAccount(security))
|
||||||
|
|||||||
@@ -117,8 +117,8 @@ public:
|
|||||||
bool first = true;
|
bool first = true;
|
||||||
bool footer = false;
|
bool footer = false;
|
||||||
|
|
||||||
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, *HashMapHolder<Player>::GetLock(), true);
|
ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, guard, *HashMapHolder<Player>::GetLock(), true);
|
||||||
HashMapHolder<Player>::MapType& m = sObjectAccessor->GetPlayers();
|
HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
|
||||||
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||||
{
|
{
|
||||||
AccountTypes itrSec = itr->second->GetSession()->GetSecurity();
|
AccountTypes itrSec = itr->second->GetSession()->GetSecurity();
|
||||||
|
|||||||
Reference in New Issue
Block a user