Zth (libzth)
zth::ThreadLocalSingleton< T > Class Template Reference

Singleton pattern, but only per-thread. More...

#include <util.h>

Public Types

typedef T singleton_type
 Alias of the T template parameter. More...
 

Static Public Member Functions

static safe_ptr< singleton_type >::type instance () noexcept
 Return the only instance of T within this thread. More...
 

Protected Member Functions

 ThreadLocalSingleton ()
 Constructor. More...
 
 ~ThreadLocalSingleton ()
 Destructor. More...
 

Detailed Description

template<typename T>
class zth::ThreadLocalSingleton< T >

Singleton pattern, but only per-thread.

This is the same as the zth::Singleton class, except that the instance is saved in thread-local storage.

Template Parameters
Tthe type of the subclass that inherits this ThreadLocalSingleton.

Definition at line 954 of file util.h.

Member Typedef Documentation

◆ singleton_type

template<typename T >
typedef T zth::ThreadLocalSingleton< T >::singleton_type

Alias of the T template parameter.

Definition at line 957 of file util.h.

Constructor & Destructor Documentation

◆ ThreadLocalSingleton()

template<typename T >
zth::ThreadLocalSingleton< T >::ThreadLocalSingleton ( )
inlineprotected

Constructor.

(Only) the first instance of the T within the current thread is recorded in m_instance.

Definition at line 965 of file util.h.

◆ ~ThreadLocalSingleton()

template<typename T >
zth::ThreadLocalSingleton< T >::~ThreadLocalSingleton ( )
inlineprotected

Destructor.

After destruction, instance() will return nullptr.

Definition at line 978 of file util.h.

Member Function Documentation

◆ instance()

template<typename T >
static safe_ptr<singleton_type>::type zth::ThreadLocalSingleton< T >::instance ( )
inlinestaticnoexcept

Return the only instance of T within this thread.

Returns
the instance, or nullptr when not constructed yet/anymore.

Definition at line 989 of file util.h.


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