#include <TSS_T.h>
Collaboration diagram for ACE_TSS< TYPE >:
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 | |
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 | |
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... |
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.
Definition at line 10 of file TSS_T.inl.
00011 : type_ (type) 00012 { 00013 } |
|
Deregister this object from thread-specific storage administration. Will cause all threads' copies of TYPE to be destroyed. 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 } |
|
|
|
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_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_TEXT ("key_ = %d\n"), this->key_)); 00075 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nonce_ = %d"), this->once_)); 00076 ACE_DEBUG ((LM_DEBUG, ACE_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 } |
|
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 } |
|
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 51 of file TSS_T.cpp. References ACE_TSS< TYPE >::ts_get().
00052 { 00053 return this->ts_get (); 00054 } |
|
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 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 } |
|
|
|
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 } |
|
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 }
|
|
Get the thread-specific object for this object.
Definition at line 22 of file TSS_T.inl.
00023 { 00024 return this->type_; 00025 } |
|
Set the thread-specific object for the calling thread. If this object has not been initialized yet, this method performs the initialization.
Definition at line 28 of file TSS_T.inl.
|
|
This implementation only works for non-threading systems...
|