UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TThreadSingleton< T > Class Template Reference

#include <ThreadSingleton.h>

+ Inheritance diagram for TThreadSingleton< T >:

Static Public Member Functions

static FORCEINLINE T & Get ()
 
static FORCEINLINE T & Get (TFunctionRef< FTlsAutoCleanup *()> CreateInstance)
 
static FORCEINLINE T * TryGet ()
 
static FORCEINLINE T * Inject (T *Instance)
 

Protected Member Functions

 TThreadSingleton ()
 
virtual ~TThreadSingleton ()
 

Static Protected Member Functions

static FTlsAutoCleanupCreateInstance ()
 

Protected Attributes

const uint32 ThreadId
 

Additional Inherited Members

- Public Member Functions inherited from FTlsAutoCleanup
virtual ~FTlsAutoCleanup ()
 
CORE_API 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.

Constructor & Destructor Documentation

◆ TThreadSingleton()

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

Default constructor.

◆ ~TThreadSingleton()

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

Member Function Documentation

◆ CreateInstance()

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

◆ Get() [1/2]

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

◆ 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.

◆ 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.

◆ 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

Member Data Documentation

◆ ThreadId

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

Thread ID of this thread singleton.


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