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>

Collaboration diagram for ACE_TSS< TYPE >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

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

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

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


Protected Member Functions

TYPE * ts_get (void) const
int ts_init (void)
void operator= (const ACE_TSS< TYPE > &)
 ACE_TSS (const ACE_TSS< TYPE > &)

Protected Attributes

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


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, 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.

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 you'd use 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.

Definition at line 74 of file TSS_T.h.


Constructor & Destructor Documentation

template<class TYPE>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL 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 10 of file TSS_T.inl.

00011   : type_ (type)
00012 {
00013 }

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

Deregister with thread-key administration.

Definition at line 30 of file TSS_T.cpp.

References ACE_OS::thr_key_detach(), and ACE_OS::thr_keyfree().

00031 {
00032 #if defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION))
00033   if (this->once_ != 0)
00034   {
00035     ACE_OS::thr_key_detach (this->key_, this);
00036     ACE_OS::thr_keyfree (this->key_);
00037   }
00038 #else // defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION))
00039   // We own it, we need to delete it.
00040   delete type_;
00041 #endif // defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION))
00042 }

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 67 of file TSS_T.cpp.

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

Referenced by ACE_TSS_Connection::dump().

00068 {
00069 #if defined (ACE_HAS_DUMP)
00070 // ACE_TRACE ("ACE_TSS<TYPE>::dump");
00071 #if defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION))
00072   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00073   this->keylock_.dump ();
00074   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("key_ = %d\n"), this->key_));
00075   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nonce_ = %d"), this->once_));
00076   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00077   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00078 #endif /* defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)) */
00079 #endif /* ACE_HAS_DUMP */
00080 }

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 57 of file TSS_T.cpp.

References ACE_NEW_RETURN.

00058 {
00059   TYPE *temp = 0;
00060   ACE_NEW_RETURN (temp,
00061                   TYPE,
00062                   0);
00063   return temp;
00064 }

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

Return or create and return the calling threads TYPE object.

Definition at line 51 of file TSS_T.cpp.

References ACE_TSS< TYPE >::ts_get().

00052 {
00053   return this->ts_get ();
00054 }

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

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

Definition at line 45 of file TSS_T.cpp.

References ACE_TSS< TYPE >::ts_get().

Referenced by ACE_TSS_Connection::get_connection().

00046 {
00047   return this->ts_get ();
00048 }

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 35 of file TSS_T.inl.

Referenced by ACE_TSS< TYPE >::operator TYPE *(), and ACE_TSS< TYPE >::operator->().

00036 {
00037   return this->type_;
00038 }

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

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

Definition at line 16 of file TSS_T.inl.

00017 {
00018   return 0;
00019 }

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 28 of file TSS_T.inl.

00029 {
00030   this->type_ = type;
00031   return this->type_;
00032 }

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 22 of file TSS_T.inl.

00023 {
00024   return this->type_;
00025 }


Member Data Documentation

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

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

Definition at line 135 of file TSS_T.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:31:58 2006 for ACE by doxygen 1.3.6