mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Misc: Replace boost::shared_mutex with std::shared_mutex (#24328)
* Core/Misc: Replace boost::shared_mutex with std::shared_mutex
* Remove std forward declarations
(cherry picked from commit 7032ee0bdb)
This commit is contained in:
@@ -30,9 +30,6 @@
|
||||
#include "Transport.h"
|
||||
#include "World.h"
|
||||
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
|
||||
template<class T>
|
||||
void HashMapHolder<T>::Insert(T* o)
|
||||
{
|
||||
@@ -40,7 +37,7 @@ void HashMapHolder<T>::Insert(T* o)
|
||||
|| std::is_same<Transport, T>::value,
|
||||
"Only Player and Transport can be registered in global HashMapHolder");
|
||||
|
||||
boost::unique_lock<boost::shared_mutex> lock(*GetLock());
|
||||
std::unique_lock<std::shared_mutex> lock(*GetLock());
|
||||
|
||||
GetContainer()[o->GetGUID()] = o;
|
||||
}
|
||||
@@ -48,7 +45,7 @@ void HashMapHolder<T>::Insert(T* o)
|
||||
template<class T>
|
||||
void HashMapHolder<T>::Remove(T* o)
|
||||
{
|
||||
boost::unique_lock<boost::shared_mutex> lock(*GetLock());
|
||||
std::unique_lock<std::shared_mutex> lock(*GetLock());
|
||||
|
||||
GetContainer().erase(o->GetGUID());
|
||||
}
|
||||
@@ -56,7 +53,7 @@ void HashMapHolder<T>::Remove(T* o)
|
||||
template<class T>
|
||||
T* HashMapHolder<T>::Find(ObjectGuid guid)
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(*GetLock());
|
||||
std::shared_lock<std::shared_mutex> lock(*GetLock());
|
||||
|
||||
typename MapType::iterator itr = GetContainer().find(guid);
|
||||
return (itr != GetContainer().end()) ? itr->second : nullptr;
|
||||
@@ -70,9 +67,9 @@ auto HashMapHolder<T>::GetContainer() -> MapType&
|
||||
}
|
||||
|
||||
template<class T>
|
||||
boost::shared_mutex* HashMapHolder<T>::GetLock()
|
||||
std::shared_mutex* HashMapHolder<T>::GetLock()
|
||||
{
|
||||
static boost::shared_mutex _lock;
|
||||
static std::shared_mutex _lock;
|
||||
return &_lock;
|
||||
}
|
||||
|
||||
@@ -299,7 +296,7 @@ HashMapHolder<Player>::MapType const& ObjectAccessor::GetPlayers()
|
||||
|
||||
void ObjectAccessor::SaveAllPlayers()
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(*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)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define TRINITY_OBJECTACCESSOR_H
|
||||
|
||||
#include "ObjectGuid.h"
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
class AreaTrigger;
|
||||
@@ -36,11 +37,6 @@ class Transport;
|
||||
class Unit;
|
||||
class WorldObject;
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class shared_mutex;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class TC_GAME_API HashMapHolder
|
||||
{
|
||||
@@ -59,7 +55,7 @@ public:
|
||||
|
||||
static MapType& GetContainer();
|
||||
|
||||
static boost::shared_mutex* GetLock();
|
||||
static std::shared_mutex* GetLock();
|
||||
};
|
||||
|
||||
namespace ObjectAccessor
|
||||
|
||||
@@ -54,8 +54,6 @@
|
||||
#include "WhoPackets.h"
|
||||
#include "World.h"
|
||||
#include "WorldPacket.h"
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <cstdarg>
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
@@ -23,10 +23,7 @@
|
||||
#include "LootMgr.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace
|
||||
@@ -46,9 +43,9 @@ LootItemStorage* LootItemStorage::instance()
|
||||
return &instance;
|
||||
}
|
||||
|
||||
boost::shared_mutex* LootItemStorage::GetLock()
|
||||
std::shared_mutex* LootItemStorage::GetLock()
|
||||
{
|
||||
static boost::shared_mutex _lock;
|
||||
static std::shared_mutex _lock;
|
||||
return &_lock;
|
||||
}
|
||||
|
||||
@@ -144,7 +141,7 @@ bool LootItemStorage::LoadStoredLoot(Item* item, Player* player)
|
||||
|
||||
// read
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(*GetLock());
|
||||
std::shared_lock<std::shared_mutex> lock(*GetLock());
|
||||
|
||||
auto itr = _lootItemStore.find(loot->containerID.GetCounter());
|
||||
if (itr == _lootItemStore.end())
|
||||
@@ -196,7 +193,7 @@ bool LootItemStorage::LoadStoredLoot(Item* item, Player* player)
|
||||
void LootItemStorage::RemoveStoredMoneyForContainer(uint64 containerId)
|
||||
{
|
||||
// write
|
||||
boost::unique_lock<boost::shared_mutex> lock(*GetLock());
|
||||
std::unique_lock<std::shared_mutex> lock(*GetLock());
|
||||
|
||||
auto itr = _lootItemStore.find(containerId);
|
||||
if (itr == _lootItemStore.end())
|
||||
@@ -209,7 +206,7 @@ void LootItemStorage::RemoveStoredLootForContainer(uint64 containerId)
|
||||
{
|
||||
// write
|
||||
{
|
||||
boost::unique_lock<boost::shared_mutex> lock(*GetLock());
|
||||
std::unique_lock<std::shared_mutex> lock(*GetLock());
|
||||
_lootItemStore.erase(containerId);
|
||||
}
|
||||
|
||||
@@ -228,7 +225,7 @@ void LootItemStorage::RemoveStoredLootForContainer(uint64 containerId)
|
||||
void LootItemStorage::RemoveStoredLootItemForContainer(uint64 containerId, uint32 itemId, uint32 count)
|
||||
{
|
||||
// write
|
||||
boost::unique_lock<boost::shared_mutex> lock(*GetLock());
|
||||
std::unique_lock<std::shared_mutex> lock(*GetLock());
|
||||
|
||||
auto itr = _lootItemStore.find(containerId);
|
||||
if (itr == _lootItemStore.end())
|
||||
@@ -245,7 +242,7 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* player)
|
||||
|
||||
// read
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(*GetLock());
|
||||
std::shared_lock<std::shared_mutex> lock(*GetLock());
|
||||
|
||||
auto itr = _lootItemStore.find(loot->containerID.GetCounter());
|
||||
if (itr != _lootItemStore.end())
|
||||
@@ -287,7 +284,7 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* player)
|
||||
|
||||
// write
|
||||
{
|
||||
boost::unique_lock<boost::shared_mutex> lock(*GetLock());
|
||||
std::unique_lock<std::shared_mutex> lock(*GetLock());
|
||||
_lootItemStore.emplace(loot->containerID.GetCounter(), std::move(container));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "DBCEnums.h"
|
||||
#include "ItemEnchantmentMgr.h"
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -31,11 +32,6 @@ class Player;
|
||||
struct Loot;
|
||||
struct LootItem;
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class shared_mutex;
|
||||
}
|
||||
|
||||
struct StoredLootItem
|
||||
{
|
||||
explicit StoredLootItem(LootItem const& lootItem);
|
||||
@@ -80,7 +76,7 @@ class LootItemStorage
|
||||
{
|
||||
public:
|
||||
static LootItemStorage* instance();
|
||||
static boost::shared_mutex* GetLock();
|
||||
static std::shared_mutex* GetLock();
|
||||
|
||||
void LoadStorageFromDB();
|
||||
bool LoadStoredLoot(Item* item, Player* player);
|
||||
|
||||
@@ -23,10 +23,8 @@
|
||||
#include "WardenCheckMgr.h"
|
||||
#include "Warden.h"
|
||||
#include "World.h"
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
WardenCheckMgr::WardenCheckMgr() : _checkStoreLock(new boost::shared_mutex())
|
||||
WardenCheckMgr::WardenCheckMgr()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -37,8 +35,6 @@ WardenCheckMgr::~WardenCheckMgr()
|
||||
|
||||
for (CheckResultContainer::iterator itr = CheckResultStore.begin(); itr != CheckResultStore.end(); ++itr)
|
||||
delete itr->second;
|
||||
|
||||
delete _checkStoreLock;
|
||||
}
|
||||
|
||||
void WardenCheckMgr::LoadWardenChecks()
|
||||
@@ -151,7 +147,7 @@ void WardenCheckMgr::LoadWardenOverrides()
|
||||
|
||||
uint32 count = 0;
|
||||
|
||||
boost::unique_lock<boost::shared_mutex> lock(*sWardenCheckMgr->_checkStoreLock);
|
||||
std::unique_lock<std::shared_mutex> lock(sWardenCheckMgr->_checkStoreLock);
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "Cryptography/BigNumber.h"
|
||||
#include <map>
|
||||
#include <shared_mutex>
|
||||
|
||||
enum WardenActions
|
||||
{
|
||||
@@ -28,11 +29,6 @@ enum WardenActions
|
||||
WARDEN_ACTION_BAN
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class shared_mutex;
|
||||
}
|
||||
|
||||
struct WardenCheck
|
||||
{
|
||||
uint8 Type;
|
||||
@@ -72,7 +68,7 @@ class TC_GAME_API WardenCheckMgr
|
||||
void LoadWardenChecks();
|
||||
void LoadWardenOverrides();
|
||||
|
||||
boost::shared_mutex* _checkStoreLock;
|
||||
std::shared_mutex _checkStoreLock;
|
||||
|
||||
private:
|
||||
CheckContainer CheckStore;
|
||||
|
||||
@@ -33,9 +33,8 @@
|
||||
#include "World.h"
|
||||
#include "WorldPacket.h"
|
||||
#include "WorldSession.h"
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <openssl/md5.h>
|
||||
#include <sstream>
|
||||
|
||||
WardenWin::WardenWin() : Warden(), _serverTicks(0) {}
|
||||
|
||||
@@ -209,7 +208,7 @@ void WardenWin::RequestData()
|
||||
ByteBuffer buff;
|
||||
buff << uint8(WARDEN_SMSG_CHEAT_CHECKS_REQUEST);
|
||||
|
||||
boost::shared_lock<boost::shared_mutex> lock(*sWardenCheckMgr->_checkStoreLock);
|
||||
std::shared_lock<std::shared_mutex> lock(sWardenCheckMgr->_checkStoreLock);
|
||||
|
||||
for (uint32 i = 0; i < sWorld->getIntConfig(CONFIG_WARDEN_NUM_OTHER_CHECKS); ++i)
|
||||
{
|
||||
@@ -371,7 +370,7 @@ void WardenWin::HandleData(ByteBuffer &buff)
|
||||
uint8 type;
|
||||
uint16 checkFailed = 0;
|
||||
|
||||
boost::shared_lock<boost::shared_mutex> lock(*sWardenCheckMgr->_checkStoreLock);
|
||||
std::shared_lock<std::shared_mutex> lock(sWardenCheckMgr->_checkStoreLock);
|
||||
|
||||
for (std::list<uint16>::iterator itr = _currentChecks.begin(); itr != _currentChecks.end(); ++itr)
|
||||
{
|
||||
|
||||
@@ -33,8 +33,6 @@ EndScriptData */
|
||||
#include "Realm.h"
|
||||
#include "World.h"
|
||||
#include "WorldSession.h"
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
class gm_commandscript : public CommandScript
|
||||
{
|
||||
@@ -129,7 +127,7 @@ public:
|
||||
bool first = true;
|
||||
bool footer = false;
|
||||
|
||||
boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
||||
std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
||||
HashMapHolder<Player>::MapType const& m = ObjectAccessor::GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
{
|
||||
|
||||
@@ -35,8 +35,6 @@ EndScriptData */
|
||||
#include "RBAC.h"
|
||||
#include "World.h"
|
||||
#include "WorldSession.h"
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
class reset_commandscript : public CommandScript
|
||||
{
|
||||
@@ -300,7 +298,7 @@ public:
|
||||
stmt->setUInt16(0, uint16(atLogin));
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
||||
std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
||||
HashMapHolder<Player>::MapType const& plist = ObjectAccessor::GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
|
||||
itr->second->SetAtLoginFlag(atLogin);
|
||||
|
||||
@@ -29,13 +29,10 @@
|
||||
#include "game_utilities_service.pb.h"
|
||||
#include "RealmList.pb.h"
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <zlib.h>
|
||||
|
||||
RealmList::RealmList() : _updateInterval(0)
|
||||
{
|
||||
_realmsMutex = std::make_unique<boost::shared_mutex>();
|
||||
}
|
||||
|
||||
RealmList::~RealmList() = default;
|
||||
@@ -211,7 +208,7 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
|
||||
TC_LOG_INFO("realmlist", "Removed realm \"%s\".", itr->second.c_str());
|
||||
|
||||
{
|
||||
std::unique_lock<boost::shared_mutex> lock(*_realmsMutex);
|
||||
std::unique_lock<std::shared_mutex> lock(_realmsMutex);
|
||||
|
||||
_subRegions.swap(newSubRegions);
|
||||
_realms.swap(newRealms);
|
||||
@@ -226,7 +223,7 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
|
||||
|
||||
Realm const* RealmList::GetRealm(Battlenet::RealmHandle const& id) const
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(*_realmsMutex);
|
||||
std::shared_lock<std::shared_mutex> lock(_realmsMutex);
|
||||
auto itr = _realms.find(id);
|
||||
if (itr != _realms.end())
|
||||
return &itr->second;
|
||||
@@ -254,7 +251,7 @@ uint32 RealmList::GetMinorMajorBugfixVersionForBuild(uint32 build) const
|
||||
|
||||
void RealmList::WriteSubRegions(bgs::protocol::game_utilities::v1::GetAllValuesForAttributeResponse* response) const
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(*_realmsMutex);
|
||||
std::shared_lock<std::shared_mutex> lock(_realmsMutex);
|
||||
for (std::string const& subRegion : _subRegions)
|
||||
response->add_attribute_value()->set_string_value(subRegion);
|
||||
}
|
||||
@@ -262,7 +259,7 @@ void RealmList::WriteSubRegions(bgs::protocol::game_utilities::v1::GetAllValuesF
|
||||
std::vector<uint8> RealmList::GetRealmEntryJSON(Battlenet::RealmHandle const& id, uint32 build) const
|
||||
{
|
||||
std::vector<uint8> compressed;
|
||||
boost::shared_lock<boost::shared_mutex> lock(*_realmsMutex);
|
||||
std::shared_lock<std::shared_mutex> lock(_realmsMutex);
|
||||
if (Realm const* realm = GetRealm(id))
|
||||
{
|
||||
if (!(realm->Flags & REALM_FLAG_OFFLINE) && realm->Build == build)
|
||||
@@ -317,7 +314,7 @@ std::vector<uint8> RealmList::GetRealmList(uint32 build, std::string const& subR
|
||||
{
|
||||
JSON::RealmList::RealmListUpdates realmList;
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(*_realmsMutex);
|
||||
std::shared_lock<std::shared_mutex> lock(_realmsMutex);
|
||||
for (auto const& realm : _realms)
|
||||
{
|
||||
if (realm.second.Id.GetSubRegionAddress() != subRegion)
|
||||
@@ -376,7 +373,7 @@ std::vector<uint8> RealmList::GetRealmList(uint32 build, std::string const& subR
|
||||
uint32 RealmList::JoinRealm(uint32 realmAddress, uint32 build, boost::asio::ip::address const& clientAddress, std::array<uint8, 32> const& clientSecret,
|
||||
LocaleConstant locale, std::string const& os, std::string accountName, bgs::protocol::game_utilities::v1::ClientResponse* response) const
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(*_realmsMutex);
|
||||
std::shared_lock<std::shared_mutex> lock(_realmsMutex);
|
||||
if (Realm const* realm = GetRealm(Battlenet::RealmHandle(realmAddress)))
|
||||
{
|
||||
if (realm->Flags & REALM_FLAG_OFFLINE || realm->Build != build)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "Realm.h"
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <shared_mutex>
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -38,8 +39,6 @@ struct RealmBuildInfo
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class shared_mutex;
|
||||
|
||||
namespace system
|
||||
{
|
||||
class error_code;
|
||||
@@ -102,7 +101,7 @@ private:
|
||||
uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population);
|
||||
|
||||
std::vector<RealmBuildInfo> _builds;
|
||||
std::unique_ptr<boost::shared_mutex> _realmsMutex;
|
||||
mutable std::shared_mutex _realmsMutex;
|
||||
RealmMap _realms;
|
||||
std::unordered_set<std::string> _subRegions;
|
||||
uint32 _updateInterval;
|
||||
|
||||
Reference in New Issue
Block a user