diff --git a/src/game/Level0.cpp b/src/game/Level0.cpp index d0a4effd1..d95043931 100644 --- a/src/game/Level0.cpp +++ b/src/game/Level0.cpp @@ -153,21 +153,23 @@ bool ChatHandler::HandleGMListIngameCommand(const char* /*args*/) { bool first = true; - HashMapHolder::MapType &m = HashMapHolder::GetContainer(); - HashMapHolder::MapType::const_iterator itr = m.begin(); - for(; itr != m.end(); ++itr) { - AccountTypes itr_sec = itr->second->GetSession()->GetSecurity(); - if ((itr->second->isGameMaster() || (itr_sec > SEC_PLAYER && itr_sec <= (AccountTypes)sWorld.getConfig(CONFIG_UINT32_GM_LEVEL_IN_GM_LIST))) && - (!m_session || itr->second->IsVisibleGloballyFor(m_session->GetPlayer()))) + HashMapHolder::ReadGuard g(HashMapHolder::GetLock()); + HashMapHolder::MapType &m = sObjectAccessor.GetPlayers(); + for(HashMapHolder::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) { - if(first) + AccountTypes itr_sec = itr->second->GetSession()->GetSecurity(); + if ((itr->second->isGameMaster() || (itr_sec > SEC_PLAYER && itr_sec <= (AccountTypes)sWorld.getConfig(CONFIG_UINT32_GM_LEVEL_IN_GM_LIST))) && + (!m_session || itr->second->IsVisibleGloballyFor(m_session->GetPlayer()))) { - SendSysMessage(LANG_GMS_ON_SRV); - first = false; - } + if(first) + { + SendSysMessage(LANG_GMS_ON_SRV); + first = false; + } - SendSysMessage(GetNameLink(itr->second).c_str()); + SendSysMessage(GetNameLink(itr->second).c_str()); + } } } diff --git a/src/game/ObjectAccessor.cpp b/src/game/ObjectAccessor.cpp index 53e4d828e..6b12b85d6 100644 --- a/src/game/ObjectAccessor.cpp +++ b/src/game/ObjectAccessor.cpp @@ -92,22 +92,21 @@ ObjectAccessor::FindPlayer(ObjectGuid guid) Player* ObjectAccessor::FindPlayerByName(const char *name) { - //TODO: Player Guard - HashMapHolder::MapType& m = HashMapHolder::GetContainer(); - HashMapHolder::MapType::iterator iter = m.begin(); - for(; iter != m.end(); ++iter) + HashMapHolder::ReadGuard g(HashMapHolder::GetLock()); + HashMapHolder::MapType& m = sObjectAccessor.GetPlayers(); + for(HashMapHolder::MapType::iterator iter = m.begin(); iter != m.end(); ++iter) if(iter->second->IsInWorld() && ( ::strcmp(name, iter->second->GetName()) == 0 )) return iter->second; + return NULL; } void ObjectAccessor::SaveAllPlayers() { - Guard guard(*HashMapHolder::GetLock()); - HashMapHolder::MapType& m = HashMapHolder::GetContainer(); - HashMapHolder::MapType::iterator itr = m.begin(); - for(; itr != m.end(); ++itr) + HashMapHolder::ReadGuard g(HashMapHolder::GetLock()); + HashMapHolder::MapType& m = sObjectAccessor.GetPlayers(); + for(HashMapHolder::MapType::iterator itr = m.begin(); itr != m.end(); ++itr) itr->second->SaveToDB(); } @@ -277,7 +276,7 @@ void ObjectAccessor::RemoveOldCorpses() /// Define the static member of HashMapHolder template UNORDERED_MAP< uint64, T* > HashMapHolder::m_objectMap; -template ACE_Thread_Mutex HashMapHolder::i_lock; +template ACE_RW_Thread_Mutex HashMapHolder::i_lock; /// Global definitions for the hashmap storage diff --git a/src/game/ObjectAccessor.h b/src/game/ObjectAccessor.h index 2853d6097..161deb60f 100644 --- a/src/game/ObjectAccessor.h +++ b/src/game/ObjectAccessor.h @@ -22,6 +22,7 @@ #include "Platform/Define.h" #include "Policies/Singleton.h" #include +#include #include "Utilities/UnorderedMap.h" #include "Policies/ThreadingModel.h" @@ -47,26 +48,33 @@ class HashMapHolder public: typedef UNORDERED_MAP< uint64, T* > MapType; - typedef ACE_Thread_Mutex LockType; - typedef MaNGOS::GeneralLock Guard; + typedef ACE_RW_Thread_Mutex LockType; + typedef ACE_Read_Guard ReadGuard; + typedef ACE_Write_Guard WriteGuard; - static void Insert(T* o) { m_objectMap[o->GetGUID()] = o; } + static void Insert(T* o) + { + WriteGuard guard(i_lock); + m_objectMap[o->GetGUID()] = o; + } static void Remove(T* o) { - Guard guard(i_lock); + WriteGuard guard(i_lock); m_objectMap.erase(o->GetGUID()); } static T* Find(ObjectGuid guid) { + ReadGuard guard(i_lock); typename MapType::iterator itr = m_objectMap.find(guid.GetRawValue()); return (itr != m_objectMap.end()) ? itr->second : NULL; } static MapType& GetContainer() { return m_objectMap; } - static LockType* GetLock() { return &i_lock; } + static LockType& GetLock() { return i_lock; } + private: //Non instanceable only static @@ -78,8 +86,8 @@ class HashMapHolder class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton > { - friend class MaNGOS::OperatorNew; + ObjectAccessor(); ~ObjectAccessor(); ObjectAccessor(const ObjectAccessor &); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 56cc0a89f..69e344530 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9996" + #define REVISION_NR "9997" #endif // __REVISION_NR_H__