Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Divide::TaskPool Class Referencefinal

#include <TaskPool.h>

+ Inheritance diagram for Divide::TaskPool:

Classes

struct  CallbackEntry
 

Public Member Functions

 TaskPool (std::string_view workerName)
 
 ~TaskPool ()
 
bool init (size_t threadCount, const DELEGATE< void, const std::thread::id & > &onThreadCreate={})
 
void shutdown ()
 
size_t flushCallbackQueue ()
 Returns the number of callbacks processed.
 
void waitForAllTasks (bool flushCallbacks)
 
void threadWaiting ()
 
bool addTask (PoolTask &&job)
 
void init ()
 
void join ()
 
void wait () const noexcept
 
void executeOneTask (bool isIdleCall)
 
 PROPERTY_R (vector< std::thread >, threads)
 
- Public Member Functions inherited from Divide::GUIDWrapper
 GUIDWrapper () noexcept
 
 GUIDWrapper (const GUIDWrapper &old) noexcept
 
 GUIDWrapper (GUIDWrapper &&old) noexcept
 
virtual ~GUIDWrapper ()=default
 
FORCE_INLINE I64 getGUID () const noexcept
 
GUIDWrapperoperator= (const GUIDWrapper &old)=delete
 
GUIDWrapperoperator= (GUIDWrapper &&other)=delete
 

Static Public Member Functions

static TaskAllocateTask (Task *parentTask, DELEGATE< void, Task & > &&func, bool allowedInIdle) noexcept
 
- Static Public Member Functions inherited from Divide::GUIDWrapper
static I64 generateGUID () noexcept
 

Static Public Attributes

static constexpr bool IsBlocking = true
 

Private Types

using QueueType = std::conditional_t< IsBlocking, moodycamel::BlockingConcurrentQueue< PoolTask >, moodycamel::ConcurrentQueue< PoolTask > >
 

Private Member Functions

void taskStarted (Task &task)
 
void taskCompleted (Task &task)
 
bool enqueue (Task &task, TaskPriority priority, const DELEGATE< void > &onCompletionFunction)
 
bool runRealTime (Task &task, const DELEGATE< void > &onCompletionFunction)
 
bool deque (bool isIdleCall, PoolTask &taskOut)
 
void waitForTask (const Task &task)
 

Private Attributes

const string _threadNamePrefix
 
SharedMutex _taskCallbacksLock
 
eastl::fixed_vector< CallbackEntry, 1<< 9, true > _taskCallbacks
 
moodycamel::ConcurrentQueue< U32_threadedCallbackBuffer {}
 
QueueType _queue
 
Mutex _taskFinishedMutex
 
std::condition_variable _taskFinishedCV
 
DELEGATE< void, const std::thread::id & > _threadCreateCbk {}
 
std::atomic_uint _runningTaskCount = 0u
 
std::atomic_size_t _activeThreads { 0u }
 
bool _isRunning { true }
 

Friends

struct Task
 
void Start (Task &task, TaskPool &pool, const TaskPriority priority, const DELEGATE< void > &onCompletionFunction)
 
void Wait (const Task &task, TaskPool &pool)
 
void Parallel_For (TaskPool &pool, const ParallelForDescriptor &descriptor)
 

Additional Inherited Members

- Protected Attributes inherited from Divide::GUIDWrapper
const I64 _guid
 

Detailed Description

Definition at line 60 of file TaskPool.h.

Member Typedef Documentation

◆ QueueType

using Divide::TaskPool::QueueType = std::conditional_t<IsBlocking, moodycamel::BlockingConcurrentQueue<PoolTask>, moodycamel::ConcurrentQueue<PoolTask> >
private

Definition at line 129 of file TaskPool.h.

Constructor & Destructor Documentation

◆ TaskPool()

Divide::TaskPool::TaskPool ( std::string_view  workerName)
explicit

Definition at line 20 of file TaskPool.cpp.

◆ ~TaskPool()

Divide::TaskPool::~TaskPool ( )

Definition at line 25 of file TaskPool.cpp.

Member Function Documentation

◆ addTask()

bool Divide::TaskPool::addTask ( PoolTask &&  job)

Definition at line 378 of file TaskPool.cpp.

◆ AllocateTask()

Task * Divide::TaskPool::AllocateTask ( Task parentTask,
DELEGATE< void, Task & > &&  func,
bool  allowedInIdle 
)
staticnoexcept

Definition at line 290 of file TaskPool.cpp.

◆ deque()

bool Divide::TaskPool::deque ( bool  isIdleCall,
PoolTask taskOut 
)
private

Definition at line 393 of file TaskPool.cpp.

◆ enqueue()

bool Divide::TaskPool::enqueue ( Task task,
TaskPriority  priority,
const DELEGATE< void > &  onCompletionFunction 
)
private

Definition at line 83 of file TaskPool.cpp.

