diff --git a/Common/Cpp/Concurrency/Backends/AsyncTask_Default.h b/Common/Cpp/Concurrency/Backends/AsyncTask_Default.h index 6e83ebde75..e797904803 100644 --- a/Common/Cpp/Concurrency/Backends/AsyncTask_Default.h +++ b/Common/Cpp/Concurrency/Backends/AsyncTask_Default.h @@ -7,9 +7,9 @@ #ifndef PokemonAutomation_AsyncTask_Default_H #define PokemonAutomation_AsyncTask_Default_H -#include #include #include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Concurrency/SpinPause.h" #include "Common/Cpp/Concurrency/Mutex.h" #include "Common/Cpp/Concurrency/ConditionVariable.h" @@ -50,7 +50,7 @@ class AsyncTask_Cpp : public AsyncTaskCore{ pause(); } } - AsyncTask_Cpp(std::function task) + AsyncTask_Cpp(MoveOnlyFunction task) : m_task(std::move(task)) , m_state(State::NOT_STARTED) {} @@ -102,7 +102,7 @@ class AsyncTask_Cpp : public AsyncTaskCore{ private: - std::function m_task; + MoveOnlyFunction m_task; std::atomic m_state; std::exception_ptr m_exception; diff --git a/Common/Cpp/Concurrency/Backends/ThreadPool_Default.cpp b/Common/Cpp/Concurrency/Backends/ThreadPool_Default.cpp index 297ba275cb..bf5ed9ce7a 100644 --- a/Common/Cpp/Concurrency/Backends/ThreadPool_Default.cpp +++ b/Common/Cpp/Concurrency/Backends/ThreadPool_Default.cpp @@ -90,7 +90,7 @@ WallDuration ThreadPool_Default::cpu_time() const{ return ret; } -AsyncTask ThreadPool_Default::dispatch(std::function&& func){ +AsyncTask ThreadPool_Default::dispatch(MoveOnlyFunction&& func){ AsyncTask task; { std::unique_lock lg(m_lock); @@ -114,7 +114,7 @@ AsyncTask ThreadPool_Default::dispatch(std::function&& func){ m_thread_cv.notify_one(); return task; } -AsyncTask ThreadPool_Default::dispatch_now_blocking(std::function&& func){ +AsyncTask ThreadPool_Default::dispatch_now_blocking(MoveOnlyFunction&& func){ AsyncTask task; { std::unique_lock lg(m_lock); @@ -138,7 +138,7 @@ AsyncTask ThreadPool_Default::dispatch_now_blocking(std::function&& func m_thread_cv.notify_one(); return task; } -AsyncTask ThreadPool_Default::try_dispatch_now(std::function& func){ +AsyncTask ThreadPool_Default::try_dispatch_now(MoveOnlyFunction& func){ AsyncTask task; { std::lock_guard lg(m_lock); diff --git a/Common/Cpp/Concurrency/Backends/ThreadPool_Default.h b/Common/Cpp/Concurrency/Backends/ThreadPool_Default.h index b2944c630f..d60a7378bb 100644 --- a/Common/Cpp/Concurrency/Backends/ThreadPool_Default.h +++ b/Common/Cpp/Concurrency/Backends/ThreadPool_Default.h @@ -49,9 +49,9 @@ class ThreadPool_Default final : public ThreadPool{ public: - [[nodiscard]] virtual AsyncTask dispatch(std::function&& func) override; - [[nodiscard]] virtual AsyncTask dispatch_now_blocking(std::function&& func) override; - [[nodiscard]] virtual AsyncTask try_dispatch_now(std::function& func) override; + [[nodiscard]] virtual AsyncTask dispatch(MoveOnlyFunction&& func) override; + [[nodiscard]] virtual AsyncTask dispatch_now_blocking(MoveOnlyFunction&& func) override; + [[nodiscard]] virtual AsyncTask try_dispatch_now(MoveOnlyFunction& func) override; virtual void run_in_parallel( const std::function& func, diff --git a/Common/Cpp/Concurrency/ThreadPool.h b/Common/Cpp/Concurrency/ThreadPool.h index 29ea2cf01c..6a47ab3337 100644 --- a/Common/Cpp/Concurrency/ThreadPool.h +++ b/Common/Cpp/Concurrency/ThreadPool.h @@ -17,6 +17,7 @@ #define PokemonAutomation_ThreadPool_H #include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Time.h" namespace PokemonAutomation{ @@ -40,17 +41,17 @@ class ThreadPool{ // Dispatch the function and return immediately. // The function is not guaranteed to begin running immediately. - [[nodiscard]] virtual AsyncTask dispatch(std::function&& func) = 0; + [[nodiscard]] virtual AsyncTask dispatch(MoveOnlyFunction&& func) = 0; // Dispatch the function and begin running now. // If there are no threads available, it waits until there are. // This function will not return until the function has begin running. - [[nodiscard]] virtual AsyncTask dispatch_now_blocking(std::function&& func) = 0; + [[nodiscard]] virtual AsyncTask dispatch_now_blocking(MoveOnlyFunction&& func) = 0; // Try to dispatch the function and begin running now. // Returns null if no threads are available. "func" will be moved-from only on success. // This function returns immediately. - [[nodiscard]] virtual AsyncTask try_dispatch_now(std::function& func) = 0; + [[nodiscard]] virtual AsyncTask try_dispatch_now(MoveOnlyFunction& func) = 0; // Run function for all the indices [start, end). // Lower indices are not allowed to block on higher indices. diff --git a/SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/SnapshotManager.cpp b/SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/SnapshotManager.cpp index 068d6ec418..1f5369a0ab 100644 --- a/SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/SnapshotManager.cpp +++ b/SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/SnapshotManager.cpp @@ -5,6 +5,7 @@ */ //#include "Common/Cpp/Concurrency/ReverseLockGuard.h" +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Concurrency/AsyncTask.h" #include "CommonFramework/ImageTypes/ImageRGB32_Qt.h" #include "CommonFramework/Tools/GlobalThreadPools.h" @@ -100,7 +101,7 @@ bool SnapshotManager::try_dispatch_conversion(uint64_t seqnum, QVideoFrame frame } try{ - std::function lambda = [=, this, frame = std::move(frame)](){ + MoveOnlyFunction lambda = [=, this, frame = std::move(frame)](){ convert(seqnum, std::move(frame), timestamp); }; diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp index ed375c9948..c3b2ae25f9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp @@ -6,6 +6,7 @@ #include #include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Concurrency/SpinLock.h" #include "Common/Cpp/Concurrency/AsyncTask.h" #include "Kernels/Waterfill/Kernels_Waterfill_Session.h" @@ -134,7 +135,7 @@ ShinySparkleSetSwSh find_sparkles(size_t screen_area, WaterfillSession& session) auto finder = session.make_iterator(20); WaterfillObject object; while (finder->find_next(object, true)){ - std::function func = [&, screen_area, object = std::move(object)]{ + MoveOnlyFunction func = [&, screen_area, object = std::move(object)]{ find_sparkles( screen_area, lock,