Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c5b44be
Common: add MoveOnlyFunction, a move-only callable wrapper
dayfine Oct 30, 2026
38bb6ae
Common: drop the noexcept move-assignment check from MoveOnlyFunction…
dayfine Oct 30, 2026
c8b3a32
Merge origin/main into common/move-only-function
dayfine Oct 30, 2026
87071ad
Merge origin/main into common/move-only-function
dayfine Oct 31, 2026
93487aa
Common: hold thread pool tasks in MoveOnlyFunction
dayfine Oct 31, 2026
981b0aa
Merge origin/main into common/move-only-function-migrate
dayfine Nov 2, 2026
c7a5fda
Merge origin/main into common/move-only-function-migrate
dayfine Nov 3, 2026
4bb2d90
Merge origin/main into common/move-only-function-migrate
dayfine Nov 4, 2026
089d1d4
Merge origin/main into common/move-only-function-migrate
dayfine Nov 6, 2026
34da3a2
Merge origin/main into common/move-only-function-migrate
dayfine Nov 7, 2026
69123f5
Merge origin/main into common/move-only-function-migrate
dayfine Nov 8, 2026
9b00659
Merge origin/main into common/move-only-function-migrate
dayfine Nov 9, 2026
32ee4bc
Merge origin/main into common/move-only-function-migrate
dayfine Nov 10, 2026
4f5bfae
Merge origin/main into common/move-only-function-migrate
dayfine Nov 11, 2026
419c9b3
Merge origin/main into common/move-only-function-migrate
dayfine Nov 12, 2026
67358a5
Merge origin/main into common/move-only-function-migrate
dayfine Nov 13, 2026
17f7d91
Merge origin/main into common/move-only-function-migrate
dayfine Nov 14, 2026
451bcab
Merge origin/main into common/move-only-function-migrate
dayfine Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Common/Cpp/Concurrency/Backends/AsyncTask_Default.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#ifndef PokemonAutomation_AsyncTask_Default_H
#define PokemonAutomation_AsyncTask_Default_H

