[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / OS_Thread_Adapter.cpp
blobf65d1acaff280fb0cbff2f51101c5e165c64dd8b
1 // $Id: OS_Thread_Adapter.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #include "ace/OS_Thread_Adapter.h"
5 ACE_RCSID (ace,
6 OS_Thread_Adapter,
7 "$Id: OS_Thread_Adapter.cpp 80826 2008-03-04 14:51:23Z wotte $")
9 #include "ace/Thread_Hook.h"
10 #include "ace/Object_Manager_Base.h"
11 #include "ace/Global_Macros.h"
12 #include "ace/OS_NS_Thread.h"
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_OS_Thread_Adapter::ACE_OS_Thread_Adapter (
17 ACE_THR_FUNC user_func
18 , void *arg
19 , ACE_THR_C_FUNC entry_point
20 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
21 , ACE_SEH_EXCEPT_HANDLER selector
22 , ACE_SEH_EXCEPT_HANDLER handler
23 # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
25 : ACE_Base_Thread_Adapter (user_func, arg, entry_point
26 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
27 , 0
28 , selector
29 , handler
30 # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
35 ACE_OS_Thread_Adapter::~ACE_OS_Thread_Adapter (void)
39 ACE_THR_FUNC_RETURN
40 ACE_OS_Thread_Adapter::invoke (void)
42 // Inherit the logging features if the parent thread has an
43 // ACE_Log_Msg instance in thread-specific storage.
44 this->inherit_log_msg ();
46 // Extract the arguments.
47 ACE_THR_FUNC_INTERNAL func =
48 reinterpret_cast<ACE_THR_FUNC_INTERNAL> (this->user_func_);
49 void *arg = this->arg_;
51 // Delete ourselves since we don't need <this> anymore. Make sure
52 // not to access <this> anywhere below this point.
53 delete this;
55 #if defined (ACE_NEEDS_LWP_PRIO_SET)
56 // On SunOS, the LWP priority needs to be set in order to get
57 // preemption when running in the RT class. This is the ACE way to
58 // do that . . .
59 ACE_hthread_t thr_handle;
60 ACE_OS::thr_self (thr_handle);
61 int prio;
63 // thr_getprio () on the current thread should never fail.
64 ACE_OS::thr_getprio (thr_handle, prio);
66 // ACE_OS::thr_setprio () has the special logic to set the LWP priority,
67 // if running in the RT class.
68 ACE_OS::thr_setprio (prio);
70 #endif /* ACE_NEEDS_LWP_PRIO_SET */
72 ACE_THR_FUNC_RETURN status = 0;
74 ACE_SEH_TRY
76 ACE_SEH_TRY
78 ACE_Thread_Hook *hook =
79 ACE_OS_Object_Manager::thread_hook ();
81 if (hook)
82 // Invoke the start hook to give the user a chance to
83 // perform some initialization processing before the
84 // <func> is invoked.
85 status = hook->start (reinterpret_cast<ACE_THR_FUNC> (func),
86 arg);
87 else
89 // Call thread entry point.
90 status = (*func) (arg);
94 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
95 ACE_SEH_EXCEPT (ACE_OS_Object_Manager::seh_except_selector ()(
96 (void *) GetExceptionInformation ()))
98 ACE_OS_Object_Manager::seh_except_handler ()(0);
100 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
103 ACE_SEH_FINALLY
105 // If we changed this to 1, change the respective if in
106 // Task::svc_run to 0.
107 #if 0
108 // Call the <Task->close> hook.
109 if (func == reinterpret_cast<ACE_THR_FUNC_INTERNAL> (ACE_Task_Base::svc_run))
111 ACE_Task_Base *task_ptr = (ACE_Task_Base *) arg;
112 ACE_Thread_Manager *thr_mgr_ptr = task_ptr->thr_mgr ();
114 // This calls the Task->close () hook.
115 task_ptr->cleanup (task_ptr, 0);
117 // This prevents a second invocation of the cleanup code
118 // (called later by <ACE_Thread_Manager::exit>.
119 thr_mgr_ptr->at_exit (task_ptr, 0, 0);
121 #endif /* 0 */
123 #if defined (ACE_WIN32) || defined (ACE_HAS_TSS_EMULATION)
124 // Call TSS destructors.
125 ACE_OS::cleanup_tss (0 /* not main thread */);
127 # if defined (ACE_WIN32)
128 // Exit the thread. Allow CWinThread-destructor to be invoked
129 // from AfxEndThread. _endthreadex will be called from
130 // AfxEndThread so don't exit the thread now if we are running
131 // an MFC thread.
132 # if defined (ACE_HAS_MFC) && (ACE_HAS_MFC != 0)
133 // Not spawned by ACE_Thread_Manager, use the old buggy
134 // version. You should seriously consider using
135 // ACE_Thread_Manager to spawn threads. The following code
136 // is know to cause some problem.
137 CWinThread *pThread = ::AfxGetThread ();
139 if (!pThread || pThread->m_nThreadID != ACE_OS::thr_self ())
140 ACE_ENDTHREADEX (status);
141 else
142 ::AfxEndThread (status);
143 # else
144 ACE_ENDTHREADEX (status);
145 # endif /* ACE_HAS_MFC && ACE_HAS_MFS != 0*/
146 # endif /* ACE_WIN32 */
147 #endif /* ACE_WIN32 || ACE_HAS_TSS_EMULATION */
150 return status;
153 ACE_END_VERSIONED_NAMESPACE_DECL