mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Misc: Use std::scoped_lock instead of unique_lock where possible (and old lock_guard)
This commit is contained in:
@@ -187,7 +187,7 @@ void RealmList::UpdateRealms()
|
||||
TC_LOG_INFO("realmlist", "Removed realm \"{}\".", itr->second);
|
||||
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(_realmsMutex);
|
||||
std::scoped_lock lock(_realmsMutex);
|
||||
|
||||
_subRegions.swap(newSubRegions);
|
||||
_realms.swap(newRealms);
|
||||
@@ -213,7 +213,7 @@ void RealmList::UpdateRealms()
|
||||
|
||||
std::shared_ptr<Realm const> RealmList::GetRealm(Battlenet::RealmHandle const& id) const
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(_realmsMutex);
|
||||
std::shared_lock lock(_realmsMutex);
|
||||
return Trinity::Containers::MapGetValuePtr(_realms, id);
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ std::shared_ptr<Realm const> RealmList::GetCurrentRealm() const
|
||||
|
||||
void RealmList::WriteSubRegions(bgs::protocol::game_utilities::v1::GetAllValuesForAttributeResponse* response) const
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(_realmsMutex);
|
||||
std::shared_lock lock(_realmsMutex);
|
||||
for (std::string const& subRegion : _subRegions)
|
||||
response->add_attribute_value()->set_string_value(subRegion);
|
||||
}
|
||||
@@ -301,7 +301,7 @@ std::vector<uint8> RealmList::GetRealmList(uint32 build, AccountTypes accountSec
|
||||
{
|
||||
JSON::RealmList::RealmListUpdates realmList;
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(_realmsMutex);
|
||||
std::shared_lock lock(_realmsMutex);
|
||||
for (auto const& [_, realm] : _realms)
|
||||
{
|
||||
if (realm->Id.GetSubRegionAddress() != subRegion)
|
||||
|
||||
@@ -93,7 +93,7 @@ void SecretMgr::Initialize(SecretOwner owner)
|
||||
{
|
||||
if (secret_info[i].flags() & SECRET_FLAG_DEFER_LOAD)
|
||||
continue;
|
||||
std::unique_lock<std::mutex> lock(_secrets[i].lock);
|
||||
std::scoped_lock lock(_secrets[i].lock);
|
||||
AttemptLoad(Secrets(i), LOG_LEVEL_FATAL, lock);
|
||||
if (!_secrets[i].IsAvailable())
|
||||
ABORT(); // load failed
|
||||
@@ -102,14 +102,14 @@ void SecretMgr::Initialize(SecretOwner owner)
|
||||
|
||||
SecretMgr::Secret const& SecretMgr::GetSecret(Secrets i)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_secrets[i].lock);
|
||||
std::scoped_lock lock(_secrets[i].lock);
|
||||
|
||||
if (_secrets[i].state == Secret::NOT_LOADED_YET)
|
||||
AttemptLoad(i, LOG_LEVEL_ERROR, lock);
|
||||
return _secrets[i];
|
||||
}
|
||||
|
||||
void SecretMgr::AttemptLoad(Secrets i, LogLevel errorLevel, std::unique_lock<std::mutex> const&)
|
||||
void SecretMgr::AttemptLoad(Secrets i, LogLevel errorLevel, std::scoped_lock<std::mutex> const&)
|
||||
{
|
||||
auto const& info = secret_info[i];
|
||||
Optional<std::string> oldDigest;
|
||||
|
||||
@@ -78,7 +78,7 @@ class TC_SHARED_API SecretMgr
|
||||
Secret const& GetSecret(Secrets i);
|
||||
|
||||
private:
|
||||
void AttemptLoad(Secrets i, LogLevel errorLevel, std::unique_lock<std::mutex> const&);
|
||||
void AttemptLoad(Secrets i, LogLevel errorLevel, std::scoped_lock<std::mutex> const&);
|
||||
Optional<std::string> AttemptTransition(Secrets i, Optional<BigNumber> const& newSecret, Optional<BigNumber> const& oldSecret, bool hadOldSecret) const;
|
||||
|
||||
std::array<Secret, NUM_SECRETS> _secrets;
|
||||
|
||||
Reference in New Issue
Block a user