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

#include <LazySingleton.h>

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

Static Public Member Functions

static TGet ()
 
static void TearDown ()
 
static TTryGet ()
 

Private Member Functions

 TLazySingleton (void(*Constructor)(void *))
 
 ~TLazySingleton ()
 
TTryGetValue ()
 
TGetValue ()
 
void Reset ()
 

Static Private Member Functions

static TLazySingletonGetLazy (void(*Constructor)(void *))
 

Private Attributes

unsigned char Data [sizeof(T)]
 
TPtr
 

Additional Inherited Members

- Static Protected Member Functions inherited from FLazySingleton
template<class T >
static void Construct (void *Place)
 
template<class T >
static void Destruct (T *Instance)
 

Detailed Description

template<class T>
class TLazySingleton< T >

Lazy singleton that can be torn down explicitly

Defining DISABLE_LAZY_SINGLETON_DESTRUCTION stops automatic static destruction and will instead leak singletons that have not been explicitly torn down. This helps prevent shutdown crashes and deadlocks in quick exit scenarios such as ExitProcess() on Windows.

T must be default constructible.

Example use case:

struct FOo { static FOo& Get(); static void TearDown();

// If default constructor is private friend class FLazySingleton; };

// Only include in .cpp and do not inline Get() and TearDown() #include "Misc/LazySingleton.h"

FOo& FOo::Get() { return TLazySingleton<FOo>::Get(); }

void FOo::TearDown() { TLazySingleton<FOo>::TearDown(); }

Definition at line 50 of file LazySingleton.h.

Constructor & Destructor Documentation

◆ TLazySingleton()

template<class T >
TLazySingleton< T >::TLazySingleton ( void(*)(void *) Constructor)
inlineprivate

Definition at line 85 of file LazySingleton.h.

◆ ~TLazySingleton()

template<class T >
TLazySingleton< T >::~TLazySingleton ( )
inlineprivate

Definition at line 96 of file LazySingleton.h.

Member Function Documentation

◆ Get()

template<class T >
static T & TLazySingleton< T >::Get ( )
inlinestatic

Creates singleton once on first call. Thread-safe w.r.t. other Get() calls. Do not call after TearDown().

Definition at line 58 of file LazySingleton.h.

◆ GetLazy()

template<class T >
static TLazySingleton & TLazySingleton< T >::GetLazy ( void(*)(void *) Constructor)
inlinestaticprivate

Definition at line 76 of file LazySingleton.h.

◆ GetValue()

template<class T >
T & TLazySingleton< T >::GetValue ( )
inlineprivate

Definition at line 107 of file LazySingleton.h.

◆ Reset()

template<class T >
void TLazySingleton< T >::Reset ( )
inlineprivate

Definition at line 113 of file LazySingleton.h.

◆ TearDown()

template<class T >
static void TLazySingleton< T >::TearDown ( )
inlinestatic

Destroys singleton. No thread must access the singleton during or after this call.

Definition at line 64 of file LazySingleton.h.

◆ TryGet()

template<class T >
static T * TLazySingleton< T >::TryGet ( )
inlinestatic

Get or create singleton unless it's torn down

Definition at line 70 of file LazySingleton.h.

◆ TryGetValue()

template<class T >
T * TLazySingleton< T >::TryGetValue ( )
inlineprivate

Definition at line 102 of file LazySingleton.h.

Member Data Documentation

◆ Data

template<class T >
unsigned char TLazySingleton< T >::Data[sizeof(T)]
private

Definition at line 82 of file LazySingleton.h.

◆ Ptr

template<class T >
T* TLazySingleton< T >::Ptr
private

Definition at line 83 of file LazySingleton.h.


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