ACE  6.4.2
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ACE_TSS< TYPE > Class Template Reference

Allows objects that are "physically" in thread specific storage (i.e., private to a thread) to be accessed as though they were "logically" global to a program. More...

#include <TSS_T.h>

Inheritance diagram for ACE_TSS< TYPE >:
Inheritance graph
[legend]
Collaboration diagram for ACE_TSS< TYPE >:
Collaboration graph
[legend]

Public Member Functions

 ACE_TSS (TYPE *ts_obj=0)
 
virtual ~ACE_TSS (void)
 
TYPE * ts_object (TYPE *new_ts_obj)
 
virtual TYPE * make_TSS_TYPE (void) const
 Hook for construction parameters. More...
 
void dump (void) const
 Dump the state of an object. More...
 
Accessors

All accessors return a pointer to the calling thread's copy of the TYPE data. The pointer may be 0 on error conditions or if the calling thread's copy of the data has not yet been set. See specific method descriptions for complete details.

TYPE * ts_object (void) const
 
TYPE * operator-> () const
 
 operator TYPE * (void) const
 

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...
 

Protected Member Functions

TYPE * ts_get (void) const
 
int ts_init (void)
 

Protected Attributes

TYPE * type_
 This implementation only works for non-threading systems... More...
 

Additional Inherited Members

- Private Member Functions inherited from ACE_Copy_Disabled
 ACE_Copy_Disabled (void)
 Default constructor. More...
 

Detailed Description

template<class TYPE>
class ACE_TSS< TYPE >

Allows objects that are "physically" in thread specific storage (i.e., private to a thread) to be accessed as though they were "logically" global to a program.

This class helps to maintain a separate copy of an object for each thread that needs access to it. All threads access a single instance of ACE_TSS to obtain a pointer to a thread-specific copy of a TYPE object. Using a pointer to TYPE in TSS instead of TYPE itself is useful because, in addition to avoiding copies on what may be a complex class, it allows assignment of objects to thread-specific data that have arbitrarily complex constructors.

When the ACE_TSS object is destroyed, all threads's instances of the data are deleted.

Modern compilers have no problem using a built-in type for TYPE. However, if you must use an older compiler that won't work with a built-in type, the ACE_TSS_Type_Adapter class template, below, can be used for adapting built-in types to work with ACE_TSS.

Note
Beware when creating static instances of this type (as with any other, btw). The unpredictable order of initialization across different platforms may cause a situation where one uses the instance before it is fully initialized. That's why typically instances of this type are dynamicaly allocated. On the stack it is typically allocated inside the ACE_Thread::svc() method which limits its lifetime appropriately.

Constructor & Destructor Documentation

template<class TYPE>
ACE_TSS< TYPE >::ACE_TSS ( TYPE *  ts_obj = 0)
inline

Default constructor. Can also initialize this ACE_TSS instance, readying it for use by the calling thread as well as all other threads in the process. If the constructor does not initialize this object, the first access to it will perform the initialization, which could possibly (under odd error conditions) fail.

Parameters
ts_objIf non-zero, this object is initialized for use by all threads and ts_obj is used to set the thread-specific value for the calling thread. Other threads use the ts_object (TYPE *) method to set a specific value.
template<class TYPE>
virtual ACE_TSS< TYPE >::~ACE_TSS ( void  )
virtual

Deregister this object from thread-specific storage administration. Will cause all threads' copies of TYPE to be destroyed.

Member Function Documentation

template<class TYPE >
void ACE_TSS< TYPE >::dump ( void  ) const

Dump the state of an object.

template<class TYPE >
TYPE * ACE_TSS< TYPE >::make_TSS_TYPE ( void  ) const
virtual

Hook for construction parameters.

Reimplemented in ACE_TSS_Connection.

template<class TYPE >
ACE_TSS< TYPE >::operator TYPE * ( void  ) const

Obtain a pointer to the calling thread's TYPE object. If this ACE_TSS object hasn't been initialized, this method will initialize it as a side-affect. If the calling thread has not set a value, a default-constructed instance of TYPE is allocated and it becomes the thread's instance.

Returns
The calling thread's copy of the data. The returned pointer may be 0 under odd error conditions; check errno for further information.
template<class TYPE >
TYPE * ACE_TSS< TYPE >::operator-> ( void  ) const

Use a "smart pointer" to get the thread-specific data associated with this object. If this ACE_TSS object hasn't been initialized, this method will initialize it as a side-affect. If the calling thread has not set a value, a default-constructed instance of TYPE is allocated and it becomes the thread's instance.

Returns
The calling thread's copy of the data. The returned pointer may be 0 under odd error conditions; check errno for further information.
template<class TYPE >
TYPE * ACE_TSS< TYPE >::ts_get ( void  ) const
inlineprotected

Actually implements the code that retrieves the object from thread-specific storage.

template<class TYPE >
int ACE_TSS< TYPE >::ts_init ( void  )
inlineprotected

Factors out common code for initializing TSS. This must NOT be called with the lock held...

template<class TYPE>
TYPE * ACE_TSS< TYPE >::ts_object ( TYPE *  new_ts_obj)
inline

Set the thread-specific object for the calling thread. If this object has not been initialized yet, this method performs the initialization.

Parameters
new_ts_objThe new value for the calling thread's copy of this object.
Returns
The previous value of the calling thread's copy of this object; 0 if there was no previous value. This method also returns 0 on errors. To tell the difference between an error and a returned 0 pointer, it's recommended that one set errno to 0 prior to calling ts_object() and check for a new errno value if ts_object() returns 0.
template<class TYPE>
TYPE * ACE_TSS< TYPE >::ts_object ( void  ) const
inline

Get the thread-specific object for this object.

Returns
0 if the object has never been initialized, otherwise returns the calling thread's copy of the data. The returned pointer may be 0 under odd error conditions; check errno for further information.

Member Data Documentation

template<class TYPE>
ACE_TSS< TYPE >::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

template<class TYPE>
TYPE* ACE_TSS< TYPE >::type_
protected

This implementation only works for non-threading systems...


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