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

OS_Thread_Adapter.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: OS_Thread_Adapter.cpp,v 1.1.1.2.2.1 2003/03/13 19:44:21 chad Exp $
00003 
00004 #include "ace/OS_Thread_Adapter.h"
00005 #include "ace/Thread_Hook.h"
00006 #include "ace/OS.h"
00007 
00008 ACE_RCSID (ace,
00009            OS_Thread_Adapter,
00010            "$Id: OS_Thread_Adapter.cpp,v 1.1.1.2.2.1 2003/03/13 19:44:21 chad Exp $")
00011 
00012 #if !defined (ACE_HAS_INLINED_OSCALLS)
00013 # include "ace/OS_Thread_Adapter.inl"
00014 #endif /* ACE_HAS_INLINED_OS_CALLS */
00015 
00016 ACE_OS_Thread_Adapter::ACE_OS_Thread_Adapter (
00017      ACE_THR_FUNC user_func
00018      , void *arg
00019      , ACE_THR_C_FUNC entry_point
00020 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00021      , ACE_SEH_EXCEPT_HANDLER selector
00022      , ACE_SEH_EXCEPT_HANDLER handler
00023 # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
00024      )
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 }
00034 
00035 ACE_OS_Thread_Adapter::~ACE_OS_Thread_Adapter (void)
00036 {
00037 }
00038 
00039 ACE_THR_FUNC_RETURN
00040 ACE_OS_Thread_Adapter::invoke (void)
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 }

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