Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FRunnableThread Class Referenceabstract

#include <RunnableThread.h>

+ Collaboration diagram for FRunnableThread:

Public Types

enum class  ThreadType { Real , Fake , Forkable }
 

Public Member Functions

virtual void SetThreadPriority (EThreadPriority NewPriority)=0
 
virtual bool SetThreadAffinity (const FThreadAffinity &Affinity)
 
virtual void Suspend (bool bShouldPause=true)=0
 
virtual bool Kill (bool bShouldWait=true)=0
 
virtual void WaitForCompletion ()=0
 
virtual FRunnableThread::ThreadType GetThreadType () const
 
const uint32 GetThreadID () const
 
const FStringGetThreadName () const
 
EThreadPriority GetThreadPriority () const
 
 FRunnableThread ()
 
virtual ~FRunnableThread ()
 

Static Public Member Functions

static uint32 GetTlsSlot ()
 
static FRunnableThreadCreate (class FRunnable *InRunnable, const TCHAR *ThreadName, uint32 InStackSize=0, EThreadPriority InThreadPri=TPri_Normal, uint64 InThreadAffinityMask=FPlatformAffinity::GetNoAffinityMask(), EThreadCreateFlags InCreateFlags=EThreadCreateFlags::None)
 
static FRunnableThreadGetRunnableThread ()
 

Protected Member Functions

virtual bool CreateInternal (FRunnable *InRunnable, const TCHAR *InThreadName, uint32 InStackSize=0, EThreadPriority InThreadPri=TPri_Normal, uint64 InThreadAffinityMask=0, EThreadCreateFlags InCreateFlags=EThreadCreateFlags::None)=0
 
void SetTls ()
 
void FreeTls ()
 

Protected Attributes

FString ThreadName
 
FRunnableRunnable
 
FEventThreadInitSyncEvent
 
uint64 ThreadAffinityMask
 
EThreadPriority ThreadPriority
 
uint32 ThreadID
 

Private Member Functions

virtual void Tick ()
 
virtual void OnPostFork ()
 
void PostCreate (EThreadPriority ThreadPriority)
 

Static Private Member Functions

static void SetupCreatedThread (FRunnableThread *&NewThread, class FRunnable *InRunnable, const TCHAR *ThreadName, uint32 InStackSize, EThreadPriority InThreadPri, uint64 InThreadAffinityMask, EThreadCreateFlags InCreateFlags)
 

Static Private Attributes

static uint32 RunnableTlsSlot
 

Friends

class FThreadSingletonInitializer
 
class FTlsAutoCleanup
 
class FThreadManager
 
class FForkableThread
 
class FForkProcessHelper
 

Detailed Description

Interface for runnable threads.

This interface specifies the methods used to manage a thread's life cycle.

Definition at line 19 of file RunnableThread.h.

Member Enumeration Documentation

◆ ThreadType

List of unique thread types we can create

Enumerator
Real 
Fake 
Forkable 

Definition at line 92 of file RunnableThread.h.

Constructor & Destructor Documentation

◆ FRunnableThread()

FRunnableThread::FRunnableThread ( )

Default constructor.

◆ ~FRunnableThread()

virtual FRunnableThread::~FRunnableThread ( )
virtual

Virtual destructor

Member Function Documentation

◆ Create()

static FRunnableThread * FRunnableThread::Create ( class FRunnable * InRunnable,
const TCHAR * ThreadName,
uint32 InStackSize = 0,
EThreadPriority InThreadPri = TPri_Normal,
uint64 InThreadAffinityMask = FPlatformAffinity::GetNoAffinityMask(),
EThreadCreateFlags InCreateFlags = EThreadCreateFlags::None )
static

Factory method to create a thread with the specified stack size and thread priority.

Parameters
InRunnableThe runnable object to execute
ThreadNameName of the thread
InStackSizeThe size of the stack to create. 0 means use the current thread's stack size
InThreadPriTells the thread whether it needs to adjust its priority or not. Defaults to normal priority
Returns
The newly created thread or nullptr if it failed

◆ CreateInternal()

virtual bool FRunnableThread::CreateInternal ( FRunnable * InRunnable,
const TCHAR * InThreadName,
uint32 InStackSize = 0,
EThreadPriority InThreadPri = TPri_Normal,
uint64 InThreadAffinityMask = 0,
EThreadCreateFlags InCreateFlags = EThreadCreateFlags::None )
protectedpure virtual

Creates the thread with the specified stack size and thread priority.

Parameters
InRunnableThe runnable object to execute
ThreadNameName of the thread
InStackSizeThe size of the stack to create. 0 means use the current thread's stack size
InThreadPriTells the thread whether it needs to adjust its priority or not. Defaults to normal priority
Returns
True if the thread and all of its initialization was successful, false otherwise

◆ FreeTls()

void FRunnableThread::FreeTls ( )
protected

Deletes all FTlsAutoCleanup objects created for this thread.

◆ GetRunnableThread()

static FRunnableThread * FRunnableThread::GetRunnableThread ( )
inlinestatic
Returns
a runnable thread that is executing this runnable, if return value is nullptr, it means the running thread can be game thread or a thread created outside the runnable interface

Definition at line 145 of file RunnableThread.h.

+ Here is the call graph for this function:

◆ GetThreadID()

const uint32 FRunnableThread::GetThreadID ( ) const
inline

Thread ID for this thread

