Skip to content

Commit

Permalink
Config: Fix cache not being invalidated when callbacks are suppressed
Browse files Browse the repository at this point in the history
The config version should always be incremented whenever config is
changed, regardless of callbacks being suppressed or not.
Otherwise, getters can return stale data until another config change
(with callbacks enabled) happens.
  • Loading branch information
leoetlino committed Dec 29, 2020
1 parent 351fb71 commit 9ffd345
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Source/Core/Common/Config/Config.cpp
Expand Up @@ -71,11 +71,14 @@ void AddConfigChangedCallback(ConfigChangedCallback func)

void OnConfigChanged()
{
// Increment the config version to invalidate caches.
// To ensure that getters do not return stale data, this should always be done
// even when callbacks are suppressed.
s_config_version.fetch_add(1, std::memory_order_relaxed);

if (s_callback_guards)
return;

s_config_version.fetch_add(1, std::memory_order_relaxed);

for (const auto& callback : s_callbacks)
callback();
}
Expand Down

0 comments on commit 9ffd345

Please sign in to comment.