Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FQueuedThreadPoolWrapper Class Reference

#include <QueuedThreadPoolWrapper.h>

+ Inheritance diagram for FQueuedThreadPoolWrapper:
+ Collaboration diagram for FQueuedThreadPoolWrapper:

Classes

class  FScheduledWork
 

Public Member Functions

 FQueuedThreadPoolWrapper (FQueuedThreadPool *InWrappedQueuedThreadPool, int32 InMaxConcurrency=-1, TFunction< EQueuedWorkPriority(EQueuedWorkPriority)> InPriorityMapper=[](EQueuedWorkPriority InPriority) { return InPriority;})
 
 ~FQueuedThreadPoolWrapper ()
 
void Pause ()
 
void Resume (int32 InNumQueuedWork=-1)
 
void SetMaxConcurrency (int32 MaxConcurrency=-1)
 
void AddQueuedWork (IQueuedWork *InQueuedWork, EQueuedWorkPriority InPriority=EQueuedWorkPriority::Normal) override
 
bool RetractQueuedWork (IQueuedWork *InQueuedWork) override
 
int32 GetNumThreads () const override
 
int32 GetCurrentConcurrency () const
 
- Public Member Functions inherited from FQueuedThreadPool
 FQueuedThreadPool ()
 
virtual ~FQueuedThreadPool ()
 

Protected Member Functions

virtual int32 GetMaxConcurrency () const
 
virtual void OnScheduled (const IQueuedWork *)
 
virtual void OnUnscheduled (const IQueuedWork *)
 
virtual FScheduledWorkAllocateScheduledWork ()
 

Protected Attributes

FCriticalSection Lock
 
FThreadPoolPriorityQueue QueuedWork
 

Private Member Functions

FScheduledWorkAllocateWork (IQueuedWork *InnerWork, EQueuedWorkPriority Priority)
 
bool CanSchedule (EQueuedWorkPriority Priority) const
 
bool Create (uint32 InNumQueuedThreads, uint32 StackSize, EThreadPriority ThreadPriority, const TCHAR *Name) override
 
void Destroy () override
 
void Schedule (FScheduledWork *Work=nullptr)
 
void ReleaseWorkNoLock (FScheduledWork *Work)
 
bool TryRetractWorkNoLock (EQueuedWorkPriority InPriority)
 

Private Attributes

TFunction< EQueuedWorkPriority(EQueuedWorkPriority)> PriorityMapper
 
FQueuedThreadPoolWrappedQueuedThreadPool
 
TArray< FScheduledWork * > WorkPool
 
TMap< IQueuedWork *, FScheduledWork * > ScheduledWork
 
std::atomic< int32MaxConcurrency
 
int32 MaxTaskToSchedule
 
std::atomic< int32CurrentConcurrency
 
EQueuedWorkPriority WrappedQueuePriority
 
bool bIsScheduling = false
 

Additional Inherited Members

- Static Public Member Functions inherited from FQueuedThreadPool
static FQueuedThreadPoolAllocate ()
 
- Static Public Attributes inherited from FQueuedThreadPool
static uint32 OverrideStackSize
 

Detailed Description

ThreadPool wrapper implementation allowing to schedule up to MaxConcurrency tasks at a time making sub-partitioning another thread-pool a breeze and allowing more fine-grained control over scheduling by effectively giving another set of priorities.

Definition at line 40 of file QueuedThreadPoolWrapper.h.

Constructor & Destructor Documentation

◆ FQueuedThreadPoolWrapper()

FQueuedThreadPoolWrapper::FQueuedThreadPoolWrapper ( FQueuedThreadPool * InWrappedQueuedThreadPool,
int32 InMaxConcurrency = -1,
TFunction< EQueuedWorkPriority(EQueuedWorkPriority)> InPriorityMapper = [](EQueuedWorkPriority InPriority) { return InPriority;} )

InWrappedQueuedThreadPool Underlying thread pool to schedule task to. InMaxConcurrency Maximum number of concurrent tasks allowed, -1 will limit concurrency to number of threads available in the underlying thread pool. InPriorityMapper Thread-safe function used to map any priority from this Queue to the priority that should be used when scheduling the task on the underlying thread pool.

◆ ~FQueuedThreadPoolWrapper()

FQueuedThreadPoolWrapper::~FQueuedThreadPoolWrapper ( )

Member Function Documentation

◆ AddQueuedWork()

void FQueuedThreadPoolWrapper::AddQueuedWork ( IQueuedWork * InQueuedWork,
EQueuedWorkPriority InQueuedWorkPriority = EQueuedWorkPriority::Normal )
overridevirtual

Checks to see if there is a thread available to perform the task. If not, it queues the work for later. Otherwise it is immediately dispatched.

Parameters
InQueuedWorkThe work that needs to be done asynchronously
InQueuedWorkPriorityThe priority at which to process this task
See also
RetractQueuedWork

Implements FQueuedThreadPool.

+ Here is the caller graph for this function:

◆ AllocateScheduledWork()

virtual FScheduledWork * FQueuedThreadPoolWrapper::AllocateScheduledWork ( )
inlineprotectedvirtual

Definition at line 187 of file QueuedThreadPoolWrapper.h.

+ Here is the call graph for this function:

◆ AllocateWork()

FScheduledWork * FQueuedThreadPoolWrapper::AllocateWork ( IQueuedWork * InnerWork,
EQueuedWorkPriority Priority )
private

◆ CanSchedule()

bool FQueuedThreadPoolWrapper::CanSchedule ( EQueuedWorkPriority Priority) const
private

