Zth (libzth)
Loading...
Searching...
No Matches
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.
 

Static Public Member Functions

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

Protected Member Functions

 ThreadLocalSingleton ()
 Constructor.
 
 ~ThreadLocalSingleton ()
 Destructor.
 

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 1146 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 1149 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 1157 of file util.h.

◆ ~ThreadLocalSingleton()

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

Destructor.

After destruction, instance() will return nullptr.

Definition at line 1170 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 1181 of file util.h.


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