Public Member Functions | List of all members
Sawyer::MultiInstanceTls< T > Class Template Reference


template<typename T>
class Sawyer::MultiInstanceTls< T >

Thread local data per object instance.

This is useful when you have a class non-static data member that needs to be thread-local.

struct MyClass {
static SAWYER_THREAD_LOCAL int foo; // static thread-local using __thread, thread_local, etc.
MultiInstanceTls<int> bar; // per-instance thread local
MyClass a, b; = 5; = 6;
assert( + 1 ==;

where SAWYER_THREAD_LOCAL is a macro expanding to, perhaps, "__thread". C++ only allows thread-local global variables or static member data, as with foo above. That means that and alias one another. But if you need some member data to be thread-local per object, you can declare it as MultiInstanceTls<T>. For instance, and are different storage locations, and are also thread-local.

Definition at line 188 of file Synchronization.h.

#include <Synchronization.h>

Public Member Functions

 MultiInstanceTls ()
 Default-constructed value. More...
 MultiInstanceTls (const T &value)
 Initialize value. More...
MultiInstanceTlsoperator= (const T &value)
 Assignment operator. More...
T & operator* ()
const T & operator* () const
T * operator-> ()
const T * operator-> () const
 operator T () const
 Implicit conversion to enclosed type. More...
T & get ()
 Get interior object.
const T & get () const
 Get interior object.

Constructor & Destructor Documentation

template<typename T >
Sawyer::MultiInstanceTls< T >::MultiInstanceTls ( )

Default-constructed value.

Definition at line 199 of file Synchronization.h.

template<typename T >
Sawyer::MultiInstanceTls< T >::MultiInstanceTls ( const T &  value)

Initialize value.

Definition at line 206 of file Synchronization.h.

Member Function Documentation

template<typename T >
MultiInstanceTls& Sawyer::MultiInstanceTls< T >::operator= ( const T &  value)

Assignment operator.

Definition at line 213 of file Synchronization.h.

template<typename T >
Sawyer::MultiInstanceTls< T >::operator T ( ) const

Implicit conversion to enclosed type.

This is so that the data member can be used as if it were type T rather than a MultiInstanceTls object.

Definition at line 259 of file Synchronization.h.

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