mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-28 01:49:33 -06:00
Core: Use MoveOnlyFunction for RunOnCPUThread.
This commit is contained in:
@ -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<void()> function, bool wait_for_completion)
|
||||
void RunOnCPUThread(Core::System& system, Common::MoveOnlyFunction<void()> 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())
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <string_view>
|
||||
|
||||
#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<void()> function, bool wait_for_completion);
|
||||
void RunOnCPUThread(Core::System& system, Common::MoveOnlyFunction<void()> function,
|
||||
bool wait_for_completion);
|
||||
|
||||
// for calling back into UI code without introducing a dependency on it in core
|
||||
using StateChangedCallbackFunc = std::function<void(Core::State)>;
|
||||
|
@ -60,7 +60,7 @@ void CPUManager::ExecutePendingJobs(std::unique_lock<std::mutex>& 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<void()> function)
|
||||
void CPUManager::AddCPUThreadJob(Common::MoveOnlyFunction<void()> function)
|
||||
{
|
||||
std::unique_lock state_lock(m_state_change_lock);
|
||||
m_pending_jobs.push(std::move(function));
|
||||
|
@ -4,11 +4,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
#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<void()> function);
|
||||
void AddCPUThreadJob(Common::MoveOnlyFunction<void()> 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<std::function<void()>> m_pending_jobs;
|
||||
std::queue<Common::MoveOnlyFunction<void()>> m_pending_jobs;
|
||||
Common::Event m_time_played_finish_sync;
|
||||
|
||||
Core::System& m_system;
|
||||
|
Reference in New Issue
Block a user