1 #include "ace/Base_Thread_Adapter.h"
3 #if !defined (ACE_HAS_INLINED_OSCALLS)
4 # include "ace/Base_Thread_Adapter.inl"
5 #endif /* ACE_HAS_INLINED_OSCALLS */
7 #if defined (ACE_HAS_TSS_EMULATION)
8 # include "ace/OS_NS_Thread.h"
9 #endif /* ACE_HAS_TSS_EMULATION */
11 #include "ace/Service_Config.h"
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 ACE_INIT_LOG_MSG_HOOK
ACE_Base_Thread_Adapter::init_log_msg_hook_
= 0;
16 ACE_INHERIT_LOG_MSG_HOOK
ACE_Base_Thread_Adapter::inherit_log_msg_hook_
= 0;
17 ACE_CLOSE_LOG_MSG_HOOK
ACE_Base_Thread_Adapter::close_log_msg_hook_
= 0;
18 ACE_SYNC_LOG_MSG_HOOK
ACE_Base_Thread_Adapter::sync_log_msg_hook_
= 0;
19 ACE_THR_DESC_LOG_MSG_HOOK
ACE_Base_Thread_Adapter::thr_desc_log_msg_hook_
= 0;
21 ACE_Base_Thread_Adapter::ACE_Base_Thread_Adapter (
22 ACE_THR_FUNC user_func
,
24 ACE_THR_C_FUNC entry_point
,
25 ACE_OS_Thread_Descriptor
*td
26 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
27 , ACE_SEH_EXCEPT_HANDLER selector
28 , ACE_SEH_EXCEPT_HANDLER handler
29 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
32 : user_func_ (user_func
)
34 , entry_point_ (entry_point
)
36 , ctx_ (ACE_Service_Config::current())
37 , flags_ (cancel_flags
)
39 ACE_OS_TRACE ("ACE_Base_Thread_Adapter::ACE_Base_Thread_Adapter");
41 if (ACE_Base_Thread_Adapter::init_log_msg_hook_
!= 0)
42 (*ACE_Base_Thread_Adapter::init_log_msg_hook_
) (
43 this->log_msg_attributes_
44 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
47 # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
50 getitimer (ITIMER_PROF
, &itimer_
);
51 #endif // ACE_USES_GPROF
54 ACE_Base_Thread_Adapter::~ACE_Base_Thread_Adapter (void)
59 ACE_Base_Thread_Adapter::inherit_log_msg (void)
61 if (ACE_Base_Thread_Adapter::inherit_log_msg_hook_
!= 0)
62 (*ACE_Base_Thread_Adapter::inherit_log_msg_hook_
)(
64 this->log_msg_attributes_
);
66 // Initialize the proper configuration context for the new thread
67 // Placed here since inherit_log_msg() gets called from any of our
68 // descendants (before self-destructing)
69 ACE_Service_Config::current (this->ctx_
);
73 ACE_Base_Thread_Adapter::close_log_msg (void)
75 if (ACE_Base_Thread_Adapter::close_log_msg_hook_
!= 0)
76 (*ACE_Base_Thread_Adapter::close_log_msg_hook_
) ();
80 ACE_Base_Thread_Adapter::sync_log_msg (const ACE_TCHAR
*prg
)
82 if (ACE_Base_Thread_Adapter::sync_log_msg_hook_
!= 0)
83 (*ACE_Base_Thread_Adapter::sync_log_msg_hook_
) (prg
);
86 ACE_OS_Thread_Descriptor::~ACE_OS_Thread_Descriptor (void)
90 ACE_OS_Thread_Descriptor
*
91 ACE_Base_Thread_Adapter::thr_desc_log_msg (void)
93 if (ACE_Base_Thread_Adapter::thr_desc_log_msg_hook_
!= 0)
94 return (*ACE_Base_Thread_Adapter::thr_desc_log_msg_hook_
) ();
98 ACE_END_VERSIONED_NAMESPACE_DECL
100 // Run the thread entry point for the <ACE_Thread_Adapter>. This must
101 // be an extern "C" to make certain compilers happy...
103 extern "C" ACE_THR_FUNC_RETURN
104 ACE_THREAD_ADAPTER_NAME (void *args
)
106 ACE_OS_TRACE ("ACE_THREAD_ADAPTER_NAME");
108 #if defined (ACE_HAS_TSS_EMULATION)
109 // As early as we can in the execution of the new thread, allocate
110 // its local TS storage. Allocate it on the stack, to save dynamic
111 // allocation/dealloction.
112 void *ts_storage
[ACE_TSS_Emulation::ACE_TSS_THREAD_KEYS_MAX
];
113 ACE_TSS_Emulation::tss_open (ts_storage
);
114 #endif /* ACE_HAS_TSS_EMULATION */
116 ACE_Base_Thread_Adapter
* const thread_args
=
117 static_cast<ACE_Base_Thread_Adapter
*> (args
);
119 #ifdef ACE_USES_GPROF
120 setitimer (ITIMER_PROF
, thread_args
->timerval (), 0);
121 #endif // ACE_USES_GPROF
123 // Invoke the user-supplied function with the args.
124 ACE_THR_FUNC_RETURN status
= thread_args
->invoke ();