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

Base_Thread_Adapter.h

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

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