TSS_Cleanup_Instance Class Reference

Collaboration diagram for TSS_Cleanup_Instance:

Collaboration graph
[legend]
List of all members.

Public Types

enum  Purpose { CREATE, USE, DESTROY }

Public Member Functions

 TSS_Cleanup_Instance (Purpose purpose=USE)
 ~TSS_Cleanup_Instance ()
bool valid ()
ACE_TSS_Cleanupoperator-> ()

Private Types

enum  { FLAG_DELETING = 1, FLAG_VALID_CHECKED = 2 }

Private Member Functions

ACE_TSS_Cleanupoperator * ()

Private Attributes

ACE_TSS_Cleanupptr_
unsigned short flags_

Static Private Attributes

unsigned int reference_count_ = 0
ACE_TSS_Cleanupinstance_ = 0
ACE_Thread_Mutexmutex_ = 0
ACE_Thread_Condition< ACE_Thread_Mutex > * condition_ = 0

Detailed Description

class to manage an instance pointer to ACE_TSS_Cleanup. Note: that the double checked locking pattern doesn't allow safe deletion. Callers who wish to access the singleton ACE_TSS_Cleanup must do so by instantiating a TSS_Cleanup_Instance, calling the valid method to be sure the ACE_TSS_Cleanup is available, then using the TSS_Cleanup_Instance as a pointer to the instance. Construction argument to the TSS_Cleanup_Instance determines how it is to be used: CREATE means allow this call to create an ACE_TSS_Cleanup if necessary. USE means use the existing ACE_TSS_Cleanup, but do not create a new one. DESTROY means provide exclusive access to the ACE_TSS_Cleanup, then delete it when the TSS_Cleanup_Instance goes out of scope.

Definition at line 676 of file OS_NS_Thread.cpp.


Member Enumeration Documentation

anonymous enum [private]
 

Enumeration values:
FLAG_DELETING 
FLAG_VALID_CHECKED 

Definition at line 704 of file OS_NS_Thread.cpp.

00705   {
00706     FLAG_DELETING = 1,
00707     FLAG_VALID_CHECKED = 2
00708   };

enum TSS_Cleanup_Instance::Purpose
 

Enumeration values:
CREATE 
USE 
DESTROY 

Definition at line 679 of file OS_NS_Thread.cpp.

00680   {
00681     CREATE,
00682     USE,
00683     DESTROY
00684   };


Constructor & Destructor Documentation

TSS_Cleanup_Instance::TSS_Cleanup_Instance Purpose  purpose = USE  ) 
 

Definition at line 711 of file OS_NS_Thread.cpp.

References ACE_ASSERT, ACE_NEW, ACE_SET_BITS, condition_, CREATE, DESTROY, FLAG_DELETING, USE, and ACE_Condition< ACE_Thread_Mutex >::wait().

00712   : ptr_(0)
00713   , flags_(0)
00714 {
00715   // During static construction or construction of the ACE_Object_Manager,
00716   // there can be only one thread in this constructor at any one time, so
00717   // it's safe to check for a zero mutex_.  If it's zero, we create a new
00718   // mutex and condition variable.
00719   if (mutex_ == 0)
00720     {
00721       ACE_NEW (mutex_, ACE_Thread_Mutex ());
00722       ACE_NEW (condition_, ACE_Thread_Condition<ACE_Thread_Mutex> (*mutex_));
00723     }
00724 
00725   ACE_Guard<ACE_Thread_Mutex> guard(*mutex_);
00726 
00727   if (purpose == CREATE)
00728   {
00729     if (instance_ == 0)
00730     {
00731       instance_ = new ACE_TSS_Cleanup();
00732     }
00733     ptr_ = instance_;
00734     ++reference_count_;
00735   }
00736   else if(purpose == DESTROY)
00737   {
00738     if (instance_ != 0)
00739     {
00740       ptr_ = instance_;
00741       instance_ = 0;
00742       ACE_SET_BITS(flags_, FLAG_DELETING);
00743       while (reference_count_ > 0)
00744       {
00745         condition_->wait();
00746       }
00747     }
00748   }
00749   else // must be normal use
00750   {
00751     ACE_ASSERT(purpose == USE);
00752     if (instance_ != 0)
00753       {
00754         ptr_ = instance_;
00755         ++reference_count_;
00756       }
00757   }
00758 }

