mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-26 15:16:24 +00:00
feat(Core/Threading): replace ace threading (#4821)
This commit is contained in:
@@ -26,6 +26,35 @@
|
||||
#include "WorldPacket.h"
|
||||
#include <cmath>
|
||||
|
||||
template<class T>
|
||||
void HashMapHolder<T>::Insert(T* o)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(*GetLock());
|
||||
m_objectMap[o->GetGUID()] = o;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void HashMapHolder<T>::Remove(T* o)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(*GetLock());
|
||||
m_objectMap.erase(o->GetGUID());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* HashMapHolder<T>::Find(uint64 guid)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(*GetLock());
|
||||
typename MapType::iterator itr = m_objectMap.find(guid);
|
||||
return (itr != m_objectMap.end()) ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::shared_mutex* HashMapHolder<T>::GetLock()
|
||||
{
|
||||
static std::shared_mutex _lock;
|
||||
return &_lock;
|
||||
}
|
||||
|
||||
ObjectAccessor::ObjectAccessor()
|
||||
{
|
||||
}
|
||||
@@ -190,20 +219,6 @@ Player* ObjectAccessor::FindConnectedPlayer(uint64 const& guid)
|
||||
|
||||
Player* ObjectAccessor::FindPlayerByName(std::string const& name, bool checkInWorld)
|
||||
{
|
||||
/*ACORE_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
|
||||
std::string nameStr = name;
|
||||
std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower);
|
||||
HashMapHolder<Player>::MapType const& m = GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
{
|
||||
if (!iter->second->IsInWorld())
|
||||
continue;
|
||||
std::string currentName = iter->second->GetName();
|
||||
std::transform(currentName.begin(), currentName.end(), currentName.begin(), ::tolower);
|
||||
if (nameStr.compare(currentName) == 0)
|
||||
return iter->second;
|
||||
}*/
|
||||
|
||||
// pussywizard: optimization
|
||||
std::string nameStr = name;
|
||||
std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower);
|
||||
@@ -217,7 +232,8 @@ Player* ObjectAccessor::FindPlayerByName(std::string const& name, bool checkInWo
|
||||
|
||||
void ObjectAccessor::SaveAllPlayers()
|
||||
{
|
||||
ACORE_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
|
||||
std::shared_lock<std::shared_mutex> lock(*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(false, false);
|
||||
@@ -225,7 +241,7 @@ void ObjectAccessor::SaveAllPlayers()
|
||||
|
||||
Corpse* ObjectAccessor::GetCorpseForPlayerGUID(uint64 guid)
|
||||
{
|
||||
ACORE_READ_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
std::shared_lock<std::shared_mutex> lock(i_corpseLock);
|
||||
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
|
||||
if (iter == i_player2corpse.end())
|
||||
@@ -242,7 +258,7 @@ void ObjectAccessor::RemoveCorpse(Corpse* corpse, bool final)
|
||||
|
||||
if (!final)
|
||||
{
|
||||
ACORE_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
std::unique_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGUID());
|
||||
if (iter == i_player2corpse.end())
|
||||
return;
|
||||
@@ -269,7 +285,7 @@ void ObjectAccessor::RemoveCorpse(Corpse* corpse, bool final)
|
||||
|
||||
// Critical section
|
||||
{
|
||||
ACORE_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
std::unique_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
|
||||
// build mapid*cellid -> guid_set map
|
||||
CellCoord cellCoord = acore::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
@@ -285,7 +301,7 @@ void ObjectAccessor::AddCorpse(Corpse* corpse)
|
||||
|
||||
// Critical section
|
||||
{
|
||||
ACORE_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
std::unique_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
|
||||
ASSERT(i_player2corpse.find(corpse->GetOwnerGUID()) == i_player2corpse.end());
|
||||
i_player2corpse[corpse->GetOwnerGUID()] = corpse;
|
||||
@@ -298,7 +314,7 @@ void ObjectAccessor::AddCorpse(Corpse* corpse)
|
||||
|
||||
void ObjectAccessor::AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map)
|
||||
{
|
||||
ACORE_READ_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
std::shared_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
|
||||
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
|
||||
{
|
||||
@@ -386,7 +402,7 @@ Corpse* ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid, bool insignia
|
||||
}
|
||||
|
||||
// pussywizard: for deleting bones
|
||||
ACORE_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
std::unique_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
i_playerBones.push_back(bones->GetGUID());
|
||||
}
|
||||
|
||||
@@ -413,7 +429,7 @@ void ObjectAccessor::RemoveOldCorpses()
|
||||
|
||||
// pussywizard: for deleting bones
|
||||
std::list<uint64>::iterator next2;
|
||||
ACORE_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
std::unique_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
for (std::list<uint64>::iterator itr = i_playerBones.begin(); itr != i_playerBones.end(); itr = next2)
|
||||
{
|
||||
next2 = itr;
|
||||
@@ -446,13 +462,13 @@ void ObjectAccessor::RemoveOldCorpses()
|
||||
|
||||
void ObjectAccessor::AddDelayedCorpseAction(Corpse* corpse, uint8 action, uint32 mapId, uint32 instanceId)
|
||||
{
|
||||
ACORE_GUARD(ACE_Thread_Mutex, DelayedCorpseLock);
|
||||
std::lock_guard<std::mutex> guard(DelayedCorpseLock);
|
||||
i_delayedCorpseActions.push_back(DelayedCorpseAction(corpse, action, mapId, instanceId));
|
||||
}
|
||||
|
||||
void ObjectAccessor::ProcessDelayedCorpseActions()
|
||||
{
|
||||
ACORE_GUARD(ACE_Thread_Mutex, DelayedCorpseLock);
|
||||
std::lock_guard<std::mutex> guard(DelayedCorpseLock);
|
||||
for (std::list<DelayedCorpseAction>::iterator itr = i_delayedCorpseActions.begin(); itr != i_delayedCorpseActions.end(); ++itr)
|
||||
{
|
||||
DelayedCorpseAction a = (*itr);
|
||||
|
||||
Reference in New Issue
Block a user