ThreadLocal< T > Class Template Reference

Thread-local storage smart pointer. More...

#include <ThreadLocal.h++>

Inheritance diagram for ThreadLocal< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

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

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 (  )  throw (SystemException)

Construct a new ThreadLocal object.

Exceptions:
SystemException If a system-level error occurred.
virtual ~ThreadLocal (  )  throw () [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

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.

T* getValue (  )  throw ()

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

Returns:
The current (possibly NULL) value.
virtual T* initialValue (  )  [protected, virtual]

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.

T& operator* (  )  throw (NullPointerException)

Pointer-dereference operator.

Returns:
A reference to the thread-local object.
Exceptions:
NullPointerException If the value of the object was never initialized for the calling thread.
T* operator-> (  )  throw (NullPointerException)

Pointer operator.

Returns:
A pointer to the thread-local object.
Exceptions:
NullPointerException If the value of the object was never initialized for the calling thread.
void setValue ( T *  value  )  throw ()

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

Parameters:
value The new value.

The documentation for this class was generated from the following file:
Generated on Sat Nov 26 16:49:09 2011 for libcommonc++ by  doxygen 1.6.3