diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 5f90f93bae..424b364795 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -809,7 +809,8 @@ static bool PauseAndLock(Core::System& system, bool do_lock, bool unpause_on_unl return was_unpaused; } -void RunOnCPUThread(Core::System& system, std::function function, bool wait_for_completion) +void RunOnCPUThread(Core::System& system, Common::MoveOnlyFunction function, + bool wait_for_completion) { // If the CPU thread is not running, assume there is no active CPU thread we can race against. if (!IsRunning(system) || IsCPUThread()) diff --git a/Source/Core/Core/Core.h b/Source/Core/Core/Core.h index eca18cf3be..188f57a75a 100644 --- a/Source/Core/Core/Core.h +++ b/Source/Core/Core/Core.h @@ -15,6 +15,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/Functional.h" struct BootParameters; struct WindowSystemInfo; @@ -159,7 +160,8 @@ void OnFrameEnd(Core::System& system); // Run a function on the CPU thread, asynchronously. // This is only valid to call from the host thread, since it uses PauseAndLock() internally. -void RunOnCPUThread(Core::System& system, std::function function, bool wait_for_completion); +void RunOnCPUThread(Core::System& system, Common::MoveOnlyFunction function, + bool wait_for_completion); // for calling back into UI code without introducing a dependency on it in core using StateChangedCallbackFunc = std::function; diff --git a/Source/Core/Core/HW/CPU.cpp b/Source/Core/Core/HW/CPU.cpp index 5a21e5e3c8..e67111e72d 100644 --- a/Source/Core/Core/HW/CPU.cpp +++ b/Source/Core/Core/HW/CPU.cpp @@ -60,7 +60,7 @@ void CPUManager::ExecutePendingJobs(std::unique_lock& state_lock) { while (!m_pending_jobs.empty()) { - auto callback = m_pending_jobs.front(); + auto callback = std::move(m_pending_jobs.front()); m_pending_jobs.pop(); state_lock.unlock(); callback(); @@ -414,7 +414,7 @@ bool CPUManager::PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control return was_unpaused; } -void CPUManager::AddCPUThreadJob(std::function function) +void CPUManager::AddCPUThreadJob(Common::MoveOnlyFunction function) { std::unique_lock state_lock(m_state_change_lock); m_pending_jobs.push(std::move(function)); diff --git a/Source/Core/Core/HW/CPU.h b/Source/Core/Core/HW/CPU.h index b73471136d..438a48763b 100644 --- a/Source/Core/Core/HW/CPU.h +++ b/Source/Core/Core/HW/CPU.h @@ -4,11 +4,11 @@ #pragma once #include -#include #include #include #include "Common/Event.h" +#include "Common/Functional.h" namespace Common { @@ -99,7 +99,7 @@ public: // Adds a job to be executed during on the CPU thread. This should be combined with // PauseAndLock(), as while the CPU is in the run loop, it won't execute the function. - void AddCPUThreadJob(std::function function); + void AddCPUThreadJob(Common::MoveOnlyFunction function); private: void FlushStepSyncEventLocked(); @@ -135,7 +135,7 @@ private: bool m_state_system_request_stepping = false; bool m_state_cpu_step_instruction = false; Common::Event* m_state_cpu_step_instruction_sync = nullptr; - std::queue> m_pending_jobs; + std::queue> m_pending_jobs; Common::Event m_time_played_finish_sync; Core::System& m_system;