00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Thread_Adapter.h 00006 * 00007 * $Id: Thread_Adapter.h 80826 2008-03-04 14:51:23Z wotte $ 00008 * 00009 * @author Carlos O'Ryan <coryan@uci.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_THREAD_ADAPTER_H 00014 #define ACE_THREAD_ADAPTER_H 00015 #include /**/ "ace/pre.h" 00016 00017 #include /**/ "ace/ACE_export.h" 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 # pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 #include "ace/Base_Thread_Adapter.h" 00024 00025 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00026 00027 // Forward decl. 00028 class ACE_Thread_Manager; 00029 class ACE_Thread_Descriptor; 00030 00031 /** 00032 * @class ACE_Thread_Adapter 00033 * 00034 * @brief Converts a C++ function into a function that 00035 * can be called from a thread creation routine 00036 * (e.g., pthread_create() or _beginthreadex()) that expects an 00037 * extern "C" entry point. This class also makes it possible to 00038 * transparently provide hooks to register a thread with an 00039 * ACE_Thread_Manager. 00040 * 00041 * This class is used in ACE_OS::thr_create(). In general, the 00042 * thread that creates an object of this class is different from 00043 * the thread that calls @c invoke() on this object. Therefore, 00044 * the @c invoke() method is responsible for deleting itself. 00045 */ 00046 class ACE_Export ACE_Thread_Adapter : public ACE_Base_Thread_Adapter 00047 { 00048 public: 00049 /// Constructor. 00050 ACE_Thread_Adapter (ACE_THR_FUNC user_func, 00051 void *arg, 00052 ACE_THR_C_FUNC entry_point = (ACE_THR_C_FUNC) ACE_THREAD_ADAPTER_NAME, 00053 ACE_Thread_Manager *thr_mgr = 0, 00054 ACE_Thread_Descriptor *td = 0 00055 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) 00056 , ACE_SEH_EXCEPT_HANDLER selector = 0, 00057 ACE_SEH_EXCEPT_HANDLER handler = 0 00058 # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */ 00059 ); 00060 00061 /** 00062 * Execute the <user_func_> with the <arg>. This function deletes 00063 * @c this, thereby rendering the object useless after the call 00064 * returns. 00065 */ 00066 virtual ACE_THR_FUNC_RETURN invoke (void); 00067 00068 /// Accessor for the optional ACE_Thread_Manager. 00069 ACE_Thread_Manager *thr_mgr (void); 00070 00071 protected: 00072 00073 /// Ensure that this object must be allocated on the heap. 00074 ~ACE_Thread_Adapter (void); 00075 00076 private: 00077 00078 /// Called by invoke, mainly here to separate the SEH stuff because 00079 /// SEH on Win32 doesn't compile with local vars with destructors. 00080 virtual ACE_THR_FUNC_RETURN invoke_i (void); 00081 00082 private: 00083 00084 /// Optional thread manager. 00085 ACE_Thread_Manager *thr_mgr_; 00086 00087 }; 00088 00089 ACE_END_VERSIONED_NAMESPACE_DECL 00090 00091 # if defined (ACE_HAS_INLINED_OSCALLS) 00092 # if defined (ACE_INLINE) 00093 # undef ACE_INLINE 00094 # endif /* ACE_INLINE */ 00095 # define ACE_INLINE inline 00096 # include "ace/Thread_Adapter.inl" 00097 # endif /* ACE_HAS_INLINED_OSCALLS */ 00098 00099 #include /**/ "ace/post.h" 00100 #endif /* ACE_THREAD_ADAPTER_H */