diff options
| author | Mat M <mathew1800@gmail.com> | 2019-03-03 18:44:34 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-03 18:44:34 -0500 |
| commit | 503b96c617997ccd2105481f6833e583b9905991 (patch) | |
| tree | cf0c81cb333e166aa7493ea5eca3028fb76f5076 /Source/Core/Common/Config/Config.cpp | |
| parent | 2eb9140e07d253a584bca91638e843e654c74c08 (diff) | |
| parent | bbc6bf5294f829d62ef61244c315c2886c54c790 (diff) | |
Merge pull request #7848 from jordan-woyak/config-change-callbacks
Common/Config: Add a utility class to defer config change callbacks.
Diffstat (limited to 'Source/Core/Common/Config/Config.cpp')
| -rw-r--r-- | Source/Core/Common/Config/Config.cpp | 18 |
1 files changed, 18 insertions, 0 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 |