#include <functional>
#include <atomic>
#include <exception>
#include "Common/Cpp/MoveOnlyFunction.h"
#include "Common/Cpp/Concurrency/SpinPause.h"
#include "Common/Cpp/Concurrency/Mutex.h"
#include "Common/Cpp/Concurrency/ConditionVariable.h"
Expand Down Expand Up @@ -50,7 +50,7 @@ class AsyncTask_Cpp : public AsyncTaskCore{
pause();
}
}
AsyncTask_Cpp(std::function<void()> task)
AsyncTask_Cpp(MoveOnlyFunction<void()> task)
: m_task(std::move(task))
, m_state(State::NOT_STARTED)
{}
Expand Down Expand Up @@ -102,7 +102,7 @@ class AsyncTask_Cpp : public AsyncTaskCore{


private:
std::function<void()> m_task;
MoveOnlyFunction<void()> m_task;
std::atomic<State> m_state;

std::exception_ptr m_exception;
Expand Down
6 changes: 3 additions & 3 deletions Common/Cpp/Concurrency/Backends/ThreadPool_Default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ WallDuration ThreadPool_Default::cpu_time() const{
return ret;
}

AsyncTask ThreadPool_Default::dispatch(std::function<void()>&& func){
AsyncTask ThreadPool_Default::dispatch(MoveOnlyFunction<void()>&& func){
AsyncTask task;
{
std::unique_lock<Mutex> lg(m_lock);
Expand All @@ -114,7 +114,7 @@ AsyncTask ThreadPool_Default::dispatch(std::function<void()>&& func){
m_thread_cv.notify_one();
return task;
}
AsyncTask ThreadPool_Default::dispatch_now_blocking(std::function<void()>&& func){
AsyncTask ThreadPool_Default::dispatch_now_blocking(MoveOnlyFunction<void()>&& func){
AsyncTask task;
{
std::unique_lock<Mutex> lg(m_lock);
Expand All @@ -138,7 +138,7 @@ AsyncTask ThreadPool_Default::dispatch_now_blocking(std::function<void()>&& func
m_thread_cv.notify_one();
return task;
}
AsyncTask ThreadPool_Default::try_dispatch_now(std::function<void()>& func){
AsyncTask ThreadPool_Default::try_dispatch_now(MoveOnlyFunction<void()>& func){
AsyncTask task;
{
std::lock_guard<Mutex> lg(m_lock);
Expand Down
6 changes: 3 additions & 3 deletions Common/Cpp/Concurrency/Backends/ThreadPool_Default.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class ThreadPool_Default final : public ThreadPool{


public:
[[nodiscard]] virtual AsyncTask dispatch(std::function<void()>&& func) override;
[[nodiscard]] virtual AsyncTask dispatch_now_blocking(std::function<void()>&& func) override;
[[nodiscard]] virtual AsyncTask try_dispatch_now(std::function<void()>& func) override;
[[nodiscard]] virtual AsyncTask dispatch(MoveOnlyFunction<void()>&& func) override;
[[nodiscard]] virtual AsyncTask dispatch_now_blocking(MoveOnlyFunction<void()>&& func) override;
[[nodiscard]] virtual AsyncTask try_dispatch_now(MoveOnlyFunction<void()>& func) override;

virtual void run_in_parallel(
const std::function<void(size_t index)>& func,
Expand Down
7 changes: 4 additions & 3 deletions Common/Cpp/Concurrency/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define PokemonAutomation_ThreadPool_H

#include <functional>
#include "Common/Cpp/MoveOnlyFunction.h"
#include "Common/Cpp/Time.h"

namespace PokemonAutomation{
Expand All @@ -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<void()>&& func) = 0;
[[nodiscard]] virtual AsyncTask dispatch(MoveOnlyFunction<void()>&& 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<void()>&& func) = 0;
[[nodiscard]] virtual AsyncTask dispatch_now_blocking(MoveOnlyFunction<void()>&& 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<void()>& func) = 0;
[[nodiscard]] virtual AsyncTask try_dispatch_now(MoveOnlyFunction<void()>& func) = 0;

// Run function for all the indices [start, end).
// Lower indices are not allowed to block on higher indices.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -100,7 +101,7 @@ bool SnapshotManager::try_dispatch_conversion(uint64_t seqnum, QVideoFrame frame
}

try{
std::function<void()> lambda = [=, this, frame = std::move(frame)](){
MoveOnlyFunction<void()> lambda = [=, this, frame = std::move(frame)](){
convert(seqnum, std::move(frame), timestamp);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <deque>
#include <sstream>
#include "Common/Cpp/MoveOnlyFunction.h"
#include "Common/Cpp/Concurrency/SpinLock.h"
#include "Common/Cpp/Concurrency/AsyncTask.h"
#include "Kernels/Waterfill/Kernels_Waterfill_Session.h"
Expand Down Expand Up @@ -126,7 +127,7 @@
// running one of these calls, all of them wait for a free thread that never
// comes, and the program freezes with the pool stuck at 100% per thread.
//
ShinySparkleSetSwSh find_sparkles(size_t screen_area, WaterfillSession& session){

Check warning on line 130 in SerialPrograms/Source/VideoGames/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonSwSh::find_sparkles( size_t screen_area , WaterfillSession & session): function_lines=27 (advisory above 25, limit 50)
ThreadPool& pool = GlobalThreadPools::computation_realtime();
SpinLock lock;
ShinySparkleSetSwSh sparkles;
Expand All @@ -134,7 +135,7 @@
auto finder = session.make_iterator(20);
WaterfillObject object;
while (finder->find_next(object, true)){
std::function<void()> func = [&, screen_area, object = std::move(object)]{
MoveOnlyFunction<void()> func = [&, screen_area, object = std::move(object)]{
find_sparkles(
screen_area,
lock,
Expand Down
Loading