diff --git a/Source/Core/AudioCommon/Mixer.h b/Source/Core/AudioCommon/Mixer.h index c27ff311c3..5a71f5e8af 100644 --- a/Source/Core/AudioCommon/Mixer.h +++ b/Source/Core/AudioCommon/Mixer.h @@ -10,6 +10,7 @@ #include "AudioCommon/SurroundDecoder.h" #include "AudioCommon/WaveFile.h" #include "Common/CommonTypes.h" +#include "Common/Config/Config.h" class PointerWrap; @@ -120,5 +121,5 @@ private: int m_config_timing_variance; bool m_config_audio_stretch; - size_t m_config_changed_callback_id; + Config::ConfigChangedCallbackID m_config_changed_callback_id; }; 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) { diff --git a/Source/Core/Common/Config/Config.h b/Source/Core/Common/Config/Config.h index 4d770ee36e..1303388566 100644 --- a/Source/Core/Common/Config/Config.h +++ b/Source/Core/Common/Config/Config.h @@ -15,6 +15,14 @@ namespace Config { +struct ConfigChangedCallbackID +{ + size_t id = -1; + + bool operator==(const ConfigChangedCallbackID&) const = default; + bool operator!=(const ConfigChangedCallbackID&) const = default; +}; + using ConfigChangedCallback = std::function; // Layer management @@ -24,8 +32,8 @@ void RemoveLayer(LayerType layer); // Returns an ID that can be passed to RemoveConfigChangedCallback(). // The callback may be called from any thread. -size_t AddConfigChangedCallback(ConfigChangedCallback func); -void RemoveConfigChangedCallback(size_t callback_id); +ConfigChangedCallbackID AddConfigChangedCallback(ConfigChangedCallback func); +void RemoveConfigChangedCallback(ConfigChangedCallbackID callback_id); void OnConfigChanged(); // Returns the number of times the config has changed in the current execution of the program diff --git a/Source/Core/Core/CPUThreadConfigCallback.cpp b/Source/Core/Core/CPUThreadConfigCallback.cpp index 2148630c22..857ba24189 100644 --- a/Source/Core/Core/CPUThreadConfigCallback.cpp +++ b/Source/Core/Core/CPUThreadConfigCallback.cpp @@ -13,7 +13,10 @@ namespace { std::atomic s_should_run_callbacks = false; -static std::vector> s_callbacks; +static std::vector< + std::pair> + s_callbacks; + static size_t s_next_callback_id = 0; void RunCallbacks() @@ -39,19 +42,19 @@ void OnConfigChanged() namespace CPUThreadConfigCallback { -size_t AddConfigChangedCallback(Config::ConfigChangedCallback func) +ConfigChangedCallbackID AddConfigChangedCallback(Config::ConfigChangedCallback func) { DEBUG_ASSERT(Core::IsCPUThread()); - static size_t s_config_changed_callback_id = Config::AddConfigChangedCallback(&OnConfigChanged); + static auto s_config_changed_callback_id = Config::AddConfigChangedCallback(&OnConfigChanged); - 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) { DEBUG_ASSERT(Core::IsCPUThread()); diff --git a/Source/Core/Core/CPUThreadConfigCallback.h b/Source/Core/Core/CPUThreadConfigCallback.h index c43e01a9a0..404e522809 100644 --- a/Source/Core/Core/CPUThreadConfigCallback.h +++ b/Source/Core/Core/CPUThreadConfigCallback.h @@ -11,10 +11,18 @@ namespace CPUThreadConfigCallback { -// returns an ID that can be passed to RemoveConfigChangedCallback() -size_t AddConfigChangedCallback(Config::ConfigChangedCallback func); +struct ConfigChangedCallbackID +{ + size_t id = -1; -void RemoveConfigChangedCallback(size_t callback_id); + bool operator==(const ConfigChangedCallbackID&) const = default; + bool operator!=(const ConfigChangedCallbackID&) const = default; +}; + +// returns an ID that can be passed to RemoveConfigChangedCallback() +ConfigChangedCallbackID AddConfigChangedCallback(Config::ConfigChangedCallback func); + +void RemoveConfigChangedCallback(ConfigChangedCallbackID callback_id); // Should be called regularly from the CPU thread void CheckForConfigChanges(); diff --git a/Source/Core/Core/CoreTiming.h b/Source/Core/Core/CoreTiming.h index 1790dd70ee..6c60b74479 100644 --- a/Source/Core/Core/CoreTiming.h +++ b/Source/Core/Core/CoreTiming.h @@ -23,6 +23,7 @@ #include "Common/CommonTypes.h" #include "Common/SPSCQueue.h" +#include "Core/CPUThreadConfigCallback.h" class PointerWrap; @@ -182,7 +183,7 @@ private: EventType* m_ev_lost = nullptr; - size_t m_registered_config_callback_id = 0; + CPUThreadConfigCallback::ConfigChangedCallbackID m_registered_config_callback_id; float m_config_oc_factor = 0.0f; float m_config_oc_inv_factor = 0.0f; bool m_config_sync_on_skip_idle = false; diff --git a/Source/Core/Core/FifoPlayer/FifoPlayer.h b/Source/Core/Core/FifoPlayer/FifoPlayer.h index 365add85fe..b1cbd7a12d 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlayer.h +++ b/Source/Core/Core/FifoPlayer/FifoPlayer.h @@ -10,6 +10,7 @@ #include #include "Common/Assert.h" +#include "Common/Config/Config.h" #include "Core/FifoPlayer/FifoDataFile.h" #include "Core/PowerPC/CPUCoreBase.h" #include "VideoCommon/CPMemory.h" @@ -189,7 +190,7 @@ private: CallbackFunc m_FileLoadedCb = nullptr; CallbackFunc m_FrameWrittenCb = nullptr; - size_t m_config_changed_callback_id; + Config::ConfigChangedCallbackID m_config_changed_callback_id; std::unique_ptr m_File; diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 580bff8aee..13ef2139f6 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -30,7 +30,7 @@ static std::array s_last_connect_request_counter; namespace { static std::array, MAX_BBMOTES> s_wiimote_sources; -static std::optional s_config_callback_id = std::nullopt; +static std::optional s_config_callback_id = std::nullopt; WiimoteSource GetSource(unsigned int index) { diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index eb45dce496..116e393bf2 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -9,6 +9,7 @@ #include #include "Common/Common.h" +#include "Common/Config/Config.h" #include "Core/HW/WiimoteCommon/WiimoteReport.h" @@ -343,6 +344,6 @@ private: IMUCursorState m_imu_cursor_state; - size_t m_config_changed_callback_id; + Config::ConfigChangedCallbackID m_config_changed_callback_id; }; } // namespace WiimoteEmu diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h index 39f13f0f44..eccf7bb22d 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h @@ -11,6 +11,7 @@ #include #include "Common/Common.h" +#include "Common/Config/Config.h" #include "Common/Event.h" #include "Common/Flag.h" #include "Common/SPSCQueue.h" @@ -157,7 +158,7 @@ private: bool m_speaker_enabled_in_dolphin_config = false; int m_balance_board_dump_port = 0; - size_t m_config_changed_callback_id; + Config::ConfigChangedCallbackID m_config_changed_callback_id; }; class WiimoteScannerBackend diff --git a/Source/Core/Core/IOS/SDIO/SDIOSlot0.h b/Source/Core/Core/IOS/SDIO/SDIOSlot0.h index c096539e70..5c0dd201a7 100644 --- a/Source/Core/Core/IOS/SDIO/SDIOSlot0.h +++ b/Source/Core/Core/IOS/SDIO/SDIOSlot0.h @@ -10,6 +10,7 @@ #include "Common/CommonTypes.h" #include "Common/IOFile.h" +#include "Core/CPUThreadConfigCallback.h" #include "Core/IOS/Device.h" #include "Core/IOS/IOS.h" @@ -166,7 +167,7 @@ private: File::IOFile m_card; - size_t m_config_callback_id; + CPUThreadConfigCallback::ConfigChangedCallbackID m_config_callback_id; bool m_sd_card_inserted = false; }; } // namespace IOS::HLE diff --git a/Source/Core/Core/PowerPC/JitCommon/JitBase.h b/Source/Core/Core/PowerPC/JitCommon/JitBase.h index e6488960e7..c2e41f8e52 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitBase.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitBase.h @@ -10,6 +10,7 @@ #include "Common/BitSet.h" #include "Common/CommonTypes.h" #include "Common/x64Emitter.h" +#include "Core/CPUThreadConfigCallback.h" #include "Core/ConfigManager.h" #include "Core/MachineContext.h" #include "Core/PowerPC/CPUCoreBase.h" @@ -129,7 +130,7 @@ protected: PPCAnalyst::CodeBuffer m_code_buffer; PPCAnalyst::PPCAnalyzer analyzer; - size_t m_registered_config_callback_id; + CPUThreadConfigCallback::ConfigChangedCallbackID m_registered_config_callback_id; bool bJITOff = false; bool bJITLoadStoreOff = false; bool bJITLoadStorelXzOff = false; diff --git a/Source/Core/Core/PowerPC/PPCCache.h b/Source/Core/Core/PowerPC/PPCCache.h index 8214b116af..5d5648a71e 100644 --- a/Source/Core/Core/PowerPC/PPCCache.h +++ b/Source/Core/Core/PowerPC/PPCCache.h @@ -8,6 +8,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/Config/Config.h" class PointerWrap; @@ -61,7 +62,7 @@ struct Cache struct InstructionCache : public Cache { - std::optional m_config_callback_id = std::nullopt; + std::optional m_config_callback_id = std::nullopt; bool m_disable_icache = false; diff --git a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp index 4d3fa483e3..d3030a60fa 100644 --- a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp @@ -219,7 +219,7 @@ private: SteadyClock::time_point m_next_listports_time; std::thread m_hotplug_thread; Common::Flag m_hotplug_thread_running; - std::size_t m_config_change_callback_id; + Config::ConfigChangedCallbackID m_config_change_callback_id; }; std::unique_ptr CreateInputBackend(ControllerInterface* controller_interface) diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index 6334a23778..2d135970d1 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -23,6 +23,7 @@ #endif #include "Common/BitUtils.h" +#include "Common/Config/Config.h" #include "Common/Event.h" #include "Common/Flag.h" #include "Common/Logging/Log.h" @@ -158,7 +159,7 @@ static u8 s_endpoint_out = 0; static u64 s_last_init = 0; -static std::optional s_config_callback_id = std::nullopt; +static std::optional s_config_callback_id = std::nullopt; static bool s_is_adapter_wanted = false; static std::array s_config_rumble_enabled{}; diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 2acd69f2c2..9b31ad5bf9 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -62,7 +62,7 @@ namespace UICommon { -static size_t s_config_changed_callback_id; +static Config::ConfigChangedCallbackID s_config_changed_callback_id; static void CreateDumpPath(std::string path) { diff --git a/Source/Core/VideoCommon/Fifo.h b/Source/Core/VideoCommon/Fifo.h index 20648562b4..2ee237c782 100644 --- a/Source/Core/VideoCommon/Fifo.h +++ b/Source/Core/VideoCommon/Fifo.h @@ -9,6 +9,7 @@ #include "Common/BlockingLoop.h" #include "Common/CommonTypes.h" +#include "Common/Config/Config.h" #include "Common/Event.h" #include "Common/Flag.h" @@ -121,7 +122,7 @@ private: bool m_syncing_suspended = false; Common::Event m_sync_wakeup_event; - std::optional m_config_callback_id = std::nullopt; + std::optional m_config_callback_id = std::nullopt; bool m_config_sync_gpu = false; int m_config_sync_gpu_max_distance = 0; int m_config_sync_gpu_min_distance = 0;