Common/Config: Add a utility class to suppress config change callbacks.

This commit is contained in:
Jordan Woyak
2019-03-03 10:58:37 -06:00
parent 2a3c075330
commit bbc6bf5294
8 changed files with 42 additions and 1 deletions

View File

@ -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