Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Base_Thread_Adapter.h
blob8a65e5726554e1a97de40e42e2486b3a4323f61d
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Base_Thread_Adapter.h
7 * @author Nanbor Wang <nanbor@cs.wustl.edu>
8 */
9 //=============================================================================
11 #ifndef ACE_BASE_THREAD_ADAPTER_H
12 #define ACE_BASE_THREAD_ADAPTER_H
13 #include /**/ "ace/pre.h"
15 #include "ace/OS_Log_Msg_Attributes.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 # pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include /**/ "ace/ACE_export.h"
22 #include "ace/OS_Log_Msg_Attributes.h"
24 #ifdef ACE_USES_GPROF
25 #include "os_include/sys/os_time.h"
26 #endif // ACE_USES_GPROF
28 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) && ACE_HAS_VERSIONED_NAMESPACE == 1)
29 # define ACE_THREAD_ADAPTER_NAME ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _ace_thread_adapter)
30 #else
31 # define ACE_THREAD_ADAPTER_NAME ace_thread_adapter
32 #endif /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
34 /// Run the thread entry point for the ACE_Thread_Adapter. This must
35 /// be an extern "C" to make certain compilers happy...
36 extern "C" ACE_Export ACE_THR_FUNC_RETURN ACE_THREAD_ADAPTER_NAME (void *args);
38 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
40 /**
41 * @class ACE_OS_Thread_Descriptor
43 * @brief Parent class of all ACE_Thread_Descriptor classes.
45 * Container for ACE_Thread_Descriptor members that are
46 * used in ACE_OS.
48 class ACE_Export ACE_OS_Thread_Descriptor
50 public:
51 /// Get the thread creation flags.
52 long flags () const;
54 virtual ~ACE_OS_Thread_Descriptor () = default;
56 protected:
57 /// For use by ACE_Thread_Descriptor.
58 ACE_OS_Thread_Descriptor (long flags = 0);
60 /**
61 * Keeps track of whether this thread was created "detached" or not.
62 * If a thread is *not* created detached then if someone calls
63 * ACE_Thread_Manager::wait(), we need to join with that thread (and
64 * close down the handle).
66 long flags_;
69 class ACE_Service_Gestalt;
71 /**
72 * @class ACE_Base_Thread_Adapter
74 * @brief Base class for all the Thread_Adapters.
76 * Converts a C++ function into a function that can be
77 * called from a thread creation routine
78 * (e.g., pthread_create() or _beginthreadex()) that expects an
79 * extern "C" entry point. This class also makes it possible to
80 * transparently provide hooks to register a thread with an
81 * ACE_Thread_Manager.
82 * This class is used in ACE_OS::thr_create(). In general, the
83 * thread that creates an object of this class is different from
84 * the thread that calls @c invoke() on this object. Therefore,
85 * the @c invoke() method is responsible for deleting itself.
87 class ACE_Export ACE_Base_Thread_Adapter
89 public:
90 virtual ~ACE_Base_Thread_Adapter () = default;
92 /// Virtual method invoked by the thread entry point.
93 virtual ACE_THR_FUNC_RETURN invoke () = 0;
95 /// Accessor for the C entry point function to the OS thread creation
96 /// routine.
97 ACE_THR_C_FUNC entry_point ();
99 #ifdef ACE_USES_GPROF
100 /// Accessor to the itimer_
101 /// followed http://sam.zoy.org/writings/programming/gprof.html
102 struct itimerval* timerval ();
103 #endif // ACE_USES_PROF
105 /// Invoke the close_log_msg_hook, if it is present
106 static void close_log_msg ();
108 /// Invoke the sync_log_msg_hook, if it is present
109 static void sync_log_msg (const ACE_TCHAR *prog_name);
111 /// Invoke the thr_desc_log_msg_hook, if it is present
112 static ACE_OS_Thread_Descriptor *thr_desc_log_msg ();
114 protected:
115 /// Constructor.
116 ACE_Base_Thread_Adapter (ACE_THR_FUNC user_func,
117 void *arg,
118 ACE_THR_C_FUNC entry_point = (ACE_THR_C_FUNC) ACE_THREAD_ADAPTER_NAME,
119 ACE_OS_Thread_Descriptor *td = 0
120 # if defined (ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS)
121 , ACE_SEH_EXCEPT_HANDLER selector = 0
122 , ACE_SEH_EXCEPT_HANDLER handler = 0
123 # endif /* ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS */
124 , long cancel_flags = 0
126 /// Inherit the logging features if the parent thread has an
127 /// ACE_Log_Msg.
128 void inherit_log_msg ();
130 private:
131 /// The hooks to inherit and cleanup the Log_Msg attributes
132 static ACE_INIT_LOG_MSG_HOOK init_log_msg_hook_;
133 static ACE_INHERIT_LOG_MSG_HOOK inherit_log_msg_hook_;
134 static ACE_CLOSE_LOG_MSG_HOOK close_log_msg_hook_;
135 static ACE_SYNC_LOG_MSG_HOOK sync_log_msg_hook_;
136 static ACE_THR_DESC_LOG_MSG_HOOK thr_desc_log_msg_hook_;
138 /// Set the Log_Msg hooks
139 static void set_log_msg_hooks (ACE_INIT_LOG_MSG_HOOK init_hook,
140 ACE_INHERIT_LOG_MSG_HOOK inherit_hook,
141 ACE_CLOSE_LOG_MSG_HOOK close_hook,
142 ACE_SYNC_LOG_MSG_HOOK sync_hook,
143 ACE_THR_DESC_LOG_MSG_HOOK thr_desc);
145 /// Allow the ACE_Log_Msg class to set its hooks.
146 friend class ACE_Log_Msg;
148 protected:
149 /// Thread startup function passed in by the user (C++ linkage).
150 ACE_THR_FUNC user_func_;
152 /// Argument to thread startup function.
153 void *arg_;
155 /// Entry point to the underlying OS thread creation call (C
156 /// linkage).
157 ACE_THR_C_FUNC entry_point_;
160 * Optional thread descriptor. Passing this pointer in will force
161 * the spawned thread to cache this location in Log_Msg and wait
162 * until Thread_Manager fills in all information in thread
163 * descriptor.
165 ACE_OS_Thread_Descriptor *thr_desc_;
167 /// The ACE_Log_Msg attributes.
168 ACE_OS_Log_Msg_Attributes log_msg_attributes_;
170 /// That is useful for gprof, define itimerval
171 #ifdef ACE_USES_GPROF
172 struct itimerval itimer_;
173 #endif // ACE_USES_GPROF
175 /// Keep a reference to the configuration context that spawns the
176 /// thread so the child can inherit it.
177 ACE_Service_Gestalt * const ctx_;
179 /// Pass through the thread-creation flags that can only be acted on by
180 /// the spawned thread. Currently this is only the cancellation-related
181 /// flags.
182 long flags_;
185 ACE_END_VERSIONED_NAMESPACE_DECL
187 # if defined (ACE_HAS_INLINED_OSCALLS)
188 # if defined (ACE_INLINE)
189 # undef ACE_INLINE
190 # endif /* ACE_INLINE */
191 # define ACE_INLINE inline
192 # include "ace/Base_Thread_Adapter.inl"
193 # endif /* ACE_HAS_INLINED_OSCALLS */
195 #include /**/ "ace/post.h"
196 #endif /* ACE_BASE_THREAD_ADAPTER_H */