mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-11 05:52:19 +02:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user