Base_Thread_Adapter.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Base_Thread_Adapter.h
00006  *
00007  *  Base_Thread_Adapter.h,v 4.19 2006/05/05 07:37:43 jwillemsen Exp
00008  *
00009  *  @author Nanbor Wang <nanbor@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_BASE_THREAD_ADAPTER_H
00014 #define ACE_BASE_THREAD_ADAPTER_H
00015 #include /**/ "ace/pre.h"
00016 
00017 #include "ace/OS_Log_Msg_Attributes.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #include "ace/ACE_export.h"
00024 #include "ace/OS_Log_Msg_Attributes.h"
00025 
00026 #ifdef ACE_USES_GPROF
00027 #include "os_include/sys/os_time.h"
00028 #endif // ACE_USES_GPROF
00029 
00030 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) && ACE_HAS_VERSIONED_NAMESPACE == 1)
00031 # define ACE_THREAD_ADAPTER_NAME ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _ace_thread_adapter)
00032 #else
00033 # define ACE_THREAD_ADAPTER_NAME ace_thread_adapter
00034 #endif  /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
00035 
00036 // Run the thread entry point for the ACE_Thread_Adapter.  This must
00037 // be an extern "C" to make certain compilers happy...
00038 
00039 extern "C" ACE_Export ACE_THR_FUNC_RETURN ACE_THREAD_ADAPTER_NAME (void *args);
00040 
00041 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00042 
00043 /**
00044  * @class ACE_OS_Thread_Descriptor
00045  *
00046  * @brief Parent class of all ACE_Thread_Descriptor classes.
00047  * =
00048  * Container for ACE_Thread_Descriptor members that are
00049  * used in ACE_OS.
00050  */
00051 class ACE_Export ACE_OS_Thread_Descriptor
00052 {
00053 public:
00054   /// Get the thread creation flags.
00055   long flags (void) const;
00056 
00057 protected:
00058   /// For use by ACE_Thread_Descriptor.
00059   ACE_OS_Thread_Descriptor (long flags = 0);
00060 
00061   /**
00062    * Keeps track of whether this thread was created "detached" or not.
00063    * If a thread is *not* created detached then if someone calls
00064    * <ACE_Thread_Manager::wait>, we need to join with that thread (and
00065    * close down the handle).
00066    */
00067   long flags_;
00068 };
00069 
00070 /**
00071  * @class ACE_Base_Thread_Adapter
00072  *
00073  * @brief Base class for all the Thread_Adapters.
00074  *
00075  * Converts a C++ function into a function that can be
00076  * called from a thread creation routine
00077  * (e.g., pthread_create() or _beginthreadex()) that expects an
00078  * extern "C" entry point.  This class also makes it possible to
00079  * transparently provide hooks to register a thread with an
00080  * ACE_Thread_Manager.
00081  * This class is used in ACE_OS::thr_create().  In general, the
00082  * thread that creates an object of this class is different from
00083  * the thread that calls @c invoke() on this object.  Therefore,
00084  * the @c invoke() method is responsible for deleting itself.
00085  */
00086 class ACE_Export ACE_Base_Thread_Adapter
00087 {
00088 public:
00089 
00090   virtual ~ACE_Base_Thread_Adapter (void);
00091 
00092   /// Virtual method invoked by the thread entry point.
00093   virtual ACE_THR_FUNC_RETURN invoke (void) = 0;
00094 
00095   /// Accessor for the C entry point function to the OS thread creation
00096   /// routine.
00097   ACE_THR_C_FUNC entry_point (void);
00098 
00099 #ifdef ACE_USES_GPROF
00100   /// Accessor to the itimer_
00101   /// followed http://sam.zoy.org/writings/programming/gprof.html
00102   struct itimerval* timerval (void);
00103 #endif // ACE_USES_PROF
00104 
00105   /// Invoke the close_log_msg_hook, if it is present
00106   static void close_log_msg (void);
00107 
00108   /// Invoke the sync_log_msg_hook, if it is present
00109   static void sync_log_msg (const ACE_TCHAR *prog_name);
00110 
00111   /// Invoke the thr_desc_log_msg_hook, if it is present
00112   static ACE_OS_Thread_Descriptor *thr_desc_log_msg (void);
00113 
00114 protected:
00115   /// Constructor.
00116   ACE_Base_Thread_Adapter (ACE_THR_FUNC user_func,
00117                            void *arg,
00118                            ACE_THR_C_FUNC entry_point = (ACE_THR_C_FUNC) ACE_THREAD_ADAPTER_NAME,
00119                            ACE_OS_Thread_Descriptor *td = 0
00120 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00121                            , ACE_SEH_EXCEPT_HANDLER selector = 0
00122                            , ACE_SEH_EXCEPT_HANDLER handler = 0
00123 # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
00124                       );
00125   /// Inherit the logging features if the parent thread has an
00126   /// ACE_Log_Msg.
00127   void inherit_log_msg (void);
00128 
00129 private:
00130   /// The hooks to inherit and cleanup the Log_Msg attributes
00131   static ACE_INIT_LOG_MSG_HOOK init_log_msg_hook_;
00132   static ACE_INHERIT_LOG_MSG_HOOK inherit_log_msg_hook_;
00133   static ACE_CLOSE_LOG_MSG_HOOK close_log_msg_hook_;
00134   static ACE_SYNC_LOG_MSG_HOOK sync_log_msg_hook_;
00135   static ACE_THR_DESC_LOG_MSG_HOOK thr_desc_log_msg_hook_;
00136 
00137   /// Set the Log_Msg hooks
00138   static void set_log_msg_hooks (ACE_INIT_LOG_MSG_HOOK init_hook,
00139                                  ACE_INHERIT_LOG_MSG_HOOK inherit_hook,
00140                                  ACE_CLOSE_LOG_MSG_HOOK close_hook,
00141                                  ACE_SYNC_LOG_MSG_HOOK sync_hook,
00142                                  ACE_THR_DESC_LOG_MSG_HOOK thr_desc);
00143 
00144   /// Allow the ACE_Log_Msg class to set its hooks.
00145   friend class ACE_Log_Msg;
00146 
00147 protected:
00148   /// Thread startup function passed in by the user (C++ linkage).
00149   ACE_THR_FUNC user_func_;
00150 
00151   /// Argument to thread startup function.
00152   void *arg_;
00153 
00154   /// Entry point to the underlying OS thread creation call (C
00155   /// linkage).
00156   ACE_THR_C_FUNC entry_point_;
00157 
00158   /**
00159    * Optional thread descriptor.  Passing this pointer in will force
00160    * the spawned thread to cache this location in <Log_Msg> and wait
00161    * until <Thread_Manager> fills in all information in thread
00162    * descriptor.
00163    */
00164   ACE_OS_Thread_Descriptor *thr_desc_;
00165 
00166   /// The ACE_Log_Msg attributes.
00167   ACE_OS_Log_Msg_Attributes log_msg_attributes_;
00168   /// That is usefull for gprof, define itimerval
00169 #ifdef ACE_USES_GPROF
00170   struct itimerval itimer_;
00171 #endif // ACE_USES_GPROF
00172 
00173 };
00174 
00175 ACE_END_VERSIONED_NAMESPACE_DECL
00176 
00177 # if defined (ACE_HAS_INLINED_OSCALLS)
00178 #   if defined (ACE_INLINE)
00179 #     undef ACE_INLINE
00180 #   endif /* ACE_INLINE */
00181 #   define ACE_INLINE inline
00182 #   include "ace/Base_Thread_Adapter.inl"
00183 # endif /* ACE_HAS_INLINED_OSCALLS */
00184 
00185 #include /**/ "ace/post.h"
00186 #endif /* ACE_BASE_THREAD_ADAPTER_H */

Generated on Thu Nov 9 09:41:47 2006 for ACE by doxygen 1.3.6