Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_TSS 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 <Synch_T.h>

Inheritance diagram for ACE_TSS:

Inheritance graph
[legend]
Collaboration diagram for ACE_TSS:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_TSS (TYPE *ts_obj=0)
virtual ~ACE_TSS (void)
 Deregister with thread-key administration. More...

TYPE * ts_object (void) const
TYPE * ts_object (TYPE *)
 Set the thread-specific object for the key associated with this object. More...

TYPE * operator-> () const
 Use a "smart pointer" to get the thread-specific object associated with the <key_>. More...

 operator TYPE * (void) const
 Return or create and return the calling threads TYPE object. More...

virtual TYPE * make_TSS_TYPE (void) const
 Hook for construction parameters. More...

void dump (void) const
 Dump the state of an object. More...


Protected Methods

TYPE * ts_get (void) const
 Actually implements the code that retrieves the object from thread-specific storage. More...

int ts_init (void) const
 Factors out common code for initializing TSS. This must NOT be called with the lock held... More...

void operator= (const ACE_TSS< TYPE > &)
 ACE_TSS (const ACE_TSS< TYPE > &)

Protected Attributes

TYPE * type_
 This implementation only works for non-threading systems... 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 is a wrapper around the OS thread library thread-specific functions. It uses the <C++ operator->> to shield applications from the details of accessing thread-specific storage.

NOTE: For maximal portability, <TYPE> cannot be a built-in type, but instead should be a user-defined class (some compilers will allow a built-in type, others won't). See template class ACE_TSS_Type_Adapter, below, for adapting built-in types to work with ACE_TSS.

Definition at line 223 of file Synch_T.h.


Constructor & Destructor Documentation

template<class TYPE>
ACE_INLINE ACE_TSS< TYPE >::ACE_TSS TYPE *    ts_obj = 0
 

If caller has passed us a non-NULL ts_obj *, then we'll just use this to initialize the thread-specific value (but only for the calling thread). Thus, subsequent calls to <operator->> in this thread will return this value. This is useful since it enables us to assign objects to thread-specific data that have arbitrarily complex constructors.

Definition at line 422 of file Synch_T.i.

00423   : type_ (type)
00424 {
00425 }

template<class TYPE>
ACE_TSS< TYPE >::~ACE_TSS void    [virtual]
 

Deregister with thread-key administration.

Definition at line 242 of file Synch_T.cpp.

References ACE_OS::thr_key_detach.

00243 {
00244   // We can't call <ACE_OS::thr_keyfree> until *all* of the threads
00245   // that are using that key have done an <ACE_OS::thr_key_detach>.
00246   // Otherwise, we'll end up with "dangling TSS pointers."
00247   ACE_OS::thr_key_detach (this);
00248 }

template<class TYPE>
ACE_TSS< TYPE >::ACE_TSS const ACE_TSS< TYPE > &    [protected]
 


Member Function Documentation

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

Dump the state of an object.

Reimplemented in ACE_TSS_Connection.

Definition at line 273 of file Synch_T.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, and LM_DEBUG.

Referenced by ACE_TSS_Connection::dump.

00274 {
00275 // ACE_TRACE ("ACE_TSS<TYPE>::dump");
00276 #if defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION))
00277   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00278   this->keylock_.dump ();
00279   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("key_ = %d\n"), this->key_));
00280   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nonce_ = %d"), this->once_));
00281   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00282   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00283 #endif /* defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)) */
00284 }

template<class TYPE>
TYPE * ACE_TSS< TYPE >::make_TSS_TYPE void    const [virtual]
 

Hook for construction parameters.

Reimplemented in ACE_TSS_Connection.

Definition at line 263 of file Synch_T.cpp.

References ACE_NEW_RETURN.

00264 {
00265   TYPE *temp = 0;
00266   ACE_NEW_RETURN (temp,
00267                   TYPE,
00268                   0);
00269   return temp;
00270 }

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

Return or create and return the calling threads TYPE object.

Definition at line 257 of file Synch_T.cpp.

References ts_get.

00258 {
00259   return this->ts_get ();
00260 }

template<class TYPE>
TYPE * ACE_TSS< TYPE >::operator->   const
 

Use a "smart pointer" to get the thread-specific object associated with the <key_>.

Definition at line 251 of file Synch_T.cpp.

References ts_get.

Referenced by ACE_TSS_Connection::get_connection.

00252 {
00253   return this->ts_get ();
00254 }

template<class TYPE>
void ACE_TSS< TYPE >::operator= const ACE_TSS< TYPE > &    [protected]
 

template<class TYPE>
ACE_INLINE TYPE * ACE_TSS< TYPE >::ts_get void    const [protected]
 

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

Definition at line 447 of file Synch_T.i.

References type_.

Referenced by operator TYPE *, and operator->.

00448 {
00449   return this->type_;
00450 }

template<class TYPE>
ACE_INLINE int ACE_TSS< TYPE >::ts_init void    const [protected]
 

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

Definition at line 428 of file Synch_T.i.

00429 {
00430   return 0;
00431 }

template<class TYPE>
ACE_INLINE TYPE * ACE_TSS< TYPE >::ts_object TYPE *   
 

Set the thread-specific object for the key associated with this object.

Definition at line 440 of file Synch_T.i.

References type_.

00441 {
00442   this->type_ = type;
00443   return this->type_;
00444 }

template<class TYPE>
ACE_INLINE TYPE * ACE_TSS< TYPE >::ts_object void    const
 

Get the thread-specific object for the key associated with this object. Returns 0 if the data has never been initialized, otherwise returns a pointer to the data.

Definition at line 434 of file Synch_T.i.

References type_.

00435 {
00436   return this->type_;
00437 }


Member Data Documentation

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

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

Definition at line 283 of file Synch_T.h.

Referenced by ts_get, and ts_object.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:58:41 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002