mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Replaced mutex related code in Common.h
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "VMapManager2.h"
|
||||
@@ -252,7 +253,7 @@ namespace VMAP
|
||||
WorldModel* VMapManager2::acquireModelInstance(const std::string& basepath, const std::string& filename)
|
||||
{
|
||||
//! Critical section, thread safe access to iLoadedModelFiles
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, LoadedModelFilesLock);
|
||||
std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
|
||||
|
||||
ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
|
||||
if (model == iLoadedModelFiles.end())
|
||||
@@ -275,7 +276,7 @@ namespace VMAP
|
||||
void VMapManager2::releaseModelInstance(const std::string &filename)
|
||||
{
|
||||
//! Critical section, thread safe access to iLoadedModelFiles
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, LoadedModelFilesLock);
|
||||
std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
|
||||
|
||||
ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
|
||||
if (model == iLoadedModelFiles.end())
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
#ifndef _VMAPMANAGER2_H
|
||||
#define _VMAPMANAGER2_H
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include "Define.h"
|
||||
#include "IVMapManager.h"
|
||||
#include <unordered_map>
|
||||
#include <ace/Thread_Mutex.h>
|
||||
|
||||
//===========================================================
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace VMAP
|
||||
ModelFileMap iLoadedModelFiles;
|
||||
InstanceTreeMap iInstanceMapTrees;
|
||||
// Mutex for iLoadedModelFiles
|
||||
ACE_Thread_Mutex LoadedModelFilesLock;
|
||||
std::mutex LoadedModelFilesLock;
|
||||
|
||||
bool _loadMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY);
|
||||
/* void _unloadMap(uint32 pMapId, uint32 x, uint32 y); */
|
||||
|
||||
@@ -1600,14 +1600,14 @@ void GameEventMgr::RunSmartAIScripts(uint16 event_id, bool activate)
|
||||
//! Iterate over every supported source type (creature and gameobject)
|
||||
//! Not entirely sure how this will affect units in non-loaded grids.
|
||||
{
|
||||
TRINITY_READ_GUARD(HashMapHolder<Creature>::LockType, *HashMapHolder<Creature>::GetLock());
|
||||
boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Creature>::GetLock());
|
||||
HashMapHolder<Creature>::MapType const& m = ObjectAccessor::GetCreatures();
|
||||
for (HashMapHolder<Creature>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
if (iter->second->IsInWorld())
|
||||
iter->second->AI()->sOnGameEvent(activate, event_id);
|
||||
}
|
||||
{
|
||||
TRINITY_READ_GUARD(HashMapHolder<GameObject>::LockType, *HashMapHolder<GameObject>::GetLock());
|
||||
boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<GameObject>::GetLock());
|
||||
HashMapHolder<GameObject>::MapType const& m = ObjectAccessor::GetGameObjects();
|
||||
for (HashMapHolder<GameObject>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
if (iter->second->IsInWorld())
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
|
||||
#include "ObjectAccessor.h"
|
||||
#include "CellImpl.h"
|
||||
#include "Corpse.h"
|
||||
@@ -205,7 +208,8 @@ Unit* ObjectAccessor::FindUnit(uint64 guid)
|
||||
|
||||
Player* ObjectAccessor::FindPlayerByName(std::string const& name)
|
||||
{
|
||||
TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
|
||||
boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
||||
|
||||
std::string nameStr = name;
|
||||
std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower);
|
||||
HashMapHolder<Player>::MapType const& m = GetPlayers();
|
||||
@@ -224,7 +228,8 @@ Player* ObjectAccessor::FindPlayerByName(std::string const& name)
|
||||
|
||||
void ObjectAccessor::SaveAllPlayers()
|
||||
{
|
||||
TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
|
||||
boost::shared_lock<boost::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();
|
||||
@@ -232,7 +237,7 @@ void ObjectAccessor::SaveAllPlayers()
|
||||
|
||||
Corpse* ObjectAccessor::GetCorpseForPlayerGUID(uint64 guid)
|
||||
{
|
||||
TRINITY_READ_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
boost::shared_lock<boost::shared_mutex> lock(_corpseLock);
|
||||
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
|
||||
if (iter == i_player2corpse.end())
|
||||
@@ -247,6 +252,8 @@ void ObjectAccessor::RemoveCorpse(Corpse* corpse)
|
||||
{
|
||||
ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
|
||||
|
||||
boost::upgrade_lock<boost::shared_mutex> lock(_corpseLock);
|
||||
|
||||
/// @todo more works need to be done for corpse and other world object
|
||||
if (Map* map = corpse->FindMap())
|
||||
{
|
||||
@@ -265,7 +272,7 @@ void ObjectAccessor::RemoveCorpse(Corpse* corpse)
|
||||
|
||||
// Critical section
|
||||
{
|
||||
TRINITY_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
|
||||
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGUID());
|
||||
if (iter == i_player2corpse.end()) /// @todo Fix this
|
||||
@@ -285,7 +292,7 @@ void ObjectAccessor::AddCorpse(Corpse* corpse)
|
||||
|
||||
// Critical section
|
||||
{
|
||||
TRINITY_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
boost::unique_lock<boost::shared_mutex> lock(_corpseLock);
|
||||
|
||||
ASSERT(i_player2corpse.find(corpse->GetOwnerGUID()) == i_player2corpse.end());
|
||||
i_player2corpse[corpse->GetOwnerGUID()] = corpse;
|
||||
@@ -298,7 +305,7 @@ void ObjectAccessor::AddCorpse(Corpse* corpse)
|
||||
|
||||
void ObjectAccessor::AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map)
|
||||
{
|
||||
TRINITY_READ_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
|
||||
boost::shared_lock<boost::shared_mutex> lock(_corpseLock);
|
||||
|
||||
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
|
||||
{
|
||||
@@ -431,8 +438,8 @@ void ObjectAccessor::UnloadAll()
|
||||
|
||||
/// Define the static members of HashMapHolder
|
||||
|
||||
template <class T> std::unordered_map< uint64, T* > HashMapHolder<T>::m_objectMap;
|
||||
template <class T> typename HashMapHolder<T>::LockType HashMapHolder<T>::i_lock;
|
||||
template <class T> std::unordered_map< uint64, T* > HashMapHolder<T>::_objectMap;
|
||||
template <class T> boost::shared_mutex HashMapHolder<T>::_lock;
|
||||
|
||||
/// Global definitions for the hashmap storage
|
||||
|
||||
|
||||
@@ -19,17 +19,17 @@
|
||||
#ifndef TRINITY_OBJECTACCESSOR_H
|
||||
#define TRINITY_OBJECTACCESSOR_H
|
||||
|
||||
#include "Define.h"
|
||||
#include <ace/Singleton.h>
|
||||
#include <ace/Thread_Mutex.h>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
#include "UpdateData.h"
|
||||
|
||||
#include "Define.h"
|
||||
#include "GridDefines.h"
|
||||
#include "UpdateData.h"
|
||||
#include "Object.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
class Creature;
|
||||
class Corpse;
|
||||
@@ -48,42 +48,41 @@ class HashMapHolder
|
||||
public:
|
||||
|
||||
typedef std::unordered_map<uint64, T*> MapType;
|
||||
typedef ACE_RW_Thread_Mutex LockType;
|
||||
|
||||
static void Insert(T* o)
|
||||
{
|
||||
TRINITY_WRITE_GUARD(LockType, i_lock);
|
||||
m_objectMap[o->GetGUID()] = o;
|
||||
boost::shared_lock<boost::shared_mutex> lock(_lock);
|
||||
|
||||
_objectMap[o->GetGUID()] = o;
|
||||
}
|
||||
|
||||
static void Remove(T* o)
|
||||
{
|
||||
TRINITY_WRITE_GUARD(LockType, i_lock);
|
||||
m_objectMap.erase(o->GetGUID());
|
||||
boost::unique_lock<boost::shared_mutex> lock(_lock);
|
||||
_objectMap.erase(o->GetGUID());
|
||||
}
|
||||
|
||||
static T* Find(uint64 guid)
|
||||
{
|
||||
TRINITY_READ_GUARD(LockType, i_lock);
|
||||
typename MapType::iterator itr = m_objectMap.find(guid);
|
||||
return (itr != m_objectMap.end()) ? itr->second : NULL;
|
||||
boost::shared_lock<boost::shared_mutex> lock(_lock);
|
||||
typename MapType::iterator itr = _objectMap.find(guid);
|
||||
return (itr != _objectMap.end()) ? itr->second : NULL;
|
||||
}
|
||||
|
||||
static MapType& GetContainer() { return m_objectMap; }
|
||||
static MapType& GetContainer() { return _objectMap; }
|
||||
|
||||
static LockType* GetLock() { return &i_lock; }
|
||||
static boost::shared_mutex* GetLock() { return &_lock; }
|
||||
|
||||
private:
|
||||
//Non instanceable only static
|
||||
HashMapHolder() { }
|
||||
|
||||
static LockType i_lock;
|
||||
static MapType m_objectMap;
|
||||
static boost::shared_mutex _lock;
|
||||
static MapType _objectMap;
|
||||
};
|
||||
|
||||
class ObjectAccessor
|
||||
{
|
||||
friend class ACE_Singleton<ObjectAccessor, ACE_Null_Mutex>;
|
||||
private:
|
||||
ObjectAccessor();
|
||||
~ObjectAccessor();
|
||||
@@ -93,6 +92,12 @@ class ObjectAccessor
|
||||
public:
|
||||
/// @todo: Override these template functions for each holder type and add assertions
|
||||
|
||||
static ObjectAccessor* instance()
|
||||
{
|
||||
static ObjectAccessor *instance = new ObjectAccessor();
|
||||
return instance;
|
||||
}
|
||||
|
||||
template<class T> static T* GetObjectInOrOutOfWorld(uint64 guid, T* /*typeSpecifier*/)
|
||||
{
|
||||
return HashMapHolder<T>::Find(guid);
|
||||
@@ -195,13 +200,13 @@ class ObjectAccessor
|
||||
//non-static functions
|
||||
void AddUpdateObject(Object* obj)
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, i_objectLock);
|
||||
std::lock_guard<std::mutex> lock(_objectLock);
|
||||
i_objects.insert(obj);
|
||||
}
|
||||
|
||||
void RemoveUpdateObject(Object* obj)
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, i_objectLock);
|
||||
std::lock_guard<std::mutex> lock(_objectLock);
|
||||
i_objects.erase(obj);
|
||||
}
|
||||
|
||||
@@ -228,9 +233,9 @@ class ObjectAccessor
|
||||
std::set<Object*> i_objects;
|
||||
Player2CorpsesMapType i_player2corpse;
|
||||
|
||||
ACE_Thread_Mutex i_objectLock;
|
||||
ACE_RW_Thread_Mutex i_corpseLock;
|
||||
std::mutex _objectLock;
|
||||
boost::shared_mutex _corpseLock;
|
||||
};
|
||||
|
||||
#define sObjectAccessor ACE_Singleton<ObjectAccessor, ACE_Null_Mutex>::instance()
|
||||
#define sObjectAccessor ObjectAccessor::instance()
|
||||
#endif
|
||||
|
||||
@@ -260,7 +260,8 @@ void WorldSession::HandleWhoOpcode(WorldPacket& recvData)
|
||||
data << uint32(matchcount); // placeholder, count of players matching criteria
|
||||
data << uint32(displaycount); // placeholder, count of players displayed
|
||||
|
||||
TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
|
||||
boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
||||
|
||||
HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
{
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
#ifndef _INSTANCESAVEMGR_H
|
||||
#define _INSTANCESAVEMGR_H
|
||||
|
||||
#include "Define.h"
|
||||
#include <ace/Singleton.h>
|
||||
#include <ace/Thread_Mutex.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Define.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DBCEnums.h"
|
||||
#include "ObjectDefines.h"
|
||||
@@ -80,13 +80,18 @@ class InstanceSave
|
||||
|
||||
/* online players bound to the instance (perm/solo)
|
||||
does not include the members of the group unless they have permanent saves */
|
||||
void AddPlayer(Player* player) { TRINITY_GUARD(ACE_Thread_Mutex, _lock); m_playerList.push_back(player); }
|
||||
void AddPlayer(Player* player)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_playerListLock);
|
||||
m_playerList.push_back(player);
|
||||
}
|
||||
|
||||
bool RemovePlayer(Player* player)
|
||||
{
|
||||
_lock.acquire();
|
||||
_playerListLock.lock();
|
||||
m_playerList.remove(player);
|
||||
bool isStillValid = UnloadIfEmpty();
|
||||
_lock.release();
|
||||
_playerListLock.unlock();
|
||||
|
||||
//delete here if needed, after releasing the lock
|
||||
if (m_toDelete)
|
||||
@@ -137,14 +142,13 @@ class InstanceSave
|
||||
bool m_canReset;
|
||||
bool m_toDelete;
|
||||
|
||||
ACE_Thread_Mutex _lock;
|
||||
std::mutex _playerListLock;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<uint32 /*PAIR32(map, difficulty)*/, time_t /*resetTime*/> ResetTimeByMapDifficultyMap;
|
||||
|
||||
class InstanceSaveManager
|
||||
{
|
||||
friend class ACE_Singleton<InstanceSaveManager, ACE_Thread_Mutex>;
|
||||
friend class InstanceSave;
|
||||
|
||||
private:
|
||||
@@ -154,6 +158,12 @@ class InstanceSaveManager
|
||||
public:
|
||||
typedef std::unordered_map<uint32 /*InstanceId*/, InstanceSave*> InstanceSaveHashMap;
|
||||
|
||||
static InstanceSaveManager* instance()
|
||||
{
|
||||
static InstanceSaveManager *instance = new InstanceSaveManager();
|
||||
return instance;
|
||||
}
|
||||
|
||||
/* resetTime is a global propery of each (raid/heroic) map
|
||||
all instances of that map reset at the same time */
|
||||
struct InstResetEvent
|
||||
@@ -221,5 +231,5 @@ class InstanceSaveManager
|
||||
ResetTimeQueue m_resetTimeQueue;
|
||||
};
|
||||
|
||||
#define sInstanceSaveMgr ACE_Singleton<InstanceSaveManager, ACE_Thread_Mutex>::instance()
|
||||
#define sInstanceSaveMgr InstanceSaveManager::instance()
|
||||
#endif
|
||||
|
||||
@@ -382,7 +382,7 @@ void Map::DeleteFromWorld(Player* player)
|
||||
|
||||
void Map::EnsureGridCreated(const GridCoord &p)
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, GridLock);
|
||||
std::lock_guard<std::mutex> lock(_gridLock);
|
||||
EnsureGridCreated_i(p);
|
||||
}
|
||||
|
||||
@@ -2901,7 +2901,7 @@ bool InstanceMap::AddPlayerToMap(Player* player)
|
||||
// Is it needed?
|
||||
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, Lock);
|
||||
std::lock_guard<std::mutex> lock(_mapLock);
|
||||
// Check moved to void WorldSession::HandleMoveWorldportAckOpcode()
|
||||
//if (!CanEnter(player))
|
||||
//return false;
|
||||
@@ -3242,7 +3242,7 @@ bool BattlegroundMap::CanEnter(Player* player)
|
||||
bool BattlegroundMap::AddPlayerToMap(Player* player)
|
||||
{
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, Lock);
|
||||
std::lock_guard<std::mutex> lock(_mapLock);
|
||||
//Check moved to void WorldSession::HandleMoveWorldportAckOpcode()
|
||||
//if (!CanEnter(player))
|
||||
//return false;
|
||||
|
||||
@@ -574,8 +574,8 @@ class Map : public GridRefManager<NGridType>
|
||||
protected:
|
||||
void SetUnloadReferenceLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); }
|
||||
|
||||
ACE_Thread_Mutex Lock;
|
||||
ACE_Thread_Mutex GridLock;
|
||||
std::mutex _mapLock;
|
||||
std::mutex _gridLock;
|
||||
|
||||
MapEntry const* i_mapEntry;
|
||||
uint8 i_spawnMode;
|
||||
|
||||
@@ -187,7 +187,7 @@ Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player)
|
||||
InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save, Difficulty difficulty)
|
||||
{
|
||||
// load/create a map
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, Lock);
|
||||
std::lock_guard<std::mutex> lock(_mapLock);
|
||||
|
||||
// make sure we have a valid map id
|
||||
const MapEntry* entry = sMapStore.LookupEntry(GetId());
|
||||
@@ -223,7 +223,7 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save,
|
||||
BattlegroundMap* MapInstanced::CreateBattleground(uint32 InstanceId, Battleground* bg)
|
||||
{
|
||||
// load/create a map
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, Lock);
|
||||
std::lock_guard<std::mutex> lock(_mapLock);
|
||||
|
||||
TC_LOG_DEBUG("maps", "MapInstanced::CreateBattleground: map bg %d for %d created.", InstanceId, GetId());
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ Map* MapManager::CreateBaseMap(uint32 id)
|
||||
|
||||
if (map == NULL)
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, Lock);
|
||||
std::lock_guard<std::mutex> lock(_mapsLock);
|
||||
|
||||
MapEntry const* entry = sMapStore.LookupEntry(id);
|
||||
ASSERT(entry);
|
||||
@@ -302,7 +302,7 @@ void MapManager::UnloadAll()
|
||||
|
||||
uint32 MapManager::GetNumInstances()
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, Lock);
|
||||
std::lock_guard<std::mutex> lock(_mapsLock);
|
||||
|
||||
uint32 ret = 0;
|
||||
for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
|
||||
@@ -319,7 +319,7 @@ uint32 MapManager::GetNumInstances()
|
||||
|
||||
uint32 MapManager::GetNumPlayersInInstances()
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, Lock);
|
||||
std::lock_guard<std::mutex> lock(_mapsLock);
|
||||
|
||||
uint32 ret = 0;
|
||||
for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
|
||||
|
||||
@@ -141,7 +141,7 @@ class MapManager
|
||||
MapManager(const MapManager &);
|
||||
MapManager& operator=(const MapManager &);
|
||||
|
||||
ACE_Thread_Mutex Lock;
|
||||
std::mutex _mapsLock;
|
||||
uint32 i_gridCleanUpDelay;
|
||||
MapMapType i_maps;
|
||||
IntervalTimer i_timer;
|
||||
|
||||
@@ -1,10 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <ace/Method_Request.h>
|
||||
|
||||
#include "MapUpdater.h"
|
||||
#include "DelayExecutor.h"
|
||||
#include "Map.h"
|
||||
#include "DatabaseEnv.h"
|
||||
|
||||
#include <ace/Guard_T.h>
|
||||
#include <ace/Method_Request.h>
|
||||
|
||||
class WDBThreadStartReq1 : public ACE_Method_Request
|
||||
{
|
||||
@@ -57,8 +77,7 @@ class MapUpdateRequest : public ACE_Method_Request
|
||||
}
|
||||
};
|
||||
|
||||
MapUpdater::MapUpdater():
|
||||
m_executor(), m_mutex(), m_condition(m_mutex), pending_requests(0) { }
|
||||
MapUpdater::MapUpdater(): m_executor(), pending_requests(0) { }
|
||||
|
||||
MapUpdater::~MapUpdater()
|
||||
{
|
||||
@@ -79,17 +98,19 @@ int MapUpdater::deactivate()
|
||||
|
||||
int MapUpdater::wait()
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, m_mutex);
|
||||
std::unique_lock<std::mutex> lock(_lock);
|
||||
|
||||
while (pending_requests > 0)
|
||||
m_condition.wait();
|
||||
_condition.wait(lock);
|
||||
|
||||
lock.unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MapUpdater::schedule_update(Map& map, ACE_UINT32 diff)
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, m_mutex);
|
||||
std::lock_guard<std::mutex> lock(_lock);
|
||||
|
||||
++pending_requests;
|
||||
|
||||
@@ -111,7 +132,7 @@ bool MapUpdater::activated()
|
||||
|
||||
void MapUpdater::update_finished()
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, m_mutex);
|
||||
std::lock_guard<std::mutex> lock(_lock);
|
||||
|
||||
if (pending_requests == 0)
|
||||
{
|
||||
@@ -121,5 +142,5 @@ void MapUpdater::update_finished()
|
||||
|
||||
--pending_requests;
|
||||
|
||||
m_condition.broadcast();
|
||||
_condition.notify_all();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _MAP_UPDATER_H_INCLUDED
|
||||
#define _MAP_UPDATER_H_INCLUDED
|
||||
|
||||
#include <ace/Thread_Mutex.h>
|
||||
#include <ace/Condition_Thread_Mutex.h>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#include "DelayExecutor.h"
|
||||
|
||||
@@ -30,8 +48,8 @@ class MapUpdater
|
||||
private:
|
||||
|
||||
DelayExecutor m_executor;
|
||||
ACE_Thread_Mutex m_mutex;
|
||||
ACE_Condition_Thread_Mutex m_condition;
|
||||
std::mutex _lock;
|
||||
std::condition_variable _condition;
|
||||
size_t pending_requests;
|
||||
|
||||
void update_finished();
|
||||
|
||||
@@ -29,13 +29,13 @@
|
||||
#include <ace/Reactor_Impl.h>
|
||||
#include <ace/TP_Reactor.h>
|
||||
#include <ace/Dev_Poll_Reactor.h>
|
||||
#include <ace/Guard_T.h>
|
||||
#include <ace/Atomic_Op.h>
|
||||
#include <ace/os_include/arpa/os_inet.h>
|
||||
#include <ace/os_include/netinet/os_tcp.h>
|
||||
#include <ace/os_include/sys/os_types.h>
|
||||
#include <ace/os_include/sys/os_socket.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
|
||||
#include "Log.h"
|
||||
@@ -109,7 +109,7 @@ class ReactorRunnable : protected ACE_Task_Base
|
||||
|
||||
int AddSocket (WorldSocket* sock)
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, m_NewSockets_Lock);
|
||||
std::lock_guard<std::mutex> lock(newSocketsLock);
|
||||
|
||||
++m_Connections;
|
||||
sock->AddReference();
|
||||
@@ -130,7 +130,7 @@ class ReactorRunnable : protected ACE_Task_Base
|
||||
|
||||
void AddNewSockets()
|
||||
{
|
||||
TRINITY_GUARD(ACE_Thread_Mutex, m_NewSockets_Lock);
|
||||
std::lock_guard<std::mutex> lock(newSocketsLock);
|
||||
|
||||
if (m_NewSockets.empty())
|
||||
return;
|
||||
@@ -208,7 +208,7 @@ class ReactorRunnable : protected ACE_Task_Base
|
||||
SocketSet m_Sockets;
|
||||
|
||||
SocketSet m_NewSockets;
|
||||
ACE_Thread_Mutex m_NewSockets_Lock;
|
||||
std::mutex newSocketsLock;
|
||||
};
|
||||
|
||||
WorldSocketMgr::WorldSocketMgr() :
|
||||
|
||||
@@ -123,7 +123,7 @@ public:
|
||||
bool first = true;
|
||||
bool footer = false;
|
||||
|
||||
TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
|
||||
boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
||||
HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
{
|
||||
|
||||
@@ -297,7 +297,7 @@ public:
|
||||
stmt->setUInt16(0, uint16(atLogin));
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
|
||||
boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
||||
HashMapHolder<Player>::MapType const& plist = sObjectAccessor->GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
|
||||
itr->second->SetAtLoginFlag(atLogin);
|
||||
|
||||
@@ -84,9 +84,6 @@
|
||||
#include "Threading/LockedQueue.h"
|
||||
#include "Threading/Threading.h"
|
||||
|
||||
#include <ace/Guard_T.h>
|
||||
#include <ace/RW_Thread_Mutex.h>
|
||||
#include <ace/Thread_Mutex.h>
|
||||
#include <ace/OS_NS_time.h>
|
||||
|
||||
#if PLATFORM == PLATFORM_WINDOWS
|
||||
@@ -188,20 +185,4 @@ typedef std::vector<std::string> StringVector;
|
||||
|
||||
#define MAX_QUERY_LEN 32*1024
|
||||
|
||||
#define TRINITY_GUARD(MUTEX, LOCK) \
|
||||
ACE_Guard< MUTEX > TRINITY_GUARD_OBJECT (LOCK); \
|
||||
if (TRINITY_GUARD_OBJECT.locked() == 0) ASSERT(false);
|
||||
|
||||
//! For proper implementation of multiple-read, single-write pattern, use
|
||||
//! ACE_RW_Mutex as underlying @MUTEX
|
||||
# define TRINITY_WRITE_GUARD(MUTEX, LOCK) \
|
||||
ACE_Write_Guard< MUTEX > TRINITY_GUARD_OBJECT (LOCK); \
|
||||
if (TRINITY_GUARD_OBJECT.locked() == 0) ASSERT(false);
|
||||
|
||||
//! For proper implementation of multiple-read, single-write pattern, use
|
||||
//! ACE_RW_Mutex as underlying @MUTEX
|
||||
# define TRINITY_READ_GUARD(MUTEX, LOCK) \
|
||||
ACE_Read_Guard< MUTEX > TRINITY_GUARD_OBJECT (LOCK); \
|
||||
if (TRINITY_GUARD_OBJECT.locked() == 0) ASSERT(false);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
|
||||
template <class T, typename StorageType = std::deque<T> >
|
||||
class LockedQueue
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user