33#ifndef DVD_TASK_POOL_H_
34#define DVD_TASK_POOL_H_
66 explicit TaskPool(std::string_view workerName);
92 void wait() const noexcept;
129 using QueueType = std::conditional_t<IsBlocking, moodycamel::BlockingConcurrentQueue<PoolTask>, moodycamel::ConcurrentQueue<PoolTask>>;
142template<
class Predicate>
143Task*
CreateTask(Predicate&& threadedFunction,
bool allowedInIdle =
true);
145template<
class Predicate>
146Task*
CreateTask(Task* parentTask, Predicate&& threadedFunction,
bool allowedInIdle =
true);
148void Parallel_For(TaskPool& pool,
const ParallelForDescriptor& descriptor,
const DELEGATE<void, const Task*, U32/*start*/, U32/*end*/>& cbk);
Utility class that adds basic GUID management to objects.
static Task * AllocateTask(Task *parentTask, DELEGATE< void, Task & > &&func, bool allowedInIdle) noexcept
eastl::fixed_vector< CallbackEntry, 1<< 9, true > _taskCallbacks
bool enqueue(Task &task, TaskPriority priority, const DELEGATE< void > &onCompletionFunction)
void waitForTask(const Task &task)
std::atomic_size_t _activeThreads
const string _threadNamePrefix
friend void Start(Task &task, TaskPool &pool, const TaskPriority priority, const DELEGATE< void > &onCompletionFunction)
std::condition_variable _taskFinishedCV
moodycamel::ConcurrentQueue< U32 > _threadedCallbackBuffer
DELEGATE< void, const std::thread::id & > _threadCreateCbk
void executeOneTask(bool isIdleCall)
size_t flushCallbackQueue()
Returns the number of callbacks processed.
static constexpr bool IsBlocking
std::conditional_t< IsBlocking, moodycamel::BlockingConcurrentQueue< PoolTask >, moodycamel::ConcurrentQueue< PoolTask > > QueueType
friend void Parallel_For(TaskPool &pool, const ParallelForDescriptor &descriptor)
void wait() const noexcept
void waitForAllTasks(bool flushCallbacks)
bool deque(bool isIdleCall, PoolTask &taskOut)
std::atomic_uint _runningTaskCount
friend void Wait(const Task &task, TaskPool &pool)
void taskCompleted(Task &task)
SharedMutex _taskCallbacksLock
bool addTask(PoolTask &&job)
bool runRealTime(Task &task, const DELEGATE< void > &onCompletionFunction)
void taskStarted(Task &task)
Handle console commands that start with a forward slash.
DELEGATE_STD< Ret, Args... > DELEGATE
DELEGATE_STD< bool, bool > PoolTask
std::function< Ret(Args...) > DELEGATE_STD
Task * CreateTask(Predicate &&threadedFunction, bool allowedInIdle=true)
std::shared_mutex SharedMutex
eastl::vector< Type > vector
void Parallel_For(TaskPool &pool, const ParallelForDescriptor &descriptor, const DELEGATE< void, const Task *, U32, U32 > &cbk)
bool _allowPoolIdle
If true, we'll inform the thread pool to execute other tasks while waiting for the all async tasks to...
U32 _partitionSize
How many elements should we process per async task.
bool _useCurrentThread
If true, we'll process a for partition on the calling thread.
bool _waitForFinish
If this is false, the Parallel_For call won't block the current thread.
TaskPriority _priority
Each async task will start with the same priority specified here.
U32 _iterCount
For loop iteration count.
bool _allowRunInIdle
If true, async tasks can be invoked from other task's idle callbacks.