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>
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. | |
void | dump (void) const |
Dump the state of an object. | |
Accessors | |
TYPE * | ts_object (void) const |
TYPE * | operator-> () const |
operator TYPE * (void) const | |
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... |
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.
Definition at line 79 of file TSS_T.h.
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.
ts_obj | If 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. |
Definition at line 13 of file TSS_T.inl.
: type_ (type) { }
Deregister this object from thread-specific storage administration. Will cause all threads' copies of TYPE to be destroyed.
Definition at line 36 of file TSS_T.cpp.
{ #if defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)) if (this->once_) { # if defined (ACE_HAS_THR_C_DEST) ACE_TSS_Adapter *tss_adapter = this->ts_value (); this->ts_value (0); ACE_TSS_C_cleanup (tss_adapter); # else TYPE *ts_obj = this->ts_value (); this->ts_value (0); ACE_TSS<TYPE>::cleanup (ts_obj); # endif /* ACE_HAS_THR_C_DEST */ ACE_OS::thr_key_detach (this->key_, this); ACE_OS::thr_keyfree (this->key_); } #else // defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)) // We own it, we need to delete it. delete type_; #endif // defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)) }
void ACE_TSS< TYPE >::dump | ( | void | ) | const |
Dump the state of an object.
Definition at line 83 of file TSS_T.cpp.
{ #if defined (ACE_HAS_DUMP) // ACE_TRACE ("ACE_TSS<TYPE>::dump"); #if defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)) ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); this->keylock_.dump (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("key_ = %d\n"), this->key_)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nonce_ = %d\n"), this->once_)); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); #endif /* defined (ACE_HAS_THREADS) && (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)) */ #endif /* ACE_HAS_DUMP */ }
TYPE * ACE_TSS< TYPE >::make_TSS_TYPE | ( | void | ) | const [virtual] |
Hook for construction parameters.
Definition at line 73 of file TSS_T.cpp.
{ TYPE *temp = 0; ACE_NEW_RETURN (temp, TYPE, 0); return temp; }
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.
Definition at line 67 of file TSS_T.cpp.
{ return this->ts_get (); }
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.
Definition at line 61 of file TSS_T.cpp.
{ return this->ts_get (); }
TYPE * ACE_TSS< TYPE >::ts_get | ( | void | ) | const [protected] |
int ACE_TSS< TYPE >::ts_init | ( | void | ) | [protected] |
TYPE * ACE_TSS< TYPE >::ts_object | ( | void | ) | const |
Get the thread-specific object for this object.
Definition at line 25 of file TSS_T.inl.
{ return this->type_; }
TYPE * ACE_TSS< TYPE >::ts_object | ( | TYPE * | new_ts_obj | ) |
Set the thread-specific object for the calling thread. If this object has not been initialized yet, this method performs the initialization.
new_ts_obj | The new value for the calling thread's copy of this object. |