Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Thread_Exit.cpp

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

Generated on Mon Jun 16 11:21:45 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002