◆ Create()

bool FQueuedThreadPoolWrapper::Create ( uint32 InNumQueuedThreads,
uint32 StackSize,
EThreadPriority ThreadPriority,
const TCHAR * Name )
overrideprivatevirtual

Creates the thread pool with the specified number of threads

Parameters
InNumQueuedThreadsSpecifies the number of threads to use in the pool
StackSizeThe size of stack the threads in the pool need (32K default)
ThreadPrioritypriority of new pool thread
Nameoptional name for the pool to be used for instrumentation
Returns
Whether the pool creation was successful or not

Implements FQueuedThreadPool.

◆ Destroy()

void FQueuedThreadPoolWrapper::Destroy ( )
overrideprivatevirtual

Tells the pool to clean up all background threads

Implements FQueuedThreadPool.

◆ GetCurrentConcurrency()

int32 FQueuedThreadPoolWrapper::GetCurrentConcurrency ( ) const
inline

Definition at line 69 of file QueuedThreadPoolWrapper.h.

◆ GetMaxConcurrency()

virtual int32 FQueuedThreadPoolWrapper::GetMaxConcurrency ( ) const
inlineprotectedvirtual

Definition at line 178 of file QueuedThreadPoolWrapper.h.

◆ GetNumThreads()

int32 FQueuedThreadPoolWrapper::GetNumThreads ( ) const
overridevirtual

Get the number of queued threads

Implements FQueuedThreadPool.

◆ OnScheduled()

virtual void FQueuedThreadPoolWrapper::OnScheduled ( const IQueuedWork * )
inlineprotectedvirtual

Definition at line 181 of file QueuedThreadPoolWrapper.h.

◆ OnUnscheduled()

virtual void FQueuedThreadPoolWrapper::OnUnscheduled ( const IQueuedWork * )
inlineprotectedvirtual

Definition at line 184 of file QueuedThreadPoolWrapper.h.

◆ Pause()

void FQueuedThreadPoolWrapper::Pause ( )

Queued task are not scheduled against the wrapped thread-pool until resumed

◆ ReleaseWorkNoLock()

void FQueuedThreadPoolWrapper::ReleaseWorkNoLock ( FScheduledWork * Work)
private

◆ Resume()

void FQueuedThreadPoolWrapper::Resume ( int32 InNumQueuedWork = -1)

Resume a specified amount of queued work, or -1 to unpause.

◆ RetractQueuedWork()

bool FQueuedThreadPoolWrapper::RetractQueuedWork ( IQueuedWork * InQueuedWork)
overridevirtual

Attempts to retract a previously queued task.

Parameters
InQueuedWorkThe work to try to retract
Returns
true if the work was retracted
See also
AddQueuedWork

Implements FQueuedThreadPool.

◆ Schedule()

void FQueuedThreadPoolWrapper::Schedule ( FScheduledWork * Work = nullptr)
private
+ Here is the caller graph for this function:

◆ SetMaxConcurrency()

void FQueuedThreadPoolWrapper::SetMaxConcurrency ( int32 MaxConcurrency = -1)

Dynamically adjust the maximum number of concurrent tasks, -1 for unlimited.

◆ TryRetractWorkNoLock()

bool FQueuedThreadPoolWrapper::TryRetractWorkNoLock ( EQueuedWorkPriority InPriority)
private

Member Data Documentation

◆ bIsScheduling

bool FQueuedThreadPoolWrapper::bIsScheduling = false
private

Definition at line 206 of file QueuedThreadPoolWrapper.h.

◆ CurrentConcurrency

std::atomic<int32> FQueuedThreadPoolWrapper::CurrentConcurrency
private

Definition at line 204 of file QueuedThreadPoolWrapper.h.

◆ Lock

FCriticalSection FQueuedThreadPoolWrapper::Lock
protected

Definition at line 174 of file QueuedThreadPoolWrapper.h.

◆ MaxConcurrency

std::atomic<int32> FQueuedThreadPoolWrapper::MaxConcurrency
private

Definition at line 202 of file QueuedThreadPoolWrapper.h.

◆ MaxTaskToSchedule

int32 FQueuedThreadPoolWrapper::MaxTaskToSchedule
private

Definition at line 203 of file QueuedThreadPoolWrapper.h.

◆ PriorityMapper

TFunction<EQueuedWorkPriority(EQueuedWorkPriority)> FQueuedThreadPoolWrapper::PriorityMapper
private

Definition at line 197 of file QueuedThreadPoolWrapper.h.

◆ QueuedWork

FThreadPoolPriorityQueue FQueuedThreadPoolWrapper::QueuedWork
protected

Definition at line 175 of file QueuedThreadPoolWrapper.h.

◆ ScheduledWork

TMap<IQueuedWork*, FScheduledWork*> FQueuedThreadPoolWrapper::ScheduledWork
private

Definition at line 201 of file QueuedThreadPoolWrapper.h.

◆ WorkPool

TArray<FScheduledWork*> FQueuedThreadPoolWrapper::WorkPool
private

Definition at line 200 of file QueuedThreadPoolWrapper.h.

◆ WrappedQueuedThreadPool

FQueuedThreadPool* FQueuedThreadPoolWrapper::WrappedQueuedThreadPool
private

Definition at line 199 of file QueuedThreadPoolWrapper.h.

◆ WrappedQueuePriority

EQueuedWorkPriority FQueuedThreadPoolWrapper::WrappedQueuePriority
private

Definition at line 205 of file QueuedThreadPoolWrapper.h.


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