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

ACE_OS_Thread_Adapter Class Reference

Converts a C++ function into a function that can be called from a thread creation routine (e.g., pthread_create() or _beginthreadex()) that expects an extern "C" entry point. This class also makes it possible to transparently provide hooks to register a thread with an ACE_Thread_Manager. More...

#include <OS_Thread_Adapter.h>

Inheritance diagram for ACE_OS_Thread_Adapter:

Inheritance graph
[legend]
Collaboration diagram for ACE_OS_Thread_Adapter:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_OS_Thread_Adapter (ACE_THR_FUNC user_func, void *arg, ACE_THR_C_FUNC entry_point=(ACE_THR_C_FUNC) ace_thread_adapter)
 Constructor. More...

virtual ACE_THR_FUNC_RETURN invoke (void)

Private Methods

 ~ACE_OS_Thread_Adapter (void)
 Ensure that this object must be allocated on the heap. More...


Friends

class ACE_Thread_Adapter_Has_Private_Destructor
 Friend declaration to avoid compiler warning: only defines a private destructor and has no friends. More...


Detailed Description

Converts a C++ function into a function that can be called from a thread creation routine (e.g., pthread_create() or _beginthreadex()) that expects an extern "C" entry point. This class also makes it possible to transparently provide hooks to register a thread with an ACE_Thread_Manager.

This class is used in ACE_OS::thr_create(). In general, the thread that creates an object of this class is different from the thread that calls invoke() on this object. Therefore, the invoke() method is responsible for deleting itself.

Definition at line 39 of file OS_Thread_Adapter.h.


Constructor & Destructor Documentation

ACE_OS_Thread_Adapter::ACE_OS_Thread_Adapter ACE_THR_FUNC    user_func,
void *    arg,
ACE_THR_C_FUNC    entry_point = (ACE_THR_C_FUNC) ace_thread_adapter
 

Constructor.

Definition at line 16 of file OS_Thread_Adapter.cpp.

00025   : ACE_Base_Thread_Adapter (user_func, arg, entry_point
00026 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00027                              , 0
00028                              , selector
00029                              , handler
00030 # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
00031                              )
00032 {
00033 }

ACE_OS_Thread_Adapter::~ACE_OS_Thread_Adapter void    [private]
 

Ensure that this object must be allocated on the heap.

Definition at line 35 of file OS_Thread_Adapter.cpp.

00036 {
00037 }


Member Function Documentation

ACE_THR_FUNC_RETURN ACE_OS_Thread_Adapter::invoke void    [virtual]
 

Execute the user_func_ with the arg. This function deletes this, thereby rendering the object useless after the call returns.

Implements ACE_Base_Thread_Adapter.

Definition at line 40 of file OS_Thread_Adapter.cpp.

References ACE_hthread_t, ACE_SEH_EXCEPT, ACE_SEH_FINALLY, ACE_SEH_TRY, ACE_Base_Thread_Adapter::arg_, ACE_Thread_Manager::at_exit, ACE_Task_Base::cleanup, ACE_OS::cleanup_tss, ACE_Base_Thread_Adapter::inherit_log_msg, ACE_Thread_Hook::start, ACE_Task_Base::svc_run, ACE_OS::thr_getprio, ACE_Task_Base::thr_mgr, ACE_OS::thr_self, ACE_OS::thr_setprio, and ACE_OS_Object_Manager::thread_hook.

