summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Config/Config.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2020-12-29 19:46:41 +0100
committerLéo Lam <leo@leolam.fr>2020-12-29 22:07:47 +0100
commit9ffd345df03853cd37a392f2f19dc7bac889158e (patch)
treeb44db1a08e5909e1bbcde52a041d194954bd413e /Source/Core/Common/Config/Config.cpp
parent351fb71653c7e3db3630fe55692aa688928a4f54 (diff)
Config: Fix cache not being invalidated when callbacks are suppressed
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.
Diffstat (limited to 'Source/Core/Common/Config/Config.cpp')
-rw-r--r--Source/Core/Common/Config/Config.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Source/Core/Common/Config/Config.cpp b/Source/Core/Common/Config/Config.cpp
index 071d009b51..c75b6ee5e9 100644
--- a/Source/Core/Common/Config/Config.cpp
+++ b/Source/Core/Common/Config/Config.cpp
@@ -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();
}