Use read/write thread mx guard instead of general guard for HashMapHolder.
This commit is contained in:
@@ -165,9 +165,9 @@ Unit* ObjectAccessor::FindUnit(uint64 guid)
|
||||
|
||||
Player* ObjectAccessor::FindPlayerByName(const char* name)
|
||||
{
|
||||
ACE_GUARD_RETURN(LockType, g, *HashMapHolder<Player>::GetLock(), NULL);
|
||||
HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer();
|
||||
for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, g, *HashMapHolder<Player>::GetLock(), NULL);
|
||||
HashMapHolder<Player>::MapType const& m = GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
if (iter->second->IsInWorld() && strcmp(name, iter->second->GetName()) == 0)
|
||||
return iter->second;
|
||||
|
||||
@@ -176,9 +176,9 @@ Player* ObjectAccessor::FindPlayerByName(const char* name)
|
||||
|
||||
void ObjectAccessor::SaveAllPlayers()
|
||||
{
|
||||
ACE_GUARD(LockType, g, *HashMapHolder<Player>::GetLock());
|
||||
HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer();
|
||||
for (HashMapHolder<Player>::MapType::iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
ACE_READ_GUARD(HashMapHolder<Player>::LockType, g, *HashMapHolder<Player>::GetLock());
|
||||
HashMapHolder<Player>::MapType const& m = GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
itr->second->SaveToDB();
|
||||
}
|
||||
|
||||
@@ -380,7 +380,7 @@ void ObjectAccessor::UnloadAll()
|
||||
/// Define the static members of HashMapHolder
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -48,23 +48,23 @@ class HashMapHolder
|
||||
public:
|
||||
|
||||
typedef UNORDERED_MAP<uint64, T*> MapType;
|
||||
typedef ACE_Thread_Mutex LockType;
|
||||
typedef ACE_RW_Thread_Mutex LockType;
|
||||
|
||||
static void Insert(T* o)
|
||||
{
|
||||
ACE_GUARD(LockType, Guard, i_lock);
|
||||
ACE_WRITE_GUARD(LockType, Guard, i_lock);
|
||||
m_objectMap[o->GetGUID()] = o;
|
||||
}
|
||||
|
||||
static void Remove(T* o)
|
||||
{
|
||||
ACE_GUARD(LockType, Guard, i_lock);
|
||||
ACE_WRITE_GUARD(LockType, Guard, i_lock);
|
||||
m_objectMap.erase(o->GetGUID());
|
||||
}
|
||||
|
||||
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);
|
||||
return (itr != m_objectMap.end()) ? itr->second : NULL;
|
||||
}
|
||||
@@ -198,22 +198,22 @@ class ObjectAccessor
|
||||
Player* FindPlayerByName(const char* name);
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
HashMapHolder<Player>::MapType& GetPlayers()
|
||||
HashMapHolder<Player>::MapType const& GetPlayers() const
|
||||
{
|
||||
return HashMapHolder<Player>::GetContainer();
|
||||
}
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
HashMapHolder<Creature>::MapType& GetCreatures()
|
||||
{
|
||||
return HashMapHolder<Creature>::GetContainer();
|
||||
}
|
||||
//HashMapHolder<Creature>::MapType& GetCreatures()
|
||||
//{
|
||||
// return HashMapHolder<Creature>::GetContainer();
|
||||
//}
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
HashMapHolder<GameObject>::MapType& GetGameObjects()
|
||||
{
|
||||
return HashMapHolder<GameObject>::GetContainer();
|
||||
}
|
||||
//// when using this, you must use the hashmapholder's lock
|
||||
//HashMapHolder<GameObject>::MapType& GetGameObjects()
|
||||
//{
|
||||
// return HashMapHolder<GameObject>::GetContainer();
|
||||
//}
|
||||
|
||||
template<class T> void AddObject(T* object)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user