ACE_Thread_Adapter::ACE_Thread_Adapter (ACE_THR_FUNC user_func,
void *arg,
ACE_THR_C_FUNC entry_point,
ACE_Thread_Manager *tm,
ACE_Thread_Descriptor *td
#if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
, ACE_SEH_EXCEPT_HANDLER selector,
ACE_SEH_EXCEPT_HANDLER handler
#endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
)
: ACE_Base_Thread_Adapter (
user_func
, arg
, entry_point
, td
#if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
, selector
, handler
#endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
)
, thr_mgr_ (tm)
{
ACE_OS_TRACE ("ACE_Thread_Adapter::ACE_Thread_Adapter");
}
...
// Call thread entry point.
#if defined (ACE_PSOS)
status = 0;
(*func) (arg);
#else /* ! ACE_PSOS */
status = (*func) (arg);
#endif /* ACE_PSOS */
很奇怪,在Thread_Adapter.cpp的实现中没有用到第3个参数entry_point,原理上来说,封装线程user_func及其参数arg就足够了,为何还需要ACE_THR_C_FUNC?不解啊
再看看参数ACE_THR_C_FUNC entry_point = (ACE_THR_C_FUNC) ACE_THREAD_ADAPTER_NAME的声明
...
#if defined (ACE_PSOS)
extern "C" void ACE_THREAD_ADAPTER_NAME (unsigned long args);
#else /* ! defined (ACE_PSOS) */
extern "C" ACE_Export ACE_THR_FUNC_RETURN ACE_THREAD_ADAPTER_NAME (void *args);
#endif /* ACE_PSOS */
是个c函数,其实现如下:
extern "C" ACE_THR_FUNC_RETURN
ACE_THREAD_ADAPTER_NAME (void *args)
{
ACE_OS_TRACE ("ACE_THREAD_ADAPTER_NAME");
#if defined (ACE_HAS_TSS_EMULATION)
// As early as we can in the execution of the new thread, allocate
// its local TS storage. Allocate it on the stack, to save dynamic
// allocation/dealloction.
void *ts_storage[ACE_TSS_Emulation::ACE_TSS_THREAD_KEYS_MAX];
ACE_TSS_Emulation::tss_open (ts_storage);
#endif /* ACE_HAS_TSS_EMULATION */
ACE_Base_Thread_Adapter * const thread_args =
static_cast<ACE_Base_Thread_Adapter *> (args);
#ifdef ACE_USES_GPROF
setitimer (ITIMER_PROF, thread_args->timerval (), 0);
#endif // ACE_USES_GPROF
// Invoke the user-supplied function with the args.
ACE_THR_FUNC_RETURN status = thread_args->invoke ();
return status;
}
很绕,不知道它想干嘛:L |