Returns
ID that was set by CreateThread
See also
GetThreadName

Definition at line 114 of file RunnableThread.h.

◆ GetThreadName()

const FString & FRunnableThread::GetThreadName ( ) const
inline

Retrieves the given name of the thread

Returns
Name that was set by CreateThread
See also
GetThreadID

Definition at line 125 of file RunnableThread.h.

◆ GetThreadPriority()

EThreadPriority FRunnableThread::GetThreadPriority ( ) const
inline

Returns the runnable's thread priority

Definition at line 131 of file RunnableThread.h.

◆ GetThreadType()

virtual FRunnableThread::ThreadType FRunnableThread::GetThreadType ( ) const
inlinevirtual

Returns the type of thread this is

Definition at line 103 of file RunnableThread.h.

◆ GetTlsSlot()

static uint32 FRunnableThread::GetTlsSlot ( )
static

Gets a new Tls slot for storing the runnable thread pointer.

◆ Kill()

virtual bool FRunnableThread::Kill ( bool bShouldWait = true)
pure virtual

Tells the thread to exit. If the caller needs to know when the thread has exited, it should use the bShouldWait value. It's highly recommended not to kill the thread without waiting for it. Having a thread forcibly destroyed can cause leaks and deadlocks.

The kill method is calling Stop() on the runnable to kill the thread gracefully.

Parameters
bShouldWaitIf true, the call will wait infinitely for the thread to exit.
Returns
Always true

◆ OnPostFork()

virtual void FRunnableThread::OnPostFork ( )
inlineprivatevirtual

Called on the forked process when the forkable thread can create a real thread

Definition at line 202 of file RunnableThread.h.

◆ PostCreate()

void FRunnableThread::PostCreate ( EThreadPriority ThreadPriority)
private

Called after the internal thread is created so it can register debug information

◆ SetThreadAffinity()

virtual bool FRunnableThread::SetThreadAffinity ( const FThreadAffinity & Affinity)
inlinevirtual

Changes the thread affinity of the currently running thread

Parameters
ThreadAffinityMaskThe thread affinity to change to (can be 0 to keep previously set affinity mask)
ProcessorGroupThe thread group to change to
Returns
returns true if the affinity changed, false if affinity did not change

Definition at line 66 of file RunnableThread.h.

◆ SetThreadPriority()

virtual void FRunnableThread::SetThreadPriority ( EThreadPriority NewPriority)
pure virtual

Changes the thread priority of the currently running thread

Parameters
NewPriorityThe thread priority to change to

◆ SetTls()

void FRunnableThread::SetTls ( )
protected

Stores this instance in the runnable thread TLS slot.

◆ SetupCreatedThread()

static void FRunnableThread::SetupCreatedThread ( FRunnableThread *& NewThread,
class FRunnable * InRunnable,
const TCHAR * ThreadName,
uint32 InStackSize,
EThreadPriority InThreadPri,
uint64 InThreadAffinityMask,
EThreadCreateFlags InCreateFlags )
staticprivate

Called to setup a newly created RunnableThread

◆ Suspend()

virtual void FRunnableThread::Suspend ( bool bShouldPause = true)
pure virtual

Tells the thread to either pause execution or resume depending on the passed in value.

Parameters
bShouldPauseWhether to pause the thread (true) or resume (false)

◆ Tick()

virtual void FRunnableThread::Tick ( )
inlineprivatevirtual

Used by the thread manager to tick threads in single-threaded mode

Definition at line 197 of file RunnableThread.h.

◆ WaitForCompletion()

virtual void FRunnableThread::WaitForCompletion ( )
pure virtual

Halts the caller until this thread is has completed its work.

Friends And Related Symbol Documentation

◆ FForkableThread

friend class FForkableThread
friend

Definition at line 24 of file RunnableThread.h.

◆ FForkProcessHelper

Definition at line 25 of file RunnableThread.h.

◆ FThreadManager

Definition at line 23 of file RunnableThread.h.

◆ FThreadSingletonInitializer

Definition at line 21 of file RunnableThread.h.

◆ FTlsAutoCleanup

Definition at line 22 of file RunnableThread.h.

Member Data Documentation

◆ Runnable

FRunnable* FRunnableThread::Runnable
protected

The runnable object to execute on this thread.

Definition at line 177 of file RunnableThread.h.

◆ RunnableTlsSlot

uint32 FRunnableThread::RunnableTlsSlot
staticprivate

Index of TLS slot for FRunnableThread pointer.

Definition at line 28 of file RunnableThread.h.

◆ ThreadAffinityMask

uint64 FRunnableThread::ThreadAffinityMask
protected

The Affinity to run the thread with.

Definition at line 183 of file RunnableThread.h.

◆ ThreadID

uint32 FRunnableThread::ThreadID
protected

ID set during thread creation.

Definition at line 189 of file RunnableThread.h.

◆ ThreadInitSyncEvent

FEvent* FRunnableThread::ThreadInitSyncEvent
protected

Sync event to make sure that Init() has been completed before allowing the main thread to continue.

Definition at line 180 of file RunnableThread.h.

◆ ThreadName

FString FRunnableThread::ThreadName
protected

Holds the name of the thread.

Definition at line 174 of file RunnableThread.h.

◆ ThreadPriority

EThreadPriority FRunnableThread::ThreadPriority
protected

The priority to run the thread at.

Definition at line 186 of file RunnableThread.h.


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