libcommonc++  0.7
ThreadLocal< T > Class Template Reference

Thread-local storage smart pointer. More...

#include <ThreadLocal.h++>

Inheritance diagram for ThreadLocal< T >:

Public Member Functions

 ThreadLocal ()
 Construct a new ThreadLocal object. More...
 
virtual ~ThreadLocal ()
 Destructor. More...
 
T & operator* ()
 Pointer-dereference operator. More...
 
T * operator-> ()
 Pointer operator. More...
 
void setValue (T *value)
 Set the value of the thread-local object for the calling thread. More...
 
T * getValue ()
 Get the value of the thread-local object for the calling thread. More...
 

Static Public Member Functions

static int getSlotCount ()
 Get the maximum number of thread-local storage slots available on this platform. More...
 

Protected Member Functions

virtual T * initialValue ()
 Provide the intial value of the thread-local object for the calling thread. More...
 

Detailed Description

template<typename T>
class ccxx::ThreadLocal< T >

Thread-local storage smart pointer.

This template provides a mechanism for creating an object that has a distinct value for each thread that accesses it. The template parameter T is the type of thread-local object being created. Subclasses should override the initialValue() method to provide an initial value for the object.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ ThreadLocal()

Construct a new ThreadLocal object.

Exceptions
SystemExceptionIf a system-level error occurred.

◆ ~ThreadLocal()

virtual ~ThreadLocal ( )
virtual

Destructor.

Note that the destructor only deallocates system resources associated with the thread-local storage slot, not the actual values stored in that slot. Each thread should destroy its instance of the thread-local object when it is no longer needed.

Member Function Documentation

◆ getSlotCount()

static int getSlotCount ( )
static

Get the maximum number of thread-local storage slots available on this platform.

A return value of -1 indicates that there is no limit.

◆ getValue()

T* getValue ( )

Get the value of the thread-local object for the calling thread.

Returns
The current (possibly NULL) value.

◆ initialValue()

virtual T* initialValue ( )
protectedvirtual

Provide the intial value of the thread-local object for the calling thread.

The default implementation returns NULL.

Returns
The initial value.

Reimplemented in JavaThreadLocalBuffer, ThreadLocalBuffer< T >, and ThreadLocalCounter.

◆ operator*()

T& operator* ( )

Pointer-dereference operator.

Returns
A reference to the thread-local object.
Exceptions
NullPointerExceptionIf the value of the object was never initialized for the calling thread.

◆ operator->()

T* operator-> ( )

Pointer operator.

Returns
A pointer to the thread-local object.
Exceptions
NullPointerExceptionIf the value of the object was never initialized for the calling thread.

◆ setValue()

void setValue ( T *  value)

Set the value of the thread-local object for the calling thread.

Parameters
valueThe new value.

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