From 2b17e89336ed09db7298ca66a7c697a4db9d3cf9 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 16 Aug 2023 22:16:50 +0200 Subject: Config: Don't clear callbacks on shutdown This fixes a problem that started happening in CoreTimingTest after the previous commit. CPUThreadConfigCallback registers a Config callback only once per run of the process, but CoreTimingTest calls Config::Shutdown after each test, and Config::Shutdown was clearing all callbacks, preventing the callback from running after that. --- Source/Core/Common/Config/Config.cpp | 1 - 1 file changed, 1 deletion(-) (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 ff3a8c6783..4db249d8eb 100644 --- a/Source/Core/Common/Config/Config.cpp +++ b/Source/Core/Common/Config/Config.cpp @@ -138,7 +138,6 @@ void Shutdown() WriteLock lock(s_layers_rw_lock); s_layers.clear(); - s_callbacks.clear(); } void ClearCurrentRunLayer() -- cgit v1.2.3 From 7197e3abd0831e0d551fd3b2cd7e3346ce04bc68 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 16 Aug 2023 21:37:12 +0200 Subject: Use structs for config callback IDs This way you can't mix up regular config callback IDs and CPU thread config callback IDs. (It would be rather bad if you did!) --- Source/Core/Common/Config/Config.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (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 4db249d8eb..3f008fc913 100644 --- a/Source/Core/Common/Config/Config.cpp +++ b/Source/Core/Common/Config/Config.cpp @@ -16,7 +16,7 @@ namespace Config using Layers = std::map>; static Layers s_layers; -static std::vector> s_callbacks; +static std::vector> s_callbacks; static size_t s_next_callback_id = 0; static u32 s_callback_guards = 0; static std::atomic s_config_version = 0; @@ -65,15 +65,15 @@ void RemoveLayer(LayerType layer) OnConfigChanged(); } -size_t AddConfigChangedCallback(ConfigChangedCallback func) +ConfigChangedCallbackID AddConfigChangedCallback(ConfigChangedCallback func) { - const size_t callback_id = s_next_callback_id; + const ConfigChangedCallbackID callback_id{s_next_callback_id}; ++s_next_callback_id; s_callbacks.emplace_back(std::make_pair(callback_id, std::move(func))); return callback_id; } -void RemoveConfigChangedCallback(size_t callback_id) +void RemoveConfigChangedCallback(ConfigChangedCallbackID callback_id) { for (auto it = s_callbacks.begin(); it != s_callbacks.end(); ++it) { -- cgit v1.2.3