00001
00002
00003 #include "ace/OS_Thread_Adapter.h"
00004
00005 ACE_RCSID (ace,
00006 OS_Thread_Adapter,
00007 "OS_Thread_Adapter.cpp,v 4.8 2006/05/16 13:14:25 jwillemsen Exp")
00008
00009 #include "ace/Thread_Hook.h"
00010 #include "ace/Object_Manager_Base.h"
00011 #include "ace/Global_Macros.h"
00012 #include "ace/OS_NS_Thread.h"
00013
00014 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
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
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
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
00043
00044 this->inherit_log_msg ();
00045
00046
00047 ACE_THR_FUNC_INTERNAL func =
00048 reinterpret_cast<ACE_THR_FUNC_INTERNAL> (this->user_func_);
00049 void *arg = this->arg_;
00050
00051
00052
00053 delete this;
00054
00055 #if defined (ACE_NEEDS_LWP_PRIO_SET)
00056
00057
00058
00059 ACE_hthread_t thr_handle;
00060 ACE_OS::thr_self (thr_handle);
00061 int prio;
00062
00063
00064 ACE_OS::thr_getprio (thr_handle, prio);
00065
00066
00067
00068 ACE_OS::thr_setprio (prio);
00069
00070 #endif
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
00083
00084
00085 status = hook->start (reinterpret_cast<ACE_THR_FUNC> (func),
00086 arg);
00087 else
00088 {
00089
00090 status = (*func) (arg);
00091 }
00092 }
00093
00094 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00095 ACE_SEH_EXCEPT (ACE_OS_Object_Manager::seh_except_selector ()(
00096 (void *) GetExceptionInformation ()))
00097 {
00098 ACE_OS_Object_Manager::seh_except_handler ()(0);
00099 }
00100 #endif
00101 }
00102
00103 ACE_SEH_FINALLY
00104 {
00105
00106
00107 #if 0
00108
00109 if (func == reinterpret_cast<ACE_THR_FUNC_INTERNAL> (ACE_Task_Base::svc_run))
00110 {
00111 ACE_Task_Base *task_ptr = (ACE_Task_Base *) arg;
00112 ACE_Thread_Manager *thr_mgr_ptr = task_ptr->thr_mgr ();
00113
00114
00115 task_ptr->cleanup (task_ptr, 0);
00116
00117
00118
00119 thr_mgr_ptr->at_exit (task_ptr, 0, 0);
00120 }
00121 #endif
00122
00123 #if defined (ACE_WIN32) || defined (ACE_HAS_TSS_EMULATION)
00124
00125 ACE_OS::cleanup_tss (0 );
00126
00127 # if defined (ACE_WIN32)
00128
00129
00130
00131
00132 # if defined (ACE_HAS_MFC) && (ACE_HAS_MFC != 0)
00133
00134
00135
00136
00137 CWinThread *pThread = ::AfxGetThread ();
00138
00139 if (!pThread || pThread->m_nThreadID != ACE_OS::thr_self ())
00140 ACE_ENDTHREADEX (status);
00141 else
00142 ::AfxEndThread (status);
00143 # else
00144 ACE_ENDTHREADEX (status);
00145 # endif
00146 # endif
00147 #endif
00148 }
00149
00150 return status;
00151 }
00152
00153 ACE_END_VERSIONED_NAMESPACE_DECL