Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / os_include / os_pthread.h
bloba789d117314e7435c24bc51deb9915f819d37d94
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file os_pthread.h
7 * threads
9 * @author Don Hinton <dhinton@dresystems.com>
10 * @author This code was originally in various places including ace/OS.h.
12 //=============================================================================
14 #ifndef ACE_OS_INCLUDE_OS_PTHREAD_H
15 #define ACE_OS_INCLUDE_OS_PTHREAD_H
17 #include /**/ "ace/pre.h"
19 #include /**/ "ace/config-all.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # pragma once
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include "ace/os_include/sys/os_types.h"
26 #include "ace/os_include/os_stdint.h"
28 # if defined (ACE_HAS_PTHREADS)
29 # define ACE_DONT_INCLUDE_ACE_SIGNAL_H
30 # include "ace/os_include/os_signal.h"
31 # undef ACE_DONT_INCLUDE_ACE_SIGNAL_H
32 # endif /* ACE_HAS_PTHREADS */
34 #if !defined (ACE_LACKS_PTHREAD_H)
35 # include /**/ <pthread.h>
36 #endif /* !ACE_LACKS_PTHREAD_H */
38 #if defined (ACE_HAS_PTHREAD_NP_H)
39 // FreeBSD declares _np (non-portable) pthread extensions in <pthread_np.h>
40 # include /**/ <pthread_np.h>
41 #endif
43 // @todo: need to reoganize to put includes at the top and the rest of the
44 // code at the bottom. Also, move the classes out of this file.
45 #if defined (ACE_HAS_PTHREADS)
46 # define ACE_SCHED_OTHER SCHED_OTHER
47 # define ACE_SCHED_FIFO SCHED_FIFO
48 # define ACE_SCHED_RR SCHED_RR
50 // Definitions for THREAD- and PROCESS-LEVEL priorities...some
51 // implementations define these while others don't. In order to
52 // further complicate matters, we don't redefine the default (*_DEF)
53 // values if they've already been defined, which allows individual
54 // programs to have their own ACE-wide "default".
56 // PROCESS-level values
57 # if defined (_POSIX_PRIORITY_SCHEDULING)
58 # define ACE_PROC_PRI_FIFO_MIN (sched_get_priority_min(SCHED_FIFO))
59 # define ACE_PROC_PRI_RR_MIN (sched_get_priority_min(SCHED_RR))
60 # define ACE_PROC_PRI_OTHER_MIN (sched_get_priority_min(SCHED_OTHER))
61 # else /* UNICOS is missing a sched_get_priority_min() implementation */
62 # define ACE_PROC_PRI_FIFO_MIN 0
63 # define ACE_PROC_PRI_RR_MIN 0
64 # define ACE_PROC_PRI_OTHER_MIN 0
65 # endif
67 # if defined (_POSIX_PRIORITY_SCHEDULING)
68 # define ACE_PROC_PRI_FIFO_MAX (sched_get_priority_max(SCHED_FIFO))
69 # define ACE_PROC_PRI_RR_MAX (sched_get_priority_max(SCHED_RR))
70 # define ACE_PROC_PRI_OTHER_MAX (sched_get_priority_max(SCHED_OTHER))
71 # else
72 # define ACE_PROC_PRI_FIFO_MAX 59
73 # define ACE_PROC_PRI_RR_MAX 59
74 # define ACE_PROC_PRI_OTHER_MAX 59
75 # endif
77 # if !defined(ACE_PROC_PRI_FIFO_DEF)
78 # define ACE_PROC_PRI_FIFO_DEF (ACE_PROC_PRI_FIFO_MIN + (ACE_PROC_PRI_FIFO_MAX - ACE_PROC_PRI_FIFO_MIN)/2)
79 # endif
80 # if !defined(ACE_PROC_PRI_RR_DEF)
81 # define ACE_PROC_PRI_RR_DEF (ACE_PROC_PRI_RR_MIN + (ACE_PROC_PRI_RR_MAX - ACE_PROC_PRI_RR_MIN)/2)
82 # endif
83 # if !defined(ACE_PROC_PRI_OTHER_DEF)
84 # define ACE_PROC_PRI_OTHER_DEF (ACE_PROC_PRI_OTHER_MIN + (ACE_PROC_PRI_OTHER_MAX - ACE_PROC_PRI_OTHER_MIN)/2)
85 # endif
87 // THREAD-level values
88 # if defined(PRI_FIFO_MIN) && defined(PRI_FIFO_MAX) && defined(PRI_RR_MIN) && defined(PRI_RR_MAX) && defined(PRI_OTHER_MIN) && defined(PRI_OTHER_MAX)
89 # if !defined (ACE_THR_PRI_FIFO_MIN)
90 # define ACE_THR_PRI_FIFO_MIN (long) PRI_FIFO_MIN
91 # endif /* !ACE_THR_PRI_FIFO_MIN */
92 # if !defined (ACE_THR_PRI_FIFO_MAX)
93 # define ACE_THR_PRI_FIFO_MAX (long) PRI_FIFO_MAX
94 # endif /* !ACE_THR_PRI_FIFO_MAX */
95 # if !defined (ACE_THR_PRI_RR_MIN)
96 # define ACE_THR_PRI_RR_MIN (long) PRI_RR_MIN
97 # endif /* !ACE_THR_PRI_RR_MIN */
98 # if !defined (ACE_THR_PRI_RR_MAX)
99 # define ACE_THR_PRI_RR_MAX (long) PRI_RR_MAX
100 # endif /* !ACE_THR_PRI_RR_MAX */
101 # if !defined (ACE_THR_PRI_OTHER_MIN)
102 # define ACE_THR_PRI_OTHER_MIN (long) PRI_OTHER_MIN
103 # endif /* !ACE_THR_PRI_OTHER_MIN */
104 # if !defined (ACE_THR_PRI_OTHER_MAX)
105 # define ACE_THR_PRI_OTHER_MAX (long) PRI_OTHER_MAX
106 # endif /* !ACE_THR_PRI_OTHER_MAX */
107 # else
108 # if !defined (ACE_THR_PRI_FIFO_MIN)
109 # define ACE_THR_PRI_FIFO_MIN (long) ACE_PROC_PRI_FIFO_MIN
110 # endif /* !ACE_THR_PRI_FIFO_MIN */
111 # if !defined (ACE_THR_PRI_FIFO_MAX)
112 # define ACE_THR_PRI_FIFO_MAX (long) ACE_PROC_PRI_FIFO_MAX
113 # endif /* !ACE_THR_PRI_FIFO_MAX */
114 # if !defined (ACE_THR_PRI_RR_MIN)
115 # define ACE_THR_PRI_RR_MIN (long) ACE_PROC_PRI_RR_MIN
116 # endif /* !ACE_THR_PRI_RR_MIN */
117 # if !defined (ACE_THR_PRI_RR_MAX)
118 # define ACE_THR_PRI_RR_MAX (long) ACE_PROC_PRI_RR_MAX
119 # endif /* !ACE_THR_PRI_RR_MAX */
120 # if !defined (ACE_THR_PRI_OTHER_MIN)
121 # define ACE_THR_PRI_OTHER_MIN (long) ACE_PROC_PRI_OTHER_MIN
122 # endif /* !ACE_THR_PRI_OTHER_MIN */
123 # if !defined (ACE_THR_PRI_OTHER_MAX)
124 # define ACE_THR_PRI_OTHER_MAX (long) ACE_PROC_PRI_OTHER_MAX
125 # endif /* !ACE_THR_PRI_OTHER_MAX */
126 # endif
127 # if !defined(ACE_THR_PRI_FIFO_DEF)
128 # define ACE_THR_PRI_FIFO_DEF ((ACE_THR_PRI_FIFO_MIN + ACE_THR_PRI_FIFO_MAX)/2)
129 # endif
130 # if !defined(ACE_THR_PRI_RR_DEF)
131 # define ACE_THR_PRI_RR_DEF ((ACE_THR_PRI_RR_MIN + ACE_THR_PRI_RR_MAX)/2)
132 # endif
133 # if !defined(ACE_THR_PRI_OTHER_DEF)
134 # define ACE_THR_PRI_OTHER_DEF ((ACE_THR_PRI_OTHER_MIN + ACE_THR_PRI_OTHER_MAX)/2)
135 # endif
136 // Typedefs to help compatibility with Windows NT and Pthreads.
137 typedef pthread_t ACE_hthread_t;
138 typedef pthread_t ACE_thread_t;
140 // native TSS key type
141 typedef pthread_key_t ACE_OS_thread_key_t;
142 // TSS key type to be used by application
143 # if defined (ACE_HAS_TSS_EMULATION)
144 typedef u_int ACE_thread_key_t;
145 # else /* ! ACE_HAS_TSS_EMULATION */
146 typedef ACE_OS_thread_key_t ACE_thread_key_t;
147 # endif /* ! ACE_HAS_TSS_EMULATION */
149 # if !defined (ACE_LACKS_COND_T)
150 typedef pthread_mutex_t ACE_mutex_t;
151 typedef pthread_cond_t ACE_cond_t;
152 typedef pthread_condattr_t ACE_condattr_t;
153 typedef pthread_mutexattr_t ACE_mutexattr_t;
154 # endif /* ! ACE_LACKS_COND_T */
155 typedef pthread_mutex_t ACE_thread_mutex_t;
157 # define THR_CANCEL_DISABLE 0x00000100
158 # define THR_CANCEL_ENABLE 0x00000200
159 # define THR_CANCEL_DEFERRED 0x00000400
160 # define THR_CANCEL_ASYNCHRONOUS 0x00000800
162 # if !defined (PTHREAD_CREATE_JOINABLE)
163 # if defined (PTHREAD_CREATE_UNDETACHED)
164 # define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED
165 # else
166 # define PTHREAD_CREATE_JOINABLE 0
167 # endif /* PTHREAD_CREATE_UNDETACHED */
168 # endif /* PTHREAD_CREATE_JOINABLE */
170 # if !defined (PTHREAD_CREATE_DETACHED)
171 # define PTHREAD_CREATE_DETACHED 1
172 # endif /* PTHREAD_CREATE_DETACHED */
174 # if !defined (PTHREAD_PROCESS_PRIVATE) && !defined (ACE_HAS_PTHREAD_PROCESS_ENUM)
175 # if defined (PTHREAD_MUTEXTYPE_FAST)
176 # define PTHREAD_PROCESS_PRIVATE PTHREAD_MUTEXTYPE_FAST
177 # else
178 # define PTHREAD_PROCESS_PRIVATE 0
179 # endif /* PTHREAD_MUTEXTYPE_FAST */
180 # endif /* PTHREAD_PROCESS_PRIVATE */
182 # if !defined (PTHREAD_PROCESS_SHARED) && !defined (ACE_HAS_PTHREAD_PROCESS_ENUM)
183 # if defined (PTHREAD_MUTEXTYPE_FAST)
184 # define PTHREAD_PROCESS_SHARED PTHREAD_MUTEXTYPE_FAST
185 # else
186 # define PTHREAD_PROCESS_SHARED 1
187 # endif /* PTHREAD_MUTEXTYPE_FAST */
188 # endif /* PTHREAD_PROCESS_SHARED */
190 # if !defined (USYNC_THREAD)
191 # define USYNC_THREAD PTHREAD_PROCESS_PRIVATE
192 # endif /* ! USYNC_THREAD */
193 # if !defined (USYNC_PROCESS)
194 # define USYNC_PROCESS PTHREAD_PROCESS_SHARED
195 # endif /* ! USYNC_PROCESS */
197 /* MM-Graz: prevent warnings */
198 # undef THR_BOUND
199 # undef THR_NEW_LWP
200 # undef THR_DETACHED
201 # undef THR_SUSPENDED
202 # undef THR_DAEMON
204 # define THR_BOUND 0x00000001
205 # define THR_NEW_LWP 0x00000002
206 # define THR_DAEMON 0x00000010
207 # define THR_DETACHED 0x00000040
208 # define THR_SUSPENDED 0x00000080
209 # define THR_SCHED_FIFO 0x00020000
210 # define THR_SCHED_RR 0x00040000
211 # define THR_SCHED_DEFAULT 0x00080000
213 # define THR_JOINABLE 0x00010000
215 # define THR_SCOPE_SYSTEM 0x00100000
217 # define THR_SCOPE_PROCESS 0x00200000
218 # define THR_INHERIT_SCHED 0x00400000
219 # define THR_EXPLICIT_SCHED 0x00800000
220 # define THR_SCHED_IO 0x01000000
222 # if !defined (ACE_MQX)
223 # if !defined (ACE_HAS_POSIX_SEM) && !defined (ACE_USES_FIFO_SEM)
225 // This needs to be moved out of here.
226 #include /**/ "ace/ACE_export.h"
228 * @class ACE_sema_t
230 * @brief This is used to implement semaphores for platforms that support
231 * POSIX pthreads, but do *not* support POSIX semaphores, i.e.,
232 * it's a different type than the POSIX <sem_t>.
234 class ACE_Export ACE_sema_t
236 public:
237 /// Serialize access to internal state.
238 ACE_mutex_t lock_;
240 /// Block until there are no waiters.
241 ACE_cond_t count_nonzero_;
243 /// Count of the semaphore.
244 u_long count_;
246 /// Number of threads that have called <ACE_OS::sema_wait>.
247 u_long waiters_;
249 # endif /* !ACE_HAS_POSIX_SEM */
251 # if defined (ACE_LACKS_PTHREAD_YIELD) && defined (ACE_HAS_THR_YIELD)
252 # if !defined (ACE_LACKS_RWLOCK_T) && !defined (ACE_HAS_PTHREADS_UNIX98_EXT)
253 # include /**/ <synch.h>
254 typedef rwlock_t ACE_rwlock_t;
255 # endif /* !ACE_LACKS_RWLOCK_T */
256 # include /**/ <thread.h>
257 # endif /* (ACE_LACKS_PTHREAD_YIELD) && defined (ACE_HAS_THR_YIELD) */
259 # else
260 # if !defined (ACE_HAS_POSIX_SEM)
261 typedef sema_t ACE_sema_t;
262 # endif /* !ACE_HAS_POSIX_SEM */
263 # endif /* !ACE_MQX */
265 # if defined (ACE_HAS_PTHREADS_UNIX98_EXT) && !defined (ACE_LACKS_RWLOCK_T)
266 typedef pthread_rwlock_t ACE_rwlock_t;
267 # endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
269 # if defined (__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
271 // glibc 2.2.x or better has pthread_mutex_timedlock()
272 # ifndef ACE_HAS_MUTEX_TIMEOUTS
273 # define ACE_HAS_MUTEX_TIMEOUTS
274 # endif /* ACE_HAS_MUTEX_TIMEOUTS */
276 // Use new pthread_attr_setstack if XPG6 support is enabled.
277 # if defined (_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0) < 600
278 # define ACE_LACKS_PTHREAD_ATTR_SETSTACK
279 # endif /* (_XOPEN_SOURCE - 0) < 600 */
281 # if !defined (_XOPEN_SOURCE) \
282 || (defined (_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0) < 600)
283 // pthread_mutex_timedlock() prototype is not visible if _XOPEN_SOURCE
284 // is not >= 600 (i.e. for XPG6).
285 extern "C" int pthread_mutex_timedlock (pthread_mutex_t *mutex,
286 const struct timespec * abstime);
287 # endif /* _XOPEN_SOURCE && _XOPEN_SOURCE < 600 */
289 # endif /* ACE_LINUX && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) */
290 #endif /* ACE_HAS_PTHREADS */
292 #include /**/ "ace/post.h"
293 #endif /* ACE_OS_INCLUDE_OS_PTHREAD_H */