TSS_Cleanup_Instance::~TSS_Cleanup_Instance  ) 
 

Definition at line 760 of file OS_NS_Thread.cpp.

References ACE_ASSERT, ACE_BIT_ENABLED, condition_, FLAG_DELETING, and ACE_Condition< ACE_Thread_Mutex >::signal().

00761 {
00762   // Variable to hold the mutex_ to delete outside the scope of the
00763   // guard.
00764   ACE_Thread_Mutex *del_mutex = 0;
00765 
00766   // scope the guard
00767   {
00768     ACE_Guard<ACE_Thread_Mutex> guard (*mutex_);
00769     if (ptr_ != 0)
00770       {
00771         if (ACE_BIT_ENABLED (flags_, FLAG_DELETING))
00772           {
00773             ACE_ASSERT(instance_ == 0);
00774             ACE_ASSERT(reference_count_ == 0);
00775             delete ptr_;
00776             del_mutex = mutex_ ;
00777             mutex_ = 0;
00778           }
00779         else
00780           {
00781             ACE_ASSERT (reference_count_ > 0);
00782             --reference_count_;
00783             if (reference_count_ == 0 && instance_ == NULL)
00784               condition_->signal ();
00785           }
00786       }
00787   }// end of guard scope
00788 
00789   if (del_mutex != 0)
00790     {
00791       delete condition_;
00792       condition_ = 0;
00793       delete del_mutex;
00794     }
00795 }


Member Function Documentation

ACE_TSS_Cleanup * TSS_Cleanup_Instance::operator *  )  [private]
 

Definition at line 805 of file OS_NS_Thread.cpp.

References ACE_ASSERT, ACE_BIT_ENABLED, and FLAG_VALID_CHECKED.

00806 {
00807   ACE_ASSERT(ACE_BIT_ENABLED(flags_, FLAG_VALID_CHECKED));
00808   return instance_;
00809 }

ACE_TSS_Cleanup * TSS_Cleanup_Instance::operator->  ) 
 

Definition at line 812 of file OS_NS_Thread.cpp.

References ACE_ASSERT, ACE_BIT_ENABLED, and FLAG_VALID_CHECKED.

00813 {
00814   ACE_ASSERT(ACE_BIT_ENABLED(flags_, FLAG_VALID_CHECKED));
00815   return instance_;
00816 }

bool TSS_Cleanup_Instance::valid  ) 
 

Definition at line 798 of file OS_NS_Thread.cpp.

References ACE_SET_BITS, and FLAG_VALID_CHECKED.

Referenced by ACE_OS::cleanup_tss(), ACE_OS::thr_key_detach(), ACE_OS::thr_key_used(), ACE_OS::thr_keycreate(), ACE_OS::thr_keyfree(), and ACE_OS::thr_setspecific().

00799 {
00800   ACE_SET_BITS(flags_, FLAG_VALID_CHECKED);
00801   return (this->instance_ != NULL);
00802 }


Member Data Documentation

ACE_Thread_Condition< ACE_Thread_Mutex > * TSS_Cleanup_Instance::condition_ = 0 [static, private]
 

Definition at line 822 of file OS_NS_Thread.cpp.

Referenced by TSS_Cleanup_Instance(), and ~TSS_Cleanup_Instance().

unsigned short TSS_Cleanup_Instance::flags_ [private]
 

Definition at line 703 of file OS_NS_Thread.cpp.

ACE_TSS_Cleanup * TSS_Cleanup_Instance::instance_ = 0 [static, private]
 

Definition at line 820 of file OS_NS_Thread.cpp.

ACE_Thread_Mutex * TSS_Cleanup_Instance::mutex_ = 0 [static, private]
 

Definition at line 821 of file OS_NS_Thread.cpp.

ACE_TSS_Cleanup* TSS_Cleanup_Instance::ptr_ [private]
 

Definition at line 702 of file OS_NS_Thread.cpp.

unsigned int TSS_Cleanup_Instance::reference_count_ = 0 [static, private]
 

Definition at line 819 of file OS_NS_Thread.cpp.


The documentation for this class was generated from the following file:
Generated on Thu Nov 9 11:33:40 2006 for ACE by doxygen 1.3.6