diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2019-03-03 10:58:37 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2019-03-03 17:35:22 -0600 |
| commit | bbc6bf5294f829d62ef61244c315c2886c54c790 (patch) | |
| tree | 05a576e2923dfc842bd8a38e17a1fd762618bd3b /Source/Core/Common/Config | |
| parent | 2a3c0753303a9f4cd79a92cd94b6a22298b516d6 (diff) | |
Common/Config: Add a utility class to suppress config change callbacks.
Diffstat (limited to 'Source/Core/Common/Config')
| -rw-r--r-- | Source/Core/Common/Config/Config.cpp | 18 | ||||
| -rw-r--r-- | Source/Core/Common/Config/Config.h | 13 |
2 files changed, 30 insertions, 1 deletions
diff --git a/Source/Core/Common/Config/Config.cpp b/Source/Core/Common/Config/Config.cpp index 30215aec06..122d2d6ff1 100644 --- a/Source/Core/Common/Config/Config.cpp +++ b/Source/Core/Common/Config/Config.cpp @@ -12,6 +12,7 @@ namespace Config { static Layers s_layers; static std::list<ConfigChangedCallback> s_callbacks; +static u32 s_callback_guards = 0; Layers* GetLayers() { @@ -53,6 +54,9 @@ void AddConfigChangedCallback(ConfigChangedCallback func) void InvokeConfigChangedCallbacks() { + if (s_callback_guards) + return; + for (const auto& callback : s_callbacks) callback(); } @@ -137,4 +141,18 @@ LayerType GetActiveLayerForConfig(const ConfigLocation& config) // If config is not present in any layer, base layer is considered active. return LayerType::Base; } + +ConfigChangeCallbackGuard::ConfigChangeCallbackGuard() +{ + ++s_callback_guards; } + +ConfigChangeCallbackGuard::~ConfigChangeCallbackGuard() +{ + if (--s_callback_guards) + return; + + InvokeConfigChangedCallbacks(); +} + +} // namespace Config diff --git a/Source/Core/Common/Config/Config.h b/Source/Core/Common/Config/Config.h index 1418a86606..4120d029ba 100644 --- a/Source/Core/Common/Config/Config.h +++ b/Source/Core/Common/Config/Config.h @@ -96,4 +96,15 @@ void SetBaseOrCurrent(const ConfigInfo<T>& info, const std::common_type_t<T>& va else Set<T>(LayerType::CurrentRun, info, value); } -} + +// Used to defer InvokeConfigChangedCallbacks until after the completion of many config changes. +class ConfigChangeCallbackGuard +{ +public: + ConfigChangeCallbackGuard(); + ~ConfigChangeCallbackGuard(); + + ConfigChangeCallbackGuard(const ConfigChangeCallbackGuard&) = delete; + ConfigChangeCallbackGuard& operator=(const ConfigChangeCallbackGuard&) = delete; +}; +} // namespace Config |
