From e13d75a50299f52efa317eb3177187b2b00be190 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 24 Jun 2019 17:12:46 +0200 Subject: [PATCH] move mutex closer to guard call Signed-off-by: Deukhoofd --- src/UserData/UserDataStorage.cpp | 1 + src/UserData/UserDataStorage.hpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/UserData/UserDataStorage.cpp b/src/UserData/UserDataStorage.cpp index 466ae94..73bc099 100644 --- a/src/UserData/UserDataStorage.cpp +++ b/src/UserData/UserDataStorage.cpp @@ -3,4 +3,5 @@ namespace Porygon::UserData { UserDataStorage::_internalDataStorage UserDataStorage::_internal = UserDataStorage::_internalDataStorage(); + std::mutex UserDataStorage::_userDataMutex = std::mutex(); } \ No newline at end of file diff --git a/src/UserData/UserDataStorage.hpp b/src/UserData/UserDataStorage.hpp index a206c0a..c7bd012 100644 --- a/src/UserData/UserDataStorage.hpp +++ b/src/UserData/UserDataStorage.hpp @@ -12,7 +12,6 @@ namespace Porygon::UserData { class _internalDataStorage { public: std::unordered_map _userData; - std::mutex _userDataMutex; ~_internalDataStorage(){ for (auto u: _userData){ @@ -28,15 +27,16 @@ namespace Porygon::UserData { }; static _internalDataStorage _internal; + static std::mutex _userDataMutex; public: static void RegisterType(uint32_t i, UserData *ud) { - std::lock_guard guard(_internal._userDataMutex); + std::lock_guard guard(_userDataMutex); UserDataStorage::_internal._userData.insert({i, ud}); } static void ClearTypes(){ - std::lock_guard guard(_internal._userDataMutex); + std::lock_guard guard(_userDataMutex); for (auto u: _internal._userData){ delete u.second; }