◆ executeOneTask()

void Divide::TaskPool::executeOneTask ( bool  isIdleCall)

Definition at line 383 of file TaskPool.cpp.

◆ flushCallbackQueue()

size_t Divide::TaskPool::flushCallbackQueue ( )

Returns the number of callbacks processed.

Definition at line 201 of file TaskPool.cpp.

◆ init() [1/2]

void Divide::TaskPool::init ( )

◆ init() [2/2]

bool Divide::TaskPool::init ( size_t  threadCount,
const DELEGATE< void, const std::thread::id & > &  onThreadCreate = {} 
)

Definition at line 30 of file TaskPool.cpp.

◆ join()

void Divide::TaskPool::join ( )

Definition at line 347 of file TaskPool.cpp.

◆ PROPERTY_R()

Divide::TaskPool::PROPERTY_R ( vector< std::thread >  ,
threads   
)

◆ runRealTime()

bool Divide::TaskPool::runRealTime ( Task task,
const DELEGATE< void > &  onCompletionFunction 
)
private

Definition at line 155 of file TaskPool.cpp.

◆ shutdown()

void Divide::TaskPool::shutdown ( )

Definition at line 73 of file TaskPool.cpp.

◆ taskCompleted()

void Divide::TaskPool::taskCompleted ( Task task)
private

<Needed to cleanup any stale resources (e.g. captured by lambdas)

Definition at line 271 of file TaskPool.cpp.

◆ taskStarted()

void Divide::TaskPool::taskStarted ( Task task)
private

Definition at line 266 of file TaskPool.cpp.

◆ threadWaiting()

void Divide::TaskPool::threadWaiting ( )

Called by a task that isn't doing anything (e.g. waiting on child tasks). Use this to run another task (if any) and return to the previous execution point

Definition at line 341 of file TaskPool.cpp.

◆ wait()

void Divide::TaskPool::wait ( ) const
noexcept

Definition at line 364 of file TaskPool.cpp.

◆ waitForAllTasks()

void Divide::TaskPool::waitForAllTasks ( bool  flushCallbacks)

Definition at line 246 of file TaskPool.cpp.

◆ waitForTask()

void Divide::TaskPool::waitForTask ( const Task task)
private

Definition at line 184 of file TaskPool.cpp.

Friends And Related Function Documentation

◆ Parallel_For

void Parallel_For ( TaskPool pool,
const ParallelForDescriptor descriptor 
)
friend

◆ Start

void Start ( Task task,
TaskPool pool,
const TaskPriority  priority = TaskPriority::DONT_CARE,
const DELEGATE< void > &  onCompletionFunction = {} 
)
friend

Definition at line 9 of file Task.cpp.

◆ Task

friend struct Task
friend

Definition at line 101 of file TaskPool.h.

◆ Wait

void Wait ( const Task task,
TaskPool pool 
)
friend

Definition at line 20 of file Task.cpp.

Member Data Documentation

◆ _activeThreads

std::atomic_size_t Divide::TaskPool::_activeThreads { 0u }
private

Definition at line 137 of file TaskPool.h.

◆ _isRunning

bool Divide::TaskPool::_isRunning { true }
private

Definition at line 139 of file TaskPool.h.

◆ _queue

QueueType Divide::TaskPool::_queue
private

Definition at line 130 of file TaskPool.h.

◆ _runningTaskCount

std::atomic_uint Divide::TaskPool::_runningTaskCount = 0u
private

Definition at line 136 of file TaskPool.h.

◆ _taskCallbacks

eastl::fixed_vector<CallbackEntry, 1 << 9, true> Divide::TaskPool::_taskCallbacks
private

Definition at line 125 of file TaskPool.h.

◆ _taskCallbacksLock

SharedMutex Divide::TaskPool::_taskCallbacksLock
private

Definition at line 124 of file TaskPool.h.

◆ _taskFinishedCV

std::condition_variable Divide::TaskPool::_taskFinishedCV
private

Definition at line 133 of file TaskPool.h.

◆ _taskFinishedMutex

Mutex Divide::TaskPool::_taskFinishedMutex
private

Definition at line 132 of file TaskPool.h.

◆ _threadCreateCbk

DELEGATE<void, const std::thread::id&> Divide::TaskPool::_threadCreateCbk {}
private

Definition at line 134 of file TaskPool.h.

◆ _threadedCallbackBuffer

moodycamel::ConcurrentQueue<U32> Divide::TaskPool::_threadedCallbackBuffer {}
private

Definition at line 127 of file TaskPool.h.

◆ _threadNamePrefix

const string Divide::TaskPool::_threadNamePrefix
private

Definition at line 116 of file TaskPool.h.

◆ IsBlocking

constexpr bool Divide::TaskPool::IsBlocking = true
staticconstexpr

Definition at line 64 of file TaskPool.h.


The documentation for this class was generated from the following files: