From bbc6bf5294f829d62ef61244c315c2886c54c790 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2019 10:58:37 -0600 Subject: Common/Config: Add a utility class to suppress config change callbacks. --- Source/Core/Common/Config/Config.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Source/Core/Common/Config/Config.cpp') 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 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 -- cgit v1.2.3