Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
TThreadSingleton< T > Class Template Reference

#include <ThreadSingleton.h>

+ Inheritance diagram for TThreadSingleton< T >:
+ Collaboration diagram for TThreadSingleton< T >:

Static Public Member Functions

static FORCEINLINE TGet ()
 
static FORCEINLINE TGet (TFunctionRef< FTlsAutoCleanup *()> CreateInstance)
 
static FORCEINLINE TTryGet ()
 
static FORCEINLINE TInject (T *Instance)
 

Protected Member Functions

 TThreadSingleton ()
 
virtual ~TThreadSingleton ()
 

Static Protected Member Functions

static FTlsAutoCleanupCreateInstance ()
 

Protected Attributes

const uint32 ThreadId
 

Static Private Member Functions

static uint32GetTlsSlot ()
 

Additional Inherited Members

- Public Member Functions inherited from FTlsAutoCleanup
virtual ~FTlsAutoCleanup ()
 
void Register ()
 

Detailed Description

template<class T>
class TThreadSingleton< T >

This a special version of singleton. It means that there is created only one instance for each thread. Calling Get() method is thread-safe.

Definition at line 41 of file ThreadSingleton.h.

Constructor & Destructor Documentation

◆ TThreadSingleton()

template<class T >
TThreadSingleton< T >::TThreadSingleton ( )
inlineprotected

Default constructor.

Definition at line 69 of file ThreadSingleton.h.

◆ ~TThreadSingleton()

template<class T >
virtual TThreadSingleton< T >::~TThreadSingleton ( )
inlineprotectedvirtual

Definition at line 73 of file ThreadSingleton.h.

Member Function Documentation

◆ CreateInstance()

template<class T >
static FTlsAutoCleanup * TThreadSingleton< T >::CreateInstance ( )
inlinestaticprotected
Returns
a new instance of the thread singleton.

Definition at line 86 of file ThreadSingleton.h.

◆ Get() [1/2]

template<class T >
static FORCEINLINE T & TThreadSingleton< T >::Get ( )
inlinestatic
Returns
an instance of a singleton for the current thread.

Definition at line 99 of file ThreadSingleton.h.

◆ Get() [2/2]

template<class T >
static FORCEINLINE T & TThreadSingleton< T >::Get ( TFunctionRef< FTlsAutoCleanup *()> CreateInstance)
inlinestatic
Parameters
CreateInstanceFunction to call when a new instance must be created.
Returns
an instance of a singleton for the current thread.

Definition at line 108 of file ThreadSingleton.h.

◆ GetTlsSlot()

template<class T >
static uint32 & TThreadSingleton< T >::GetTlsSlot ( )
inlinestaticprivate
Returns
TLS slot that holds a TThreadSingleton.

Definition at line 59 of file ThreadSingleton.h.

◆ Inject()

template<class T >
static FORCEINLINE T * TThreadSingleton< T >::Inject ( T * Instance)
inlinestatic
Returns
sets the TLS store to the instance and returns the previous instance.

Definition at line 124 of file ThreadSingleton.h.

◆ TryGet()

template<class T >
static FORCEINLINE T * TThreadSingleton< T >::TryGet ( )
inlinestatic
Returns
pointer to an instance of a singleton for the current thread. May be nullptr, prefer to use access by reference

Definition at line 116 of file ThreadSingleton.h.

Member Data Documentation

◆ ThreadId

template<class T >
const uint32 TThreadSingleton< T >::ThreadId
protected

Thread ID of this thread singleton.

Definition at line 92 of file ThreadSingleton.h.


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