mirror of
https://github.com/mangosfour/server.git
synced 2025-12-16 04:37:00 +00:00
[9997] Some changes in HashMapHolder.
* Use ACE_RW_Thread_Mutex, since there's much more reading than writing. * Use read lock in Find(), and write lock in Insert() and Remove(). * Correctly lock the hashmap on outside calls.
This commit is contained in:
parent
aa62225c68
commit
a037a26fde
4 changed files with 36 additions and 27 deletions
|
|
@ -92,22 +92,21 @@ ObjectAccessor::FindPlayer(ObjectGuid guid)
|
|||
Player*
|
||||
ObjectAccessor::FindPlayerByName(const char *name)
|
||||
{
|
||||
//TODO: Player Guard
|
||||
HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer();
|
||||
HashMapHolder<Player>::MapType::iterator iter = m.begin();
|
||||
for(; iter != m.end(); ++iter)
|
||||
HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock());
|
||||
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
|
||||
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;
|
||||
}
|
||||
|
||||
void
|
||||
ObjectAccessor::SaveAllPlayers()
|
||||
{
|
||||
Guard guard(*HashMapHolder<Player>::GetLock());
|
||||
HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer();
|
||||
HashMapHolder<Player>::MapType::iterator itr = m.begin();
|
||||
for(; itr != m.end(); ++itr)
|
||||
HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock());
|
||||
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
|
||||
for(HashMapHolder<Player>::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 <class T> UNORDERED_MAP< uint64, T* > HashMapHolder<T>::m_objectMap;
|
||||
template <class T> ACE_Thread_Mutex HashMapHolder<T>::i_lock;
|
||||
template <class T> ACE_RW_Thread_Mutex HashMapHolder<T>::i_lock;
|
||||
|
||||
/// Global definitions for the hashmap storage
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue