mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
Common/Config: Add a utility class to suppress config change callbacks.
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user