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_Mutex * mutex_ = 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 623 of file OS_NS_Thread.cpp.


Member Enumeration Documentation

anonymous enum [private]
 

Enumeration values:
FLAG_DELETING 
FLAG_VALID_CHECKED 

Definition at line 651 of file OS_NS_Thread.cpp.

00652   {
00653     FLAG_DELETING = 1,
00654     FLAG_VALID_CHECKED = 2
00655   };

enum TSS_Cleanup_Instance::Purpose
 

Enumeration values:
CREATE 
USE 
DESTROY 

Definition at line 626 of file OS_NS_Thread.cpp.

00627   {
00628     CREATE,
00629     USE,
00630     DESTROY
00631   };


Constructor & Destructor Documentation

TSS_Cleanup_Instance::TSS_Cleanup_Instance Purpose  purpose = USE  ) 
 

Definition at line 658 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().

00659   : ptr_(0)
00660   , flags_(0)
00661 {
00662   // During static construction or construction of the ACE_Object_Manager,
00663   // there can be only one thread in this constructor at any one time, so
00664   // it's safe to check for a zero mutex_.  If it's zero, we create a new
00665   // mutex and condition variable.
00666   if (mutex_ == 0)
00667     {
00668       ACE_NEW (mutex_, ACE_Thread_Mutex ());
00669       ACE_NEW (condition_, ACE_Thread_Condition<ACE_Thread_Mutex> (*mutex_));
00670     }
00671 
00672   ACE_Guard<ACE_Thread_Mutex> guard(*mutex_);
00673 
00674   if (purpose == CREATE)
00675   {
00676     if (instance_ == 0)
00677     {
00678       instance_ = new ACE_TSS_Cleanup();
00679     }
00680     ptr_ = instance_;
00681     ++reference_count_;
00682   }
00683   else if(purpose == DESTROY)
00684   {
00685     if (instance_ != 0)
00686     {
00687       ptr_ = instance_;
00688       instance_ = 0;
00689       ACE_SET_BITS(flags_, FLAG_DELETING);
00690       while (reference_count_ > 0)
00691       {
00692         condition_->wait();
00693       }
00694     }
00695   }
00696   else // must be normal use
00697   {
00698     ACE_ASSERT(purpose == USE);
00699     if (instance_ != 0)
00700       {
00701         ptr_ = instance_;
00702         ++reference_count_;
00703       }
00704   }
00705 }

TSS_Cleanup_Instance::~TSS_Cleanup_Instance  ) 
 

Definition at line 707 of file OS_NS_Thread.cpp.

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

00708 {
00709   // Variable to hold the mutex_ to delete outside the scope of the
00710   // guard.
00711   ACE_Thread_Mutex *del_mutex = 0;
00712 
00713   // scope the guard
00714   {
00715     ACE_Guard<ACE_Thread_Mutex> guard (*mutex_);
00716     if (ptr_ != 0)
00717       {
00718         if (ACE_BIT_ENABLED (flags_, FLAG_DELETING))
00719           {
00720             ACE_ASSERT(instance_ == 0);
00721             ACE_ASSERT(reference_count_ == 0);
00722             delete ptr_;
00723             del_mutex = mutex_ ;
00724             mutex_ = 0;
00725           }
00726         else
00727           {
00728             ACE_ASSERT (reference_count_ > 0);
00729             --reference_count_;
00730             if (reference_count_ == 0 && instance_ == 0)
00731               condition_->signal ();
00732           }
00733       }
00734   }// end of guard scope
00735 
00736   if (del_mutex != 0)
00737     {
00738       delete condition_;
00739       condition_ = 0;
00740       delete del_mutex;
00741     }
00742 }


Member Function Documentation

ACE_TSS_Cleanup * TSS_Cleanup_Instance::operator *  )  [private]
 

Definition at line 752 of file OS_NS_Thread.cpp.

References ACE_ASSERT, ACE_BIT_ENABLED, and FLAG_VALID_CHECKED.

00753 {
00754   ACE_ASSERT(ACE_BIT_ENABLED(flags_, FLAG_VALID_CHECKED));
00755   return instance_;
00756 }

ACE_TSS_Cleanup * TSS_Cleanup_Instance::operator->  ) 
 

Definition at line 759 of file OS_NS_Thread.cpp.

References ACE_ASSERT, ACE_BIT_ENABLED, and FLAG_VALID_CHECKED.

00760 {
00761   ACE_ASSERT(ACE_BIT_ENABLED(flags_, FLAG_VALID_CHECKED));
00762   return instance_;
00763 }

bool TSS_Cleanup_Instance::valid  ) 
 

Definition at line 745 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().

00746 {
00747   ACE_SET_BITS(flags_, FLAG_VALID_CHECKED);
00748   return (this->instance_ != 0);
00749 }


Member Data Documentation

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

Definition at line 769 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 650 of file OS_NS_Thread.cpp.

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

Definition at line 767 of file OS_NS_Thread.cpp.

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

Definition at line 768 of file OS_NS_Thread.cpp.

ACE_TSS_Cleanup* TSS_Cleanup_Instance::ptr_ [private]
 

Definition at line 649 of file OS_NS_Thread.cpp.

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

Definition at line 766 of file OS_NS_Thread.cpp.


The documentation for this class was generated from the following file:
Generated on Sun Jan 27 12:59:13 2008 for ACE by doxygen 1.3.6