C12Adapter Opensource C++ Interface
MThreadLocalPointer< T > Class Template Reference

Thread-local pointer, the one that will be different in every thread, API based portable implementation. More...

Public Member Functions

 MThreadLocalPointer ()
 Constructor that does not initialize the value of the pointer. More...
 
 MThreadLocalPointer (const T *p)
 Constructor to initialize the pointer with the given value.
 
 MThreadLocalPointer (const MThreadLocalPointer &other)
 Copy constructor that takes another thread local pointer. More...
 
 ~MThreadLocalPointer ()
 Destructor, clear system resources.
 
void operator= (const MThreadLocalPointer &other)
 Assignment operator that takes another thread local pointer. More...
 
void operator= (T *ptr)
 Assignment operator that takes a pointer. More...
 
 operator T * ()
 Return the pointer that is associated with this thread local pointer class. More...
 
T & operator* ()
 Return the reference to client object associated with this pointer class. More...
 
const T & operator* () const
 Return the constant reference to client object associated with this shared pointer class. More...
 
T * operator-> ()
 Dereference the pointer that is associated with this class. More...
 
const T * operator-> () const
 Dereference the constant pointer that is associated with this shared pointer class. More...
 

Friends

bool operator== (const MThreadLocalPointer< T > &p1, const MThreadLocalPointer< T > &p2)
 Equality comparison operator that takes two thread local pointers.
 
bool operator== (const MThreadLocalPointer< T > &p1, const T *p2)
 Equality comparison operator that takes a shared pointer and a pointer.
 
bool operator== (const T *p1, const MThreadLocalPointer< T > &p2)
 Equality comparison operator that takes a pointer and a shared pointer.
 
bool operator!= (const MThreadLocalPointer< T > &p1, const MThreadLocalPointer< T > &p2)
 Inequality comparison operator that takes two shared pointers.
 
bool operator!= (const MThreadLocalPointer< T > &p1, const T *p2)
 Inequality comparison operator that takes a shared pointer and a pointer.
 
bool operator!= (const T *p1, const MThreadLocalPointer< T > &p2)
 Inequality comparison operator that takes a pointer and a shared pointer.
 

Detailed Description

template<class T>
class MThreadLocalPointer< T >

Thread-local pointer, the one that will be different in every thread, API based portable implementation.

There are three opportunities for the user to use Thread local storage:

  1. Use this thread local pointer class, which is the most portable way.
  2. Use native compiler declaration by utilizing the macro M_THREAD_LOCAL_STORAGE_VARIABLE.
  3. Use macro M_THREAD_LOCAL_POINTER that attempts to be efficient on platforms that support approach 2, while rolling back to approach 1 on less efficient platforms.
See also
M_THREAD_LOCAL_STORAGE_VARIABLE Efficient approach, less portable.
M_THREAD_LOCAL_POINTER Efficient on platforms that support thread local variable, portable otherwise.
M__USE_THREAD_LOCAL_POINTER Macro that determines which approach is used by M_THREAD_LOCAL_POINTER.

Constructor & Destructor Documentation

template<class T >
MThreadLocalPointer< T >::MThreadLocalPointer ( )
inline

Constructor that does not initialize the value of the pointer.

The value of the pointer will remain undefined until the assignment operator is called.

template<class T >
MThreadLocalPointer< T >::MThreadLocalPointer ( const MThreadLocalPointer< T > &  other)
inline

Copy constructor that takes another thread local pointer.

Parameters
otherOther object of the same type or its child.

Member Function Documentation

template<class T >
MThreadLocalPointer< T >::operator T * ( )
inline

Return the pointer that is associated with this thread local pointer class.

This makes possible the pointer-like behavior of this class.

template<class T >
T& MThreadLocalPointer< T >::operator* ( )
inline

Return the reference to client object associated with this pointer class.

This makes possible the pointer-like behavior of this class.

template<class T >
const T& MThreadLocalPointer< T >::operator* ( ) const
inline

Return the constant reference to client object associated with this shared pointer class.

This makes possible the pointer-like behavior of this class.

template<class T >
T* MThreadLocalPointer< T >::operator-> ( )
inline

Dereference the pointer that is associated with this class.

This makes possible the pointer-like behavior of this class.

template<class T >
const T* MThreadLocalPointer< T >::operator-> ( ) const
inline

Dereference the constant pointer that is associated with this shared pointer class.

This makes possible the pointer-like behavior of this class.

template<class T >
void MThreadLocalPointer< T >::operator= ( const MThreadLocalPointer< T > &  other)
inline

Assignment operator that takes another thread local pointer.

The operator returns void, and the chaining of a few of them is impossible.

Parameters
otherOther object of the same type or its child.
template<class T >
void MThreadLocalPointer< T >::operator= ( T *  ptr)
inline

Assignment operator that takes a pointer.

The operator returns void, and the chaining of a few of them is impossible.