From 0fa3a4923efb492a71f888e256348148fdd73d80 Mon Sep 17 00:00:00 2001 From: leak Date: Mon, 2 Jun 2014 23:01:01 +0200 Subject: Replaced LockedQueue ACE lock with std::mutex --- src/server/shared/Threading/LockedQueue.h | 244 ++++++++++++++---------------- 1 file changed, 117 insertions(+), 127 deletions(-) (limited to 'src/server/shared/Threading/LockedQueue.h') diff --git a/src/server/shared/Threading/LockedQueue.h b/src/server/shared/Threading/LockedQueue.h index 5709724c9a2..3ca2a5cd45c 100644 --- a/src/server/shared/Threading/LockedQueue.h +++ b/src/server/shared/Threading/LockedQueue.h @@ -19,140 +19,130 @@ #ifndef LOCKEDQUEUE_H #define LOCKEDQUEUE_H -#include -#include #include -#include -#include "Debugging/Errors.h" +#include -namespace ACE_Based + + +template > +class LockedQueue { - template > - class LockedQueue + //! Lock access to the queue. + std::mutex _lock; + + //! Storage backing the queue. + StorageType _queue; + + //! Cancellation flag. + volatile bool _canceled; + +public: + + //! Create a LockedQueue. + LockedQueue() + : _canceled(false) + { + } + + //! Destroy a LockedQueue. + virtual ~LockedQueue() + { + } + + //! Adds an item to the queue. + void add(const T& item) + { + lock(); + + _queue.push_back(item); + + unlock(); + } + + //! Gets the next result in the queue, if any. + bool next(T& result) + { + std::lock_guard lock(_lock); + + if (_queue.empty()) + return false; + + result = _queue.front(); + _queue.pop_front(); + + return true; + } + + template + bool next(T& result, Checker& check) + { + std::lock_guard lock(_lock); + + if (_queue.empty()) + return false; + + result = _queue.front(); + if (!check.Process(result)) + return false; + + _queue.pop_front(); + return true; + } + + //! Peeks at the top of the queue. Check if the queue is empty before calling! Remember to unlock after use if autoUnlock == false. + T& peek(bool autoUnlock = false) + { + lock(); + + T& result = _queue.front(); + + if (autoUnlock) + unlock(); + + return result; + } + + //! Cancels the queue. + void cancel() { - //! Lock access to the queue. - LockType _lock; + lock(); - //! Storage backing the queue. - StorageType _queue; + _canceled = true; - //! Cancellation flag. - volatile bool _canceled; + unlock(); + } - public: + //! Checks if the queue is cancelled. + bool cancelled() + { + ACE_Guard g(this->_lock); + return _canceled; + } - //! Create a LockedQueue. - LockedQueue() - : _canceled(false) - { - } + //! Locks the queue for access. + void lock() + { + this->_lock.lock(); + } - //! Destroy a LockedQueue. - virtual ~LockedQueue() - { - } - - //! Adds an item to the queue. - void add(const T& item) - { - lock(); - - //ASSERT(!this->_canceled); - // throw Cancellation_Exception(); - - _queue.push_back(item); - - unlock(); - } - - //! Gets the next result in the queue, if any. - bool next(T& result) - { - // ACE_Guard g(this->_lock); - ACE_GUARD_RETURN (LockType, g, this->_lock, false); - - if (_queue.empty()) - return false; - - //ASSERT (!_queue.empty() || !this->_canceled); - // throw Cancellation_Exception(); - result = _queue.front(); - _queue.pop_front(); - - return true; - } - - template - bool next(T& result, Checker& check) - { - ACE_Guard g(this->_lock); - - if (_queue.empty()) - return false; - - result = _queue.front(); - if (!check.Process(result)) - return false; - - _queue.pop_front(); - return true; - } - - //! Peeks at the top of the queue. Check if the queue is empty before calling! Remember to unlock after use if autoUnlock == false. - T& peek(bool autoUnlock = false) - { - lock(); - - T& result = _queue.front(); - - if (autoUnlock) - unlock(); - - return result; - } - - //! Cancels the queue. - void cancel() - { - lock(); - - _canceled = true; - - unlock(); - } - - //! Checks if the queue is cancelled. - bool cancelled() - { - ACE_Guard g(this->_lock); - return _canceled; - } - - //! Locks the queue for access. - void lock() - { - this->_lock.acquire(); - } - - //! Unlocks the queue. - void unlock() - { - this->_lock.release(); - } - - ///! Calls pop_front of the queue - void pop_front() - { - ACE_GUARD (LockType, g, this->_lock); - _queue.pop_front(); - } - - ///! Checks if we're empty or not with locks held - bool empty() - { - ACE_GUARD_RETURN (LockType, g, this->_lock, false); - return _queue.empty(); - } - }; -} + //! Unlocks the queue. + void unlock() + { + this->_lock.unlock(); + } + + ///! Calls pop_front of the queue + void pop_front() + { + std::lock_guard lock(_lock); + _queue.pop_front(); + } + + ///! Checks if we're empty or not with locks held + bool empty() + { + std::lock_guard lock(_lock); + return _queue.empty(); + } +}; #endif -- cgit v1.2.3 From ee4a3b9d59867a2440f8eb35f96405e5c4f6fe28 Mon Sep 17 00:00:00 2001 From: leak Date: Sun, 8 Jun 2014 15:30:57 +0200 Subject: Replaced mutex related code in Common.h --- src/server/collision/Management/VMapManager2.cpp | 5 ++- src/server/collision/Management/VMapManager2.h | 6 +-- src/server/game/Events/GameEventMgr.cpp | 4 +- src/server/game/Globals/ObjectAccessor.cpp | 23 ++++++---- src/server/game/Globals/ObjectAccessor.h | 53 +++++++++++++----------- src/server/game/Handlers/MiscHandler.cpp | 3 +- src/server/game/Instances/InstanceSaveMgr.h | 28 +++++++++---- src/server/game/Maps/Map.cpp | 6 +-- src/server/game/Maps/Map.h | 4 +- src/server/game/Maps/MapInstanced.cpp | 4 +- src/server/game/Maps/MapManager.cpp | 6 +-- src/server/game/Maps/MapManager.h | 2 +- src/server/game/Maps/MapUpdater.cpp | 39 +++++++++++++---- src/server/game/Maps/MapUpdater.h | 26 ++++++++++-- src/server/game/Server/WorldSocketMgr.cpp | 8 ++-- src/server/scripts/Commands/cs_gm.cpp | 2 +- src/server/scripts/Commands/cs_reset.cpp | 2 +- src/server/shared/Common.h | 19 --------- src/server/shared/Threading/LockedQueue.h | 2 - 19 files changed, 142 insertions(+), 100 deletions(-) (limited to 'src/server/shared/Threading/LockedQueue.h') diff --git a/src/server/collision/Management/VMapManager2.cpp b/src/server/collision/Management/VMapManager2.cpp index 813a3c04288..2aa3b6ab40d 100644 --- a/src/server/collision/Management/VMapManager2.cpp +++ b/src/server/collision/Management/VMapManager2.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #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 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 lock(LoadedModelFilesLock); ModelFileMap::iterator model = iLoadedModelFiles.find(filename); if (model == iLoadedModelFiles.end()) diff --git a/src/server/collision/Management/VMapManager2.h b/src/server/collision/Management/VMapManager2.h index 711025e67c0..03de6951d5d 100644 --- a/src/server/collision/Management/VMapManager2.h +++ b/src/server/collision/Management/VMapManager2.h @@ -19,10 +19,10 @@ #ifndef _VMAPMANAGER2_H #define _VMAPMANAGER2_H +#include +#include #include "Define.h" #include "IVMapManager.h" -#include -#include //=========================================================== @@ -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); */ diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index 5669f36a939..9e1514f11bd 100644 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -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::LockType, *HashMapHolder::GetLock()); + boost::shared_lock lock(*HashMapHolder::GetLock()); HashMapHolder::MapType const& m = ObjectAccessor::GetCreatures(); for (HashMapHolder::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::LockType, *HashMapHolder::GetLock()); + boost::shared_lock lock(*HashMapHolder::GetLock()); HashMapHolder::MapType const& m = ObjectAccessor::GetGameObjects(); for (HashMapHolder::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter) if (iter->second->IsInWorld()) diff --git a/src/server/game/Globals/ObjectAccessor.cpp b/src/server/game/Globals/ObjectAccessor.cpp index 8bf353d3eaa..ec33d8efbe1 100644 --- a/src/server/game/Globals/ObjectAccessor.cpp +++ b/src/server/game/Globals/ObjectAccessor.cpp @@ -16,6 +16,9 @@ * with this program. If not, see . */ +#include +#include + #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::LockType, *HashMapHolder::GetLock()); + boost::shared_lock lock(*HashMapHolder::GetLock()); + std::string nameStr = name; std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower); HashMapHolder::MapType const& m = GetPlayers(); @@ -224,7 +228,8 @@ Player* ObjectAccessor::FindPlayerByName(std::string const& name) void ObjectAccessor::SaveAllPlayers() { - TRINITY_READ_GUARD(HashMapHolder::LockType, *HashMapHolder::GetLock()); + boost::shared_lock lock(*HashMapHolder::GetLock()); + HashMapHolder::MapType const& m = GetPlayers(); for (HashMapHolder::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 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 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 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 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 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 std::unordered_map< uint64, T* > HashMapHolder::m_objectMap; -template typename HashMapHolder::LockType HashMapHolder::i_lock; +template std::unordered_map< uint64, T* > HashMapHolder::_objectMap; +template boost::shared_mutex HashMapHolder::_lock; /// Global definitions for the hashmap storage diff --git a/src/server/game/Globals/ObjectAccessor.h b/src/server/game/Globals/ObjectAccessor.h index b52699c85ac..79799cec55f 100644 --- a/src/server/game/Globals/ObjectAccessor.h +++ b/src/server/game/Globals/ObjectAccessor.h @@ -19,17 +19,17 @@ #ifndef TRINITY_OBJECTACCESSOR_H #define TRINITY_OBJECTACCESSOR_H -#include "Define.h" -#include -#include +#include +#include #include +#include +#include -#include "UpdateData.h" - +#include "Define.h" #include "GridDefines.h" +#include "UpdateData.h" #include "Object.h" -#include class Creature; class Corpse; @@ -48,42 +48,41 @@ class HashMapHolder public: typedef std::unordered_map 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 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 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 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; 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 static T* GetObjectInOrOutOfWorld(uint64 guid, T* /*typeSpecifier*/) { return HashMapHolder::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 lock(_objectLock); i_objects.insert(obj); } void RemoveUpdateObject(Object* obj) { - TRINITY_GUARD(ACE_Thread_Mutex, i_objectLock); + std::lock_guard lock(_objectLock); i_objects.erase(obj); } @@ -228,9 +233,9 @@ class ObjectAccessor std::set 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::instance() +#define sObjectAccessor ObjectAccessor::instance() #endif diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index 1b04c89b338..40830d63d05 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -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::LockType, *HashMapHolder::GetLock()); + boost::shared_lock lock(*HashMapHolder::GetLock()); + HashMapHolder::MapType const& m = sObjectAccessor->GetPlayers(); for (HashMapHolder::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) { diff --git a/src/server/game/Instances/InstanceSaveMgr.h b/src/server/game/Instances/InstanceSaveMgr.h index 4f1b576cae6..98b37386a3f 100644 --- a/src/server/game/Instances/InstanceSaveMgr.h +++ b/src/server/game/Instances/InstanceSaveMgr.h @@ -19,12 +19,12 @@ #ifndef _INSTANCESAVEMGR_H #define _INSTANCESAVEMGR_H -#include "Define.h" -#include -#include #include #include +#include #include + +#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 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 ResetTimeByMapDifficultyMap; class InstanceSaveManager { - friend class ACE_Singleton; friend class InstanceSave; private: @@ -154,6 +158,12 @@ class InstanceSaveManager public: typedef std::unordered_map 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::instance() +#define sInstanceSaveMgr InstanceSaveManager::instance() #endif diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index ba271235330..96c784cc9d9 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -382,7 +382,7 @@ void Map::DeleteFromWorld(Player* player) void Map::EnsureGridCreated(const GridCoord &p) { - TRINITY_GUARD(ACE_Thread_Mutex, GridLock); + std::lock_guard 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 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 lock(_mapLock); //Check moved to void WorldSession::HandleMoveWorldportAckOpcode() //if (!CanEnter(player)) //return false; diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index a2d88905f50..27c290264b2 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -574,8 +574,8 @@ class Map : public GridRefManager 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; diff --git a/src/server/game/Maps/MapInstanced.cpp b/src/server/game/Maps/MapInstanced.cpp index e914a5c3eee..498c669ba01 100644 --- a/src/server/game/Maps/MapInstanced.cpp +++ b/src/server/game/Maps/MapInstanced.cpp @@ -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 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 lock(_mapLock); TC_LOG_DEBUG("maps", "MapInstanced::CreateBattleground: map bg %d for %d created.", InstanceId, GetId()); diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp index d8c8889da67..2b8dbde8280 100644 --- a/src/server/game/Maps/MapManager.cpp +++ b/src/server/game/Maps/MapManager.cpp @@ -68,7 +68,7 @@ Map* MapManager::CreateBaseMap(uint32 id) if (map == NULL) { - TRINITY_GUARD(ACE_Thread_Mutex, Lock); + std::lock_guard 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 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 lock(_mapsLock); uint32 ret = 0; for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr) diff --git a/src/server/game/Maps/MapManager.h b/src/server/game/Maps/MapManager.h index b7fb0617a46..91becb88dfe 100644 --- a/src/server/game/Maps/MapManager.h +++ b/src/server/game/Maps/MapManager.h @@ -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; diff --git a/src/server/game/Maps/MapUpdater.cpp b/src/server/game/Maps/MapUpdater.cpp index f3a5a66bf66..c2d8123c2d2 100644 --- a/src/server/game/Maps/MapUpdater.cpp +++ b/src/server/game/Maps/MapUpdater.cpp @@ -1,10 +1,30 @@ +/* +* Copyright (C) 2008-2014 TrinityCore +* Copyright (C) 2005-2009 MaNGOS +* +* 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 . +*/ + +#include +#include +#include + #include "MapUpdater.h" #include "DelayExecutor.h" #include "Map.h" #include "DatabaseEnv.h" -#include -#include 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 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 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 lock(_lock); if (pending_requests == 0) { @@ -121,5 +142,5 @@ void MapUpdater::update_finished() --pending_requests; - m_condition.broadcast(); + _condition.notify_all(); } diff --git a/src/server/game/Maps/MapUpdater.h b/src/server/game/Maps/MapUpdater.h index 89798026339..8461b53e992 100644 --- a/src/server/game/Maps/MapUpdater.h +++ b/src/server/game/Maps/MapUpdater.h @@ -1,8 +1,26 @@ +/* +* Copyright (C) 2008-2014 TrinityCore +* Copyright (C) 2005-2009 MaNGOS +* +* 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 . +*/ + #ifndef _MAP_UPDATER_H_INCLUDED #define _MAP_UPDATER_H_INCLUDED -#include -#include +#include +#include #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(); diff --git a/src/server/game/Server/WorldSocketMgr.cpp b/src/server/game/Server/WorldSocketMgr.cpp index 7880552ffa1..3c1db3551d0 100644 --- a/src/server/game/Server/WorldSocketMgr.cpp +++ b/src/server/game/Server/WorldSocketMgr.cpp @@ -29,13 +29,13 @@ #include #include #include -#include #include #include #include #include #include +#include #include #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 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 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() : diff --git a/src/server/scripts/Commands/cs_gm.cpp b/src/server/scripts/Commands/cs_gm.cpp index a2c0861c113..90fd0bdd71c 100644 --- a/src/server/scripts/Commands/cs_gm.cpp +++ b/src/server/scripts/Commands/cs_gm.cpp @@ -123,7 +123,7 @@ public: bool first = true; bool footer = false; - TRINITY_READ_GUARD(HashMapHolder::LockType, *HashMapHolder::GetLock()); + boost::shared_lock lock(*HashMapHolder::GetLock()); HashMapHolder::MapType const& m = sObjectAccessor->GetPlayers(); for (HashMapHolder::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) { diff --git a/src/server/scripts/Commands/cs_reset.cpp b/src/server/scripts/Commands/cs_reset.cpp index d61c36c887f..279f9c2ef4c 100644 --- a/src/server/scripts/Commands/cs_reset.cpp +++ b/src/server/scripts/Commands/cs_reset.cpp @@ -297,7 +297,7 @@ public: stmt->setUInt16(0, uint16(atLogin)); CharacterDatabase.Execute(stmt); - TRINITY_READ_GUARD(HashMapHolder::LockType, *HashMapHolder::GetLock()); + boost::shared_lock lock(*HashMapHolder::GetLock()); HashMapHolder::MapType const& plist = sObjectAccessor->GetPlayers(); for (HashMapHolder::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr) itr->second->SetAtLoginFlag(atLogin); diff --git a/src/server/shared/Common.h b/src/server/shared/Common.h index 14cc6533a68..a7bc3acd1e5 100644 --- a/src/server/shared/Common.h +++ b/src/server/shared/Common.h @@ -84,9 +84,6 @@ #include "Threading/LockedQueue.h" #include "Threading/Threading.h" -#include -#include -#include #include #if PLATFORM == PLATFORM_WINDOWS @@ -188,20 +185,4 @@ typedef std::vector 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 diff --git a/src/server/shared/Threading/LockedQueue.h b/src/server/shared/Threading/LockedQueue.h index 3ca2a5cd45c..93225496df3 100644 --- a/src/server/shared/Threading/LockedQueue.h +++ b/src/server/shared/Threading/LockedQueue.h @@ -22,8 +22,6 @@ #include #include - - template > class LockedQueue { -- cgit v1.2.3 From fdd5e11a15a4e635bb1298c3d4c4b3c9e718e6b0 Mon Sep 17 00:00:00 2001 From: leak Date: Sun, 8 Jun 2014 16:05:23 +0200 Subject: Fix for LockedQueue.h (clean rebuilds ftw.) --- src/server/shared/Threading/LockedQueue.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/server/shared/Threading/LockedQueue.h') diff --git a/src/server/shared/Threading/LockedQueue.h b/src/server/shared/Threading/LockedQueue.h index 93225496df3..bbd60cb7760 100644 --- a/src/server/shared/Threading/LockedQueue.h +++ b/src/server/shared/Threading/LockedQueue.h @@ -103,17 +103,15 @@ public: //! Cancels the queue. void cancel() { - lock(); + std::lock_guard lock(_lock); _canceled = true; - - unlock(); } //! Checks if the queue is cancelled. bool cancelled() { - ACE_Guard g(this->_lock); + std::lock_guard lock(_lock); return _canceled; } -- cgit v1.2.3