00001 00002 //============================================================================= 00003 /** 00004 * @file Thread_Exit.h 00005 * 00006 * $Id: Thread_Exit.h,v 1.1.1.2 2003/02/21 18:36:32 chad Exp $ 00007 * 00008 * @author Carlos O'Ryan <coryan@uci.edu> 00009 */ 00010 //============================================================================= 00011 00012 00013 #ifndef ACE_THREAD_EXIT_H 00014 #define ACE_THREAD_EXIT_H 00015 #include "ace/pre.h" 00016 00017 #include "ace/config-all.h" 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 # pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 #include "ace/OS.h" 00024 #include "ace/Thread_Control.h" 00025 00026 /** 00027 * @class ACE_Thread_Exit 00028 * 00029 * @brief Keep exit information for a Thread in thread specific storage. 00030 * so that the thread-specific exit hooks will get called no 00031 * matter how the thread exits (e.g., via <ACE_Thread::exit>, C++ 00032 * or Win32 exception, "falling off the end" of the thread entry 00033 * point function, etc.). 00034 * 00035 * This clever little helper class is stored in thread-specific 00036 * storage using the <ACE_TSS> wrapper. When a thread exits the 00037 * <ACE_TSS::cleanup> function deletes this object, thereby 00038 * closing it down gracefully. 00039 */ 00040 class ACE_Export ACE_Thread_Exit 00041 { 00042 public: 00043 /// Capture the Thread that will be cleaned up automatically. 00044 ACE_Thread_Exit (void); 00045 00046 /// Set the <ACE_Thread_Manager>. 00047 void thr_mgr (ACE_Thread_Manager *tm); 00048 00049 /// Destructor calls the thread-specific exit hooks when a thread 00050 /// exits. 00051 ~ACE_Thread_Exit (void); 00052 00053 /// Singleton access point. 00054 static ACE_Thread_Exit *instance (void); 00055 00056 /// Cleanup method, used by the <ACE_Object_Manager> to destroy the 00057 /// singleton. 00058 static void cleanup (void *instance); 00059 00060 private: 00061 /// Automatically add/remove the thread from the 00062 /// <ACE_Thread_Manager>. 00063 ACE_Thread_Control thread_control_; 00064 00065 /** 00066 * Used to detect whether we should create a new instance (or not) 00067 * within the instance method -- we don't trust the instance_ ptr 00068 * because the destructor may have run (if ACE::fini() was called). 00069 * See bug #526. 00070 * We don't follow the singleton pattern due to dependency issues. 00071 */ 00072 static u_int is_constructed_; 00073 }; 00074 00075 /** 00076 * @class ACE_Thread_Exit_Maybe 00077 * 00078 * @brief A version of ACE_Thread_Exit that is created dynamically 00079 * under the hood if the flag is set to TRUE. 00080 * 00081 * Allows the appearance of a "smart pointer", but is not 00082 * always created. 00083 */ 00084 class ACE_Export ACE_Thread_Exit_Maybe 00085 { 00086 public: 00087 /// Don't create an ACE_Thread_Exit instance by default. 00088 ACE_Thread_Exit_Maybe (int flag = 0); 00089 00090 /// Destroys the underlying ACE_Thread_Exit instance if it exists. 00091 ~ACE_Thread_Exit_Maybe (void); 00092 00093 /// Delegates to underlying instance. 00094 ACE_Thread_Exit * operator -> (void) const; 00095 00096 /// Returns the underlying instance. 00097 ACE_Thread_Exit * instance (void) const; 00098 00099 private: 00100 00101 /// Holds the underlying instance. 00102 ACE_Thread_Exit *instance_; 00103 00104 }; 00105 00106 #include "ace/post.h" 00107 #endif /* ACE_THREAD_EXIT_H */
1.2.14 written by Dimitri van Heesch,
© 1997-2002