00041 {
00042   // Inherit the logging features if the parent thread has an
00043   // ACE_Log_Msg instance in thread-specific storage.
00044   this->inherit_log_msg ();
00045 
00046   // Extract the arguments.
00047   ACE_THR_FUNC_INTERNAL func =
00048     ACE_reinterpret_cast (ACE_THR_FUNC_INTERNAL, this->user_func_);
00049   void *arg = this->arg_;
00050 
00051   // Delete ourselves since we don't need <this> anymore.  Make sure
00052   // not to access <this> anywhere below this point.
00053   delete this;
00054 
00055 #if defined (ACE_NEEDS_LWP_PRIO_SET)
00056   // On SunOS, the LWP priority needs to be set in order to get
00057   // preemption when running in the RT class.  This is the ACE way to
00058   // do that . . .
00059   ACE_hthread_t thr_handle;
00060   ACE_OS::thr_self (thr_handle);
00061   int prio;
00062 
00063   // thr_getprio () on the current thread should never fail.
00064   ACE_OS::thr_getprio (thr_handle, prio);
00065 
00066   // ACE_OS::thr_setprio () has the special logic to set the LWP priority,
00067   // if running in the RT class.
00068   ACE_OS::thr_setprio (prio);
00069 
00070 #endif /* ACE_NEEDS_LWP_PRIO_SET */
00071 
00072   ACE_THR_FUNC_RETURN status = 0;
00073 
00074   ACE_SEH_TRY
00075     {
00076       ACE_SEH_TRY
00077         {
00078           ACE_Thread_Hook *hook =
00079             ACE_OS_Object_Manager::thread_hook ();
00080 
00081           if (hook)
00082             // Invoke the start hook to give the user a chance to
00083             // perform some initialization processing before the
00084             // <func> is invoked.
00085             status = hook->start (ACE_reinterpret_cast (ACE_THR_FUNC, func),
00086                                   arg);
00087           else
00088             {
00089               // Call thread entry point.
00090 #if defined (ACE_PSOS)
00091               (*func) (arg);
00092               status = 0;
00093 #else /* ! ACE_PSOS */
00094               status = (*func) (arg);
00095 #endif /* ACE_PSOS */
00096             }
00097         }
00098 
00099 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00100       ACE_SEH_EXCEPT (ACE_OS_Object_Manager::seh_except_selector ()(
00101                           (void *) GetExceptionInformation ()))
00102         {
00103           ACE_OS_Object_Manager::seh_except_handler ()(0);
00104         }
00105 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
00106     }
00107 
00108   ACE_SEH_FINALLY
00109     {
00110       // If we changed this to 1, change the respective if in
00111       // Task::svc_run to 0.
00112 #if 0
00113       // Call the <Task->close> hook.
00114       if (func == ACE_reinterpret_cast (ACE_THR_FUNC_INTERNAL,
00115                                         ACE_Task_Base::svc_run))
00116         {
00117           ACE_Task_Base *task_ptr = (ACE_Task_Base *) arg;
00118           ACE_Thread_Manager *thr_mgr_ptr = task_ptr->thr_mgr ();
00119 
00120           // This calls the Task->close () hook.
00121           task_ptr->cleanup (task_ptr, 0);
00122 
00123           // This prevents a second invocation of the cleanup code
00124           // (called later by <ACE_Thread_Manager::exit>.
00125           thr_mgr_ptr->at_exit (task_ptr, 0, 0);
00126         }
00127 #endif /* 0 */
00128 
00129 #if defined (ACE_WIN32) || defined (ACE_HAS_TSS_EMULATION)
00130       // Call TSS destructors.
00131       ACE_OS::cleanup_tss (0 /* not main thread */);
00132 
00133 # if defined (ACE_WIN32)
00134       // Exit the thread.  Allow CWinThread-destructor to be invoked
00135       // from AfxEndThread.  _endthreadex will be called from
00136       // AfxEndThread so don't exit the thread now if we are running
00137       // an MFC thread.
00138 #   if defined (ACE_HAS_MFC) && (ACE_HAS_MFC != 0)
00139       // Not spawned by ACE_Thread_Manager, use the old buggy
00140       // version.  You should seriously consider using
00141       // ACE_Thread_Manager to spawn threads.  The following code
00142       // is know to cause some problem.
00143       CWinThread *pThread = ::AfxGetThread ();
00144 
00145       if (!pThread || pThread->m_nThreadID != ACE_OS::thr_self ())
00146         ACE_ENDTHREADEX (status);
00147       else
00148         ::AfxEndThread (status);
00149 #   else
00150       ACE_ENDTHREADEX (status);
00151 #   endif /* ACE_HAS_MFC && ACE_HAS_MFS != 0*/
00152 # endif /* ACE_WIN32 */
00153 #endif /* ACE_WIN32 || ACE_HAS_TSS_EMULATION */
00154 
00155 #if defined (ACE_PSOS)
00156       // This sequence of calls is documented by ISI as the proper way to
00157       // clean up a pSOS task. They affect different components, so only
00158       // try the ones for components that are built with ACE.
00159 #  if defined (SC_PREPC) && (SC_PREPC == YES)
00160       ::fclose (0);   // Return pREPC+ resources
00161 #  endif /* SC_PREPC */
00162 #  if defined (SC_PHILE) && (SC_PHILE == YES)
00163       ::close_f (0);  // Return pHILE+ resources
00164 #  endif /* SC_PHILE */
00165 #  if defined (SC_PNA) && (SC_PNA == YES)
00166       ::close (0);    // Return pNA+ resources
00167 #  endif /* SC_PNA */
00168 #  if defined (SC_SC_PREPC) && (SC_PREPC == YES)
00169       ::free (-1);    // Return pREPC+ memory
00170 #  endif /* SC_PREPC */
00171       status = ::t_delete (0); // Suicide - only returns on error
00172 #endif /* ACE_PSOS */
00173     }
00174 
00175   return status;
00176 }


Friends And Related Function Documentation

friend class ACE_Thread_Adapter_Has_Private_Destructor [friend]
 

Friend declaration to avoid compiler warning: only defines a private destructor and has no friends.

Reimplemented from ACE_Base_Thread_Adapter.

Definition at line 66 of file OS_Thread_Adapter.h.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:51:53 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002