00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Thread_Control.h 00006 * 00007 * Thread_Control.h,v 4.9 2005/10/28 23:55:10 ossama Exp 00008 * 00009 * @author Carlos O'Ryan <coryan@uci.edu> 00010 */ 00011 //============================================================================= 00012 00013 00014 #ifndef ACE_THREAD_CONTROL_H 00015 #define ACE_THREAD_CONTROL_H 00016 #include /**/ "ace/pre.h" 00017 00018 #include "ace/ACE_export.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00025 00026 class ACE_Thread_Manager; 00027 00028 /** 00029 * @class ACE_Thread_Control 00030 * 00031 * @brief Used to keep track of a thread's activities within its entry 00032 * point function. 00033 * 00034 * A ACE_Thread_Manager uses this class to ensure that threads 00035 * it spawns automatically register and unregister themselves 00036 * with it. 00037 * This class can be stored in thread-specific storage using the 00038 * ACE_TSS wrapper. When a thread exits the 00039 * <ACE_TSS::cleanup> function deletes this object, thereby 00040 * ensuring that it gets removed from its associated 00041 * ACE_Thread_Manager. 00042 */ 00043 class ACE_Export ACE_Thread_Control 00044 { 00045 public: 00046 /// Initialize the thread control object. If <insert> != 0, then 00047 /// register the thread with the Thread_Manager. 00048 ACE_Thread_Control (ACE_Thread_Manager *tm = 0, 00049 int insert = 0); 00050 00051 /// Remove the thread from its associated <Thread_Manager> and exit 00052 /// the thread if <do_thr_exit> is enabled. 00053 ~ACE_Thread_Control (void); 00054 00055 /// Remove this thread from its associated ACE_Thread_Manager and exit 00056 /// the thread if @a do_thr_exit is enabled. 00057 ACE_THR_FUNC_RETURN exit (ACE_THR_FUNC_RETURN status, 00058 int do_thr_exit); 00059 00060 /// Store the <Thread_Manager> and use it to register ourselves for 00061 /// correct shutdown. 00062 int insert (ACE_Thread_Manager *tm, int insert = 0); 00063 00064 /// Returns the current <Thread_Manager>. 00065 ACE_Thread_Manager *thr_mgr (void); 00066 00067 /// Atomically set a new <Thread_Manager> and return the old 00068 /// <Thread_Manager>. 00069 ACE_Thread_Manager *thr_mgr (ACE_Thread_Manager *); 00070 00071 /// Set the exit status (and return existing status). 00072 ACE_THR_FUNC_RETURN status (ACE_THR_FUNC_RETURN status); 00073 00074 /// Get the current exit status. 00075 ACE_THR_FUNC_RETURN status (void); 00076 00077 /// Dump the state of an object. 00078 void dump (void) const; 00079 00080 /// Declare the dynamic allocation hooks. 00081 ACE_ALLOC_HOOK_DECLARE; 00082 00083 private: 00084 /// Pointer to the thread manager for this block of code. 00085 ACE_Thread_Manager *tm_; 00086 00087 /// Keeps track of the exit status for the thread. 00088 ACE_THR_FUNC_RETURN status_; 00089 }; 00090 00091 ACE_END_VERSIONED_NAMESPACE_DECL 00092 00093 # if defined (ACE_HAS_INLINED_OSCALLS) 00094 # if defined (ACE_INLINE) 00095 # undef ACE_INLINE 00096 # endif /* ACE_INLINE */ 00097 # define ACE_INLINE inline 00098 # include "ace/Thread_Control.inl" 00099 # endif /* ACE_HAS_INLINED_OSCALLS */ 00100 00101 #include /**/ "ace/post.h" 00102 #endif /* ACE_THREAD_CONTROL_H */