Thread_Exit.cpp

Go to the documentation of this file.
00001 // Thread_Exit.cpp,v 4.14 2006/04/19 19:13:09 jwillemsen Exp
00002 
00003 #include "ace/Thread_Exit.h"
00004 #include "ace/Managed_Object.h"
00005 #include "ace/Thread_Manager.h"
00006 #include "ace/Guard_T.h"
00007 
00008 ACE_RCSID(ace, Thread_Exit, "Thread_Exit.cpp,v 4.14 2006/04/19 19:13:09 jwillemsen Exp")
00009 
00010 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00011 
00012 u_int ACE_Thread_Exit::is_constructed_ = 0;
00013 
00014 void
00015 ACE_Thread_Exit::cleanup (void *instance)
00016 {
00017   ACE_OS_TRACE ("ACE_Thread_Exit::cleanup");
00018 
00019   delete (ACE_TSS_TYPE (ACE_Thread_Exit) *) instance;
00020 
00021   // Set the thr_exit_ static to null to keep things from crashing if
00022   // ACE::fini() is enabled here.
00023   ACE_Thread_Manager::thr_exit_ = 0;
00024 
00025   ACE_Thread_Exit::is_constructed_ = 0;
00026   // All TSS objects have been destroyed.  Reset this flag so
00027   // ACE_Thread_Exit singleton can be created again.
00028 }
00029 
00030 // NOTE: this preprocessor directive should match the one in
00031 // ACE_Task_Base::svc_run () below.  This prevents the two statics
00032 // from being defined.
00033 
00034 ACE_Thread_Exit *
00035 ACE_Thread_Exit::instance (void)
00036 {
00037 #if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION)
00038   ACE_OS_TRACE ("ACE_Thread_Exit::instance");
00039 
00040   // Determines if we were dynamically allocated.
00041   static ACE_TSS_TYPE (ACE_Thread_Exit) *instance_;
00042 
00043   // Implement the Double Check pattern.
00044 
00045   if (ACE_Thread_Exit::is_constructed_ == 0)
00046     {
00047       ACE_MT (ACE_Thread_Mutex *lock =
00048               ACE_Managed_Object<ACE_Thread_Mutex>::get_preallocated_object
00049                 (ACE_Object_Manager::ACE_THREAD_EXIT_LOCK);
00050               ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, *lock, 0));
00051 
00052       if (ACE_Thread_Exit::is_constructed_ == 0)
00053         {
00054           ACE_NEW_RETURN (instance_,
00055                           ACE_TSS_TYPE (ACE_Thread_Exit),
00056                           0);
00057 
00058           ACE_Thread_Exit::is_constructed_ = 1;
00059 
00060           ACE_Thread_Manager::set_thr_exit (instance_);
00061         }
00062     }
00063 
00064   return ACE_TSS_GET (instance_, ACE_Thread_Exit);
00065 #else
00066   return 0;
00067 #endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */
00068 }
00069 
00070 // Grab hold of the Task * so that we can close() it in the
00071 // destructor.
00072 
00073 ACE_Thread_Exit::ACE_Thread_Exit (void)
00074 {
00075   ACE_OS_TRACE ("ACE_Thread_Exit::ACE_Thread_Exit");
00076 }
00077 
00078 // Set the this pointer...
00079 
00080 void
00081 ACE_Thread_Exit::thr_mgr (ACE_Thread_Manager *tm)
00082 {
00083   ACE_OS_TRACE ("ACE_Thread_Exit::thr_mgr");
00084 
00085   if (tm != 0)
00086     this->thread_control_.insert (tm, 0);
00087 }
00088 
00089 // When this object is destroyed the Task is automatically closed
00090 // down!
00091 
00092 ACE_Thread_Exit::~ACE_Thread_Exit (void)
00093 {
00094   ACE_OS_TRACE ("ACE_Thread_Exit::~ACE_Thread_Exit");
00095 }
00096 
00097 ACE_Thread_Exit_Maybe::ACE_Thread_Exit_Maybe (int flag)
00098   : instance_ (0)
00099 {
00100   if (flag)
00101     {
00102       ACE_NEW (instance_, ACE_Thread_Exit);
00103     }
00104 }
00105 
00106 ACE_Thread_Exit_Maybe::~ACE_Thread_Exit_Maybe (void)
00107 {
00108   delete this->instance_;
00109 }
00110 
00111 ACE_Thread_Exit *
00112 ACE_Thread_Exit_Maybe::operator -> (void) const
00113 {
00114   return this->instance_;
00115 }
00116 
00117 ACE_Thread_Exit *
00118 ACE_Thread_Exit_Maybe::instance (void) const
00119 {
00120   return this->instance_;
00121 }
00122 
00123 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:42:06 2006 for ACE by doxygen 1.3.6