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

Thread_Adapter.h

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

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