Thread safety for FanncyZonesData (#1281)

* FancyZones: make FancyZonesData thread-safe

* fixup: format affected sources

* fixup: clang-format case-style and format FancyZones.cpp

* fixup! add missing lock
This commit is contained in:
Andrey Nekrasov
2020-02-17 18:28:49 +03:00
committed by GitHub
parent cdf2f6b5b4
commit 1e6936a8c3
10 changed files with 1631 additions and 1533 deletions

View File

@@ -2,6 +2,7 @@
#include <common/settings_helpers.h>
#include <common/json.h>
#include <mutex>
#include <string>
#include <strsafe.h>
@@ -159,12 +160,28 @@ namespace JSONHelpers
class FancyZonesData
{
mutable std::recursive_mutex dataLock;
public:
FancyZonesData();
const std::wstring& GetPersistFancyZonesJSONPath() const;
inline const std::wstring& GetPersistFancyZonesJSONPath() const
{
return jsonFilePath;
}
json::JsonObject GetPersistFancyZonesJSON();
std::optional<DeviceInfoData> FindDeviceInfo(const std::wstring& zoneWindowId) const;
std::optional<CustomZoneSetData> FindCustomZoneSet(const std::wstring& guuid) const;
inline const std::wstring GetActiveDeviceId() const
{
std::scoped_lock lock{ dataLock };
return activeDeviceId;
}
#if defined(UNIT_TESTS)
inline const std::unordered_map<std::wstring, DeviceInfoData>& GetDeviceInfoMap() const
{
return deviceInfoMap;
@@ -180,13 +197,19 @@ namespace JSONHelpers
return appZoneHistoryMap;
}
inline const std::wstring GetActiveDeviceId() const
inline void clear_data()
{
return activeDeviceId;
appliedZoneSetsMap.clear();
appZoneHistoryMap.clear();
deviceInfoMap.clear();
customZoneSetsMap.clear();
activeDeviceId.clear();
}
#endif
void SetActiveDeviceId(const std::wstring& deviceId)
inline void SetActiveDeviceId(const std::wstring& deviceId)
{
std::scoped_lock lock{ dataLock };
activeDeviceId = deviceId;
}