glibmm 2.66.10

Public Types | Public Member Functions | Static Public Member Functions | List of all members
Glib::Threads::Private< T > Class Template Reference
Threads

Thread-local data pointer. More...

`#include <glibmm/threads.h>`

## Public Types
using | DestructorFunc = void (*) (void*)

## Public Member Functions
| Private (const Private< T > &)=delete
Private< T > & | operator= (const Private< T > &)=delete
| Private (DestructorFunc destructor_func=& Private< T >::delete_ptr)
| Constructor.
T * | get ()
| Gets the pointer stored in the calling thread.
void | set (T * data)
| Sets the pointer in the calling thread without calling destructor_func().
void | replace (T * data)
| Sets the pointer in the calling thread and calls destructor_func().
GPrivate * | gobj ()

## Static Public Member Functions
static void | delete_ptr (void * data)
| Deletes static_cast<T*>(data).

## Detailed Description

template<class T>
class Glib::Threads::Private< T >

Thread-local data pointer.

It is recommended that all instances of this class are statically allocated. The first time an instance is used (get(), set() or replace() is called) glib allocates a scarce OS resource that cannot be deallocated.

Deprecated
  Please use the thread_local keyword instead.

## Member Typedef Documentation

## ◆ DestructorFunc

template <class T>

using Glib::Threads::Private< T >::DestructorFunc = void (*) (void*)

## Constructor & Destructor Documentation

## ◆ Private() [1/2]

template <class T>

Glib::Threads::Private< T >::Private | ( | const Private< T > & |  | ) |
| delete

## ◆ Private() [2/2]

template <class T>

Glib::Threads::Private< T >::Private | ( | DestructorFunc | destructor_func = & Private< T >::delete_ptr | ) |
| inline explicit

Constructor.

Parameters

  destructor_func | Function pointer, or nullptr. If destructor_func is not nullptr and the stored data pointer is not nullptr, this function is called when replace() is called and when the thread exits.

## Member Function Documentation

## ◆ delete_ptr()

template <class T>

void Glib::Threads::Private< T >::delete_ptr | ( | void * | data | ) |
| static

Deletes static_cast<T*>(data).

## ◆ get()

template <class T>

T * Glib::Threads::Private< T >::get | ( |  | ) |
| inline

Gets the pointer stored in the calling thread.

Returns
  If no value has yet been set in this thread, nullptr is returned.

## ◆ gobj()

template <class T>

GPrivate * Glib::Threads::Private< T >::gobj | ( |  | ) |
| inline

## ◆ operator=()

template <class T>

Private< T > & Glib::Threads::Private< T >::operator= | ( | const Private< T > & |  | ) |
| delete

## ◆ replace()

template <class T>

void Glib::Threads::Private< T >::replace | ( | T * | data | ) |
| inline

Sets the pointer in the calling thread and calls destructor_func().

If a function pointer (and not nullptr) was specified in the constructor, and the stored data pointer before the call to replace() is not nullptr, then destructor_func() is called with this old pointer value.

Since glibmm 2.32

## ◆ set()

template <class T>

void Glib::Threads::Private< T >::set | ( | T * | data | ) |
| inline

Sets the pointer in the calling thread without calling destructor_func().