aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Maps
diff options
context:
space:
mode:
authorleak <leak@bitmx.net>2014-06-08 15:30:57 +0200
committerleak <leak@bitmx.net>2014-06-08 15:30:57 +0200
commitee4a3b9d59867a2440f8eb35f96405e5c4f6fe28 (patch)
treee6b3bb0b141565d8c0593e053466b8ccc629e93c /src/server/game/Maps
parent0fa3a4923efb492a71f888e256348148fdd73d80 (diff)
Replaced mutex related code in Common.h
Diffstat (limited to 'src/server/game/Maps')
-rw-r--r--src/server/game/Maps/Map.cpp6
-rw-r--r--src/server/game/Maps/Map.h4
-rw-r--r--src/server/game/Maps/MapInstanced.cpp4
-rw-r--r--src/server/game/Maps/MapManager.cpp6
-rw-r--r--src/server/game/Maps/MapManager.h2
-rw-r--r--src/server/game/Maps/MapUpdater.cpp39
-rw-r--r--src/server/game/Maps/MapUpdater.h26
7 files changed, 63 insertions, 24 deletions
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<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;
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<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;
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<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());
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<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)
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 <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();
}
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 <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();