Use read/write thread mx guard instead of general guard for HashMapHolder.

This commit is contained in:
megamage
2011-10-21 17:29:09 -04:00
parent 5fdde0da73
commit c9c5c2a355
5 changed files with 26 additions and 26 deletions
+14 -14
View File
@@ -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)
{