gnuace: use list of generated files from GENERATED_DIRTY for ADDITIONAL_IDL_TARGETS
[ACE_TAO.git] / ACE / ace / OS_NS_Thread.h
blob98a24079307df61c85e0f4f8e906f98ef0295e44
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file OS_NS_Thread.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Jesper S. M|ller<stophph@diku.dk>
9 * @author and a cast of thousands...
11 * Originally in OS.h.
13 //=============================================================================
15 #ifndef ACE_OS_NS_THREAD_H
16 # define ACE_OS_NS_THREAD_H
18 # include /**/ "ace/pre.h"
20 # include "ace/config-all.h"
22 # if !defined (ACE_LACKS_PRAGMA_ONCE)
23 # pragma once
24 # endif /* ACE_LACKS_PRAGMA_ONCE */
26 # include "ace/Global_Macros.h"
27 # include "ace/Basic_Types.h"
28 # include "ace/Default_Constants.h"
29 # include "ace/os_include/os_pthread.h"
30 # include "ace/os_include/os_sched.h"
31 # include "ace/Base_Thread_Adapter.h"
32 # include "ace/os_include/sys/os_sem.h"
33 # include "ace/os_include/os_semaphore.h"
34 # include "ace/OS_Memory.h"
35 # include "ace/OS_NS_signal.h"
36 # include "ace/ACE_export.h"
37 # include "ace/Object_Manager_Base.h"
39 #if defined (ACE_HAS_TSS_EMULATION) && !defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
40 # if defined (ACE_HAS_VXTHREADS) && !defined (_WRS_CONFIG_SMP) && !defined (INCLUDE_AMP_CPU)
41 # include "taskVarLib.h" /* used by VxWorks < 6.9 */
42 # endif /* VxWorks and ! SMP */
43 #endif
45 # if defined (ACE_EXPORT_MACRO)
46 # undef ACE_EXPORT_MACRO
47 # endif
48 # define ACE_EXPORT_MACRO ACE_Export
50 # if defined (ACE_HAS_PRIOCNTL)
51 // Need to #include thread.h before #defining THR_BOUND, etc.,
52 // when building without threads on SunOS 5.x.
53 # if defined (sun)
54 # include /**/ <thread.h>
55 # endif /* sun */
57 // Need to #include these before #defining USYNC_PROCESS on SunOS 5.x.
58 # include /**/ <sys/rtpriocntl.h>
59 # include /**/ <sys/tspriocntl.h>
60 # endif /* ACE_HAS_PRIOCNTL */
62 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
64 # if defined (ACE_WIN32)
65 typedef DWORD ACE_thread_t;
66 typedef HANDLE ACE_hthread_t;
67 // Native TSS key type
68 typedef DWORD ACE_OS_thread_key_t;
69 // Application TSS key type (use this type except in TSS Emulation)
70 # if defined (ACE_HAS_TSS_EMULATION)
71 typedef u_int ACE_thread_key_t;
72 # else /* ! ACE_HAS_TSS_EMULATION */
73 typedef ACE_OS_thread_key_t ACE_thread_key_t;
74 # endif /* ! ACE_HAS_TSS_EMULATION */
75 # endif /* ACE_WIN32 */
77 ACE_END_VERSIONED_NAMESPACE_DECL
79 # if !defined (ACE_HAS_POSIX_SEM) && defined (ACE_USES_FIFO_SEM)
81 extern "C" {
82 typedef struct
84 char* name_;
85 ACE_HANDLE fd_[2];
86 } ACE_sema_t;
89 #endif /* !ACE_HAS_POSIX_SEM && ACE_USES_FIFO_SEM */
91 # if defined (ACE_HAS_THREADS)
93 # if defined (ACE_HAS_STHREADS)
94 # include /**/ <synch.h>
95 # include /**/ <thread.h>
96 # define ACE_SCOPE_PROCESS P_PID
97 # define ACE_SCOPE_LWP P_LWPID
98 # define ACE_SCOPE_THREAD (ACE_SCOPE_LWP + 1)
99 # else
100 # define ACE_SCOPE_PROCESS 0
101 # define ACE_SCOPE_LWP 1
102 # define ACE_SCOPE_THREAD 2
103 # endif /* ACE_HAS_STHREADS */
105 # if !defined (ACE_HAS_PTHREADS)
106 # define ACE_SCHED_OTHER 0
107 # define ACE_SCHED_FIFO 1
108 # define ACE_SCHED_RR 2
109 # endif /* ! ACE_HAS_PTHREADS */
111 # if defined (ACE_HAS_PTHREADS)
112 // moved to pthread.h
113 # elif defined (ACE_HAS_STHREADS)
115 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
117 // Solaris threads, without PTHREADS.
118 // Typedefs to help compatibility with Windows NT and Pthreads.
119 typedef thread_t ACE_thread_t;
120 // Native TSS key type (not for general use)
121 typedef thread_key_t ACE_OS_thread_key_t;
122 // Application TSS key type (use this type except in TSS Emulation)
123 # if defined (ACE_HAS_TSS_EMULATION)
124 typedef u_int ACE_thread_key_t;
125 # else /* ! ACE_HAS_TSS_EMULATION */
126 typedef ACE_OS_thread_key_t ACE_thread_key_t;
127 # endif /* ! ACE_HAS_TSS_EMULATION */
128 typedef mutex_t ACE_mutex_t;
129 # if !defined (ACE_LACKS_RWLOCK_T)
130 typedef rwlock_t ACE_rwlock_t;
131 # endif /* !ACE_LACKS_RWLOCK_T */
132 # if !defined (ACE_HAS_POSIX_SEM) && !defined (ACE_USES_FIFO_SEM)
133 typedef sema_t ACE_sema_t;
134 # endif /* !ACE_HAS_POSIX_SEM */
136 typedef cond_t ACE_cond_t;
137 struct ACE_Export ACE_condattr_t
139 int type;
141 struct ACE_Export ACE_mutexattr_t
143 int type;
145 typedef ACE_thread_t ACE_hthread_t;
146 typedef ACE_mutex_t ACE_thread_mutex_t;
148 ACE_END_VERSIONED_NAMESPACE_DECL
150 # define THR_CANCEL_DISABLE 0
151 # define THR_CANCEL_ENABLE 0
152 # define THR_CANCEL_DEFERRED 0
153 # define THR_CANCEL_ASYNCHRONOUS 0
154 # define THR_JOINABLE 0
155 # define THR_SCHED_FIFO 0
156 # define THR_SCHED_RR 0
157 # define THR_SCHED_DEFAULT 0
158 # define THR_INHERIT_SCHED 0
159 # define THR_SCOPE_PROCESS 0
161 # elif defined (ACE_VXWORKS)
162 # include /**/ <sysLib.h> // for sysClkRateGet()
163 # include /**/ <types/vxTypes.h>
164 # if !defined (__RTP__)
165 # include /**/ <taskLib.h>
166 # include /**/ <taskHookLib.h>
167 # endif
169 // make sure these are included for VXWORKS.
170 // @todo move these to a common place, perhaps the top of the file.
171 # include "ace/os_include/os_fcntl.h"
172 # include "ace/os_include/os_netdb.h"
173 # include "ace/os_include/os_semaphore.h"
174 # include "ace/os_include/os_signal.h"
175 # include "ace/os_include/os_stdio.h"
176 # include "ace/os_include/os_stdlib.h"
177 # include "ace/os_include/os_stropts.h"
178 # include "ace/os_include/os_unistd.h"
179 # include "ace/os_include/arpa/os_inet.h"
180 # include "ace/os_include/sys/os_select.h"
181 # include "ace/os_include/sys/os_socket.h"
183 // task options: the other options are either obsolete, internal, or for
184 // Fortran or Ada support
185 # define VX_UNBREAKABLE 0x0002 /* breakpoints ignored */
186 # if !defined (VX_FP_TASK)
187 # define VX_FP_TASK 0x0008 /* floating point coprocessor */
188 # endif
189 # define VX_PRIVATE_ENV 0x0080 /* private environment support */
190 # define VX_NO_STACK_FILL 0x0100 /* do not stack fill for
191 checkstack () */
193 # define THR_CANCEL_DISABLE 0
194 # define THR_CANCEL_ENABLE 0
195 # define THR_CANCEL_DEFERRED 0
196 # define THR_CANCEL_ASYNCHRONOUS 0
197 # define THR_BOUND 0
198 # define THR_NEW_LWP 0
199 # define THR_DETACHED 0
200 # define THR_SUSPENDED 0
201 # define THR_DAEMON 0
202 # define THR_JOINABLE 0
203 # define THR_SCHED_FIFO 0
204 # define THR_SCHED_RR 0
205 # define THR_SCHED_DEFAULT 0
206 # define THR_INHERIT_SCHED 0
207 # define THR_EXPLICIT_SCHED 0
208 # define THR_SCHED_IO 0
209 # define THR_SCOPE_SYSTEM 0
210 # define THR_SCOPE_PROCESS 0
211 # define USYNC_THREAD 0
212 # define USYNC_PROCESS 1 /* It's all global on VxWorks
213 (without MMU option). */
215 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
217 typedef SEM_ID ACE_mutex_t;
218 // Implement ACE_thread_mutex_t with ACE_mutex_t because there's just
219 // one process . . .
220 typedef ACE_mutex_t ACE_thread_mutex_t;
221 # if !defined (ACE_HAS_POSIX_SEM)
222 // Use VxWorks semaphores, wrapped ...
223 typedef struct
225 /// Semaphore handle. This is allocated by VxWorks.
226 SEM_ID sema_;
228 /// Name of the semaphore: always NULL with VxWorks.
229 char *name_;
230 } ACE_sema_t;
231 # endif /* !ACE_HAS_POSIX_SEM */
232 typedef ACE_VX_TASK_ID ACE_thread_t;
233 typedef ACE_VX_TASK_ID ACE_hthread_t;
234 // Key type: the ACE TSS emulation requires the key type be unsigned,
235 // for efficiency. (Current POSIX and Solaris TSS implementations also
236 // use u_int, so the ACE TSS emulation is compatible with them.)
237 // Native TSS key type
238 typedef u_int ACE_OS_thread_key_t;
239 // Application TSS key type (use this type except in TSS Emulation)
240 # if defined (ACE_HAS_TSS_EMULATION)
241 typedef u_int ACE_thread_key_t;
242 # else /* ! ACE_HAS_TSS_EMULATION */
243 typedef ACE_OS_thread_key_t ACE_thread_key_t;
244 # endif /* ! ACE_HAS_TSS_EMULATION */
246 ACE_END_VERSIONED_NAMESPACE_DECL
248 # elif defined (ACE_HAS_WTHREADS)
250 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
252 typedef CRITICAL_SECTION ACE_thread_mutex_t;
254 typedef struct
256 /// Either USYNC_THREAD or USYNC_PROCESS
257 int type_;
258 union
260 HANDLE proc_mutex_;
261 CRITICAL_SECTION thr_mutex_;
263 } ACE_mutex_t;
265 // Wrapper for NT Events.
266 typedef HANDLE ACE_event_t;
268 # if defined (ACE_WIN32)
269 //@@ ACE_USES_WINCE_SEMA_SIMULATION is used to debug
270 // semaphore simulation on WinNT. It should be
271 // changed to ACE_USES_HAS_WINCE at some later point.
272 # if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
273 typedef HANDLE ACE_sema_t;
274 # else
276 * @class ACE_sema_t
278 * @brief Semaphore simulation for Windows CE.
280 class ACE_Export ACE_sema_t
282 public:
283 /// Serializes access to @c count_.
284 ACE_thread_mutex_t lock_;
286 /// This event is signaled whenever the count becomes non-zero.
287 ACE_event_t count_nonzero_;
289 /// Current count of the semaphore.
290 u_int count_;
293 # endif /* ACE_USES_WINCE_SEMA_SIMULATION */
294 # endif /* defined (ACE_WIN32) */
296 ACE_END_VERSIONED_NAMESPACE_DECL
298 // These need to be different values, neither of which can be 0...
299 # define USYNC_THREAD 1
300 # define USYNC_PROCESS 2
302 # define THR_CANCEL_DISABLE 0
303 # define THR_CANCEL_ENABLE 0
304 # define THR_CANCEL_DEFERRED 0
305 # define THR_CANCEL_ASYNCHRONOUS 0
306 # define THR_DETACHED 0x02000000 /* ignore in most places */
307 # define THR_BOUND 0 /* ignore in most places */
308 # define THR_NEW_LWP 0 /* ignore in most places */
309 # define THR_DAEMON 0 /* ignore in most places */
310 # define THR_JOINABLE 0 /* ignore in most places */
311 # define THR_SUSPENDED CREATE_SUSPENDED
312 # if !defined (STACK_SIZE_PARAM_IS_A_RESERVATION)
313 # define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
314 # endif /* STACK_SIZE_PARAM_IS_A_RESERVATION */
315 # define THR_USE_AFX 0x01000000
316 # define THR_SCHED_FIFO 0
317 # define THR_SCHED_RR 0
318 # define THR_SCHED_DEFAULT 0
319 # define THR_INHERIT_SCHED 0
320 # define THR_EXPLICIT_SCHED 0
321 # define THR_SCOPE_PROCESS 0
322 # define THR_SCOPE_SYSTEM 0
323 # endif /* ACE_HAS_PTHREADS / STHREADS / VXWORKS / WTHREADS **********/
325 # if defined (ACE_HAS_WTHREADS_CONDITION_VARIABLE)
327 typedef CONDITION_VARIABLE ACE_cond_t;
329 # elif defined (ACE_LACKS_COND_T)
331 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
334 * @class ACE_cond_t
336 * @brief This structure is used to implement condition variables on
337 * platforms that lack it natively, such as VxWorks, and Win32.
339 * At the current time, this stuff only works for threads
340 * within the same process.
342 class ACE_Export ACE_cond_t
344 public:
346 /// Returns the number of waiters.
347 long waiters (void) const;
349 //protected:
350 /// Number of waiting threads.
351 long waiters_;
353 /// Serialize access to the waiters count.
354 ACE_thread_mutex_t waiters_lock_;
356 /// Queue up threads waiting for the condition to become signaled.
357 ACE_sema_t sema_;
359 # if defined (ACE_VXWORKS) || defined (ACE_MQX)
361 * A semaphore used by the broadcast/signal thread to wait for all
362 * the waiting thread(s) to wake up and be released from the
363 * semaphore.
365 ACE_sema_t waiters_done_;
366 # elif defined (ACE_WIN32)
368 * An auto reset event used by the broadcast/signal thread to wait
369 * for the waiting thread(s) to wake up and get a chance at the
370 * semaphore.
372 HANDLE waiters_done_;
373 # else
374 # error "Please implement this feature or check your config.h file!"
375 # endif /* ACE_VXWORKS */
377 /// Keeps track of whether we were broadcasting or just signaling.
378 size_t was_broadcast_;
381 ACE_END_VERSIONED_NAMESPACE_DECL
383 # endif /* ACE_LACKS_COND_T */
385 # if defined (ACE_HAS_WTHREADS_CONDITION_VARIABLE) || defined (ACE_LACKS_COND_T)
387 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
389 struct ACE_Export ACE_condattr_t
391 int type;
394 #if !defined (ACE_MQX)
395 struct ACE_Export ACE_mutexattr_t
397 int type;
399 #endif
401 ACE_END_VERSIONED_NAMESPACE_DECL
403 # endif /* ACE_HAS_WTHREADS_CONDITION_VARIABLE || ACE_LACKS_COND_T */
405 # if defined (ACE_LACKS_RWLOCK_T)
407 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
410 * @class ACE_rwlock_t
412 * @brief This is used to implement readers/writer locks on NT,
413 * VxWorks, and POSIX pthreads.
415 * At the current time, this stuff only works for threads
416 * within the same process.
418 struct ACE_Export ACE_rwlock_t
420 public:
421 //protected:
423 /// Serialize access to internal state.
424 ACE_mutex_t lock_;
426 /// Reader threads waiting to acquire the lock.
427 ACE_cond_t waiting_readers_;
429 /// Number of waiting readers.
430 int num_waiting_readers_;
432 /// Writer threads waiting to acquire the lock.
433 ACE_cond_t waiting_writers_;
435 /// Number of waiting writers.
436 int num_waiting_writers_;
438 /// Value is -1 if writer has the lock, else this keeps track of the
439 /// number of readers holding the lock.
440 int ref_count_;
442 /// Indicate that a reader is trying to upgrade
443 bool important_writer_;
445 /// Condition for the upgrading reader
446 ACE_cond_t waiting_important_writer_;
449 ACE_END_VERSIONED_NAMESPACE_DECL
451 # elif defined (ACE_HAS_PTHREADS_UNIX98_EXT)
452 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
453 typedef pthread_rwlock_t ACE_rwlock_t;
454 ACE_END_VERSIONED_NAMESPACE_DECL
455 # elif defined (ACE_HAS_STHREADS)
456 # include /**/ <synch.h>
457 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
458 typedef rwlock_t ACE_rwlock_t;
459 ACE_END_VERSIONED_NAMESPACE_DECL
460 # endif /* ACE_LACKS_RWLOCK_T */
462 // Define some default thread priorities on all threaded platforms, if
463 // not defined above or in the individual platform config file.
464 // ACE_THR_PRI_FIFO_DEF should be used by applications for default
465 // real-time thread priority. ACE_THR_PRI_OTHER_DEF should be used
466 // for non-real-time priority.
467 # if !defined(ACE_THR_PRI_FIFO_DEF)
468 # if defined (ACE_WTHREADS)
469 // It would be more in spirit to use THREAD_PRIORITY_NORMAL. But,
470 // using THREAD_PRIORITY_ABOVE_NORMAL should give preference to the
471 // threads in this process, even if the process is not in the
472 // REALTIME_PRIORITY_CLASS.
473 # define ACE_THR_PRI_FIFO_DEF THREAD_PRIORITY_ABOVE_NORMAL
474 # else /* ! ACE_WTHREADS */
475 # define ACE_THR_PRI_FIFO_DEF 0
476 # endif /* ! ACE_WTHREADS */
477 # endif /* ! ACE_THR_PRI_FIFO_DEF */
479 # if !defined(ACE_THR_PRI_OTHER_DEF)
480 # if defined (ACE_WTHREADS)
481 // It would be more in spirit to use THREAD_PRIORITY_NORMAL. But,
482 // using THREAD_PRIORITY_ABOVE_NORMAL should give preference to the
483 // threads in this process, even if the process is not in the
484 // REALTIME_PRIORITY_CLASS.
485 # define ACE_THR_PRI_OTHER_DEF THREAD_PRIORITY_NORMAL
486 # else /* ! ACE_WTHREADS */
487 # define ACE_THR_PRI_OTHER_DEF 0
488 # endif /* ! ACE_WTHREADS */
489 # endif /* ! ACE_THR_PRI_OTHER_DEF */
491 // Recursive mutex support.
493 // There are two parts to this:
494 // 1. The mutex type itself. This is based on whether or not the
495 // platform supports recursive mutexes natively or they're emulated.
496 // 2. Support for using the recursive mutex with a condition variable.
497 // When a thread waits on a condition variable, it has to relinquish
498 // the lock and wait atomically, then reacquire it after the condition
499 // variable is signaled. In non-recursive mutexes, the platform
500 // handles this automatically. But in recursive mutexes, especially
501 // when emulated, the recursion count needs to be maintained across
502 // the wait. Since another thread needs to be able to acquire the
503 // lock, it needs to appear free, even if the waiting thread had done
504 // multiple acquires. Thus, there's another structure to hold this
505 // information, and is used with the recursive_mutex_cond_unlock()
506 // and recursive_mutex_cond_relock() methods to maintain the expected
507 // state when the wait finishes.
508 # if defined (ACE_HAS_RECURSIVE_MUTEXES)
510 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
512 typedef ACE_thread_mutex_t ACE_recursive_thread_mutex_t;
513 # if defined (ACE_WIN32)
514 // Windows has recursive mutexes, but doesn't have condition variables,
515 // so there's no built-in support for this. Thus, the condition-related
516 // unlock/relock is augmented in ACE.
517 struct ACE_recursive_mutex_state
519 // On Windows the augmented processing is simply unlocking/relocking
520 // the recursive locks - the condition handles a single lock ok.
521 LONG relock_count_;
523 # else
524 // No need for special handling; just need a type for method signatures.
525 typedef int ACE_recursive_mutex_state;
526 # endif /* ACE_WIN32 */
528 ACE_END_VERSIONED_NAMESPACE_DECL
530 # else
532 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
535 * @class ACE_recursive_thread_mutex_t
537 * @brief
538 * Implement a thin C++ wrapper that allows nested acquisition
539 * and release of a mutex that occurs in the same thread.
541 * This implementation is based on an algorithm sketched by Dave
542 * Butenhof <butenhof@zko.dec.com>. Naturally, I take the
543 * credit for any mistakes ;-)
545 class ACE_recursive_thread_mutex_t
547 public:
548 /// Guards the state of the nesting level and thread id.
549 ACE_thread_mutex_t nesting_mutex_;
551 /// This condition variable suspends other waiting threads until the
552 /// mutex is available.
553 ACE_cond_t lock_available_;
555 /// Current nesting level of the recursion.
556 int nesting_level_;
558 /// Current owner of the lock.
559 ACE_thread_t owner_id_;
562 /// Since recursive mutex is emulated, the state saving needs to be handled
563 /// in ACE as well. These members save those from ACE_recursive_thread_mutex_t.
564 struct ACE_recursive_mutex_state
566 int nesting_level_;
567 ACE_thread_t owner_id_;
570 ACE_END_VERSIONED_NAMESPACE_DECL
572 # endif /* ACE_HAS_RECURSIVE_MUTEXES */
574 # else /* !ACE_HAS_THREADS, i.e., the OS/platform doesn't support threading. */
576 // Give these things some reasonable value...
577 # define ACE_SCOPE_PROCESS 0
578 # define ACE_SCOPE_LWP 1
579 # define ACE_SCOPE_THREAD 2
580 # define ACE_SCHED_OTHER 0
581 # define ACE_SCHED_FIFO 1
582 # define ACE_SCHED_RR 2
583 # if !defined (THR_CANCEL_DISABLE)
584 # define THR_CANCEL_DISABLE 0
585 # endif /* ! THR_CANCEL_DISABLE */
586 # if !defined (THR_CANCEL_ENABLE)
587 # define THR_CANCEL_ENABLE 0
588 # endif /* ! THR_CANCEL_ENABLE */
589 # if !defined (THR_CANCEL_DEFERRED)
590 # define THR_CANCEL_DEFERRED 0
591 # endif /* ! THR_CANCEL_DEFERRED */
592 # if !defined (THR_CANCEL_ASYNCHRONOUS)
593 # define THR_CANCEL_ASYNCHRONOUS 0
594 # endif /* ! THR_CANCEL_ASYNCHRONOUS */
595 # if !defined (THR_JOINABLE)
596 # define THR_JOINABLE 0 /* ignore in most places */
597 # endif /* ! THR_JOINABLE */
598 # if !defined (THR_DETACHED)
599 # define THR_DETACHED 0 /* ignore in most places */
600 # endif /* ! THR_DETACHED */
601 # if !defined (THR_DAEMON)
602 # define THR_DAEMON 0 /* ignore in most places */
603 # endif /* ! THR_DAEMON */
604 # if !defined (THR_BOUND)
605 # define THR_BOUND 0 /* ignore in most places */
606 # endif /* ! THR_BOUND */
607 # if !defined (THR_NEW_LWP)
608 # define THR_NEW_LWP 0 /* ignore in most places */
609 # endif /* ! THR_NEW_LWP */
610 # if !defined (THR_SUSPENDED)
611 # define THR_SUSPENDED 0 /* ignore in most places */
612 # endif /* ! THR_SUSPENDED */
613 # if !defined (THR_SCHED_FIFO)
614 # define THR_SCHED_FIFO 0
615 # endif /* ! THR_SCHED_FIFO */
616 # if !defined (THR_SCHED_RR)
617 # define THR_SCHED_RR 0
618 # endif /* ! THR_SCHED_RR */
619 # if !defined (THR_SCHED_DEFAULT)
620 # define THR_SCHED_DEFAULT 0
621 # endif /* ! THR_SCHED_DEFAULT */
622 # if !defined (THR_INHERIT_SCHED)
623 # define THR_INHERIT_SCHED 0
624 # endif /* ! THR_INHERIT_SCHED */
625 # if !defined (USYNC_THREAD)
626 # define USYNC_THREAD 0
627 # endif /* ! USYNC_THREAD */
628 # if !defined (USYNC_PROCESS)
629 # define USYNC_PROCESS 0
630 # endif /* ! USYNC_PROCESS */
631 # if !defined (THR_SCOPE_PROCESS)
632 # define THR_SCOPE_PROCESS 0
633 # endif /* ! THR_SCOPE_PROCESS */
634 # if !defined (THR_SCOPE_SYSTEM)
635 # define THR_SCOPE_SYSTEM 0
636 # endif /* ! THR_SCOPE_SYSTEM */
638 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
640 // These are dummies needed for class OS.h
641 typedef int ACE_cond_t;
642 struct ACE_Export ACE_condattr_t
644 int type;
646 struct ACE_Export ACE_mutexattr_t
648 int type;
650 typedef int ACE_mutex_t;
651 typedef int ACE_thread_mutex_t;
652 typedef int ACE_recursive_thread_mutex_t;
653 typedef int ACE_recursive_mutex_state;
654 # if !defined (ACE_HAS_POSIX_SEM) && !defined (ACE_USES_FIFO_SEM)
655 typedef int ACE_sema_t;
656 # endif /* !ACE_HAS_POSIX_SEM && !ACE_USES_FIFO_SEM */
657 typedef int ACE_rwlock_t;
658 typedef int ACE_thread_t;
659 typedef int ACE_hthread_t;
660 // Native TSS key type
661 typedef unsigned int ACE_OS_thread_key_t;
662 // Application TSS key type (use this type except in TSS Emulation)
663 # if defined (ACE_HAS_TSS_EMULATION)
664 typedef u_int ACE_thread_key_t;
665 # else /* ! ACE_HAS_TSS_EMULATION */
666 typedef ACE_OS_thread_key_t ACE_thread_key_t;
667 # endif /* ! ACE_HAS_TSS_EMULATION */
669 ACE_END_VERSIONED_NAMESPACE_DECL
671 // Ensure that ACE_THR_PRI_FIFO_DEF and ACE_THR_PRI_OTHER_DEF are
672 // defined on non-threaded platforms, to support application source
673 // code compatibility. ACE_THR_PRI_FIFO_DEF should be used by
674 // applications for default real-time thread priority.
675 // ACE_THR_PRI_OTHER_DEF should be used for non-real-time priority.
676 # if !defined(ACE_THR_PRI_FIFO_DEF)
677 # define ACE_THR_PRI_FIFO_DEF 0
678 # endif /* ! ACE_THR_PRI_FIFO_DEF */
679 # if !defined(ACE_THR_PRI_OTHER_DEF)
680 # define ACE_THR_PRI_OTHER_DEF 0
681 # endif /* ! ACE_THR_PRI_OTHER_DEF */
683 # endif /* ACE_HAS_THREADS ***********************************************/
685 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
688 * @class ACE_Thread_ID
690 * @brief
691 * Defines a platform-independent thread ID class. Note that
692 * this class should be defined within the scope of a thread, rather
693 * than at global scope!
695 class ACE_Export ACE_Thread_ID
697 public:
698 /// Initialize the object using the thread id and thread handle
699 /// passed as parameters.
700 ACE_Thread_ID (ACE_thread_t thr_id,
701 ACE_hthread_t thr_handle);
703 /// Initialize the object using calls to ACE_OS::thr_self().
704 ACE_Thread_ID (void);
706 /// Copy constructor.
707 ACE_Thread_ID (const ACE_Thread_ID &id);
709 /// Assignment operator
710 ACE_Thread_ID& operator= (const ACE_Thread_ID &id);
712 /// Get the thread id.
713 ACE_thread_t id (void) const;
715 /// Set the thread id.
716 void id (ACE_thread_t);
718 /// Get the thread handle.
719 ACE_hthread_t handle (void) const;
721 /// Set the thread handle.
722 void handle (ACE_hthread_t);
724 // Create a string representation of the thread id.
725 void to_string (char *thr_string, size_t thr_string_len) const;
727 // Create a string representation of the thread id.
728 template <size_t N>
729 void to_string (char (&thr_string)[N]) const
731 this->to_string (thr_string, N);
734 /// Equality operator.
735 bool operator== (const ACE_Thread_ID &) const;
737 /// Inequality operator.
738 bool operator!= (const ACE_Thread_ID &) const;
740 private:
741 /// Identify the thread.
742 ACE_thread_t thread_id_;
744 /// Handle to the thread (typically used to "wait" on Win32).
745 ACE_hthread_t thread_handle_;
748 // = The ACE_Sched_Priority type should be used for platform-
749 // independent thread and process priorities, by convention.
750 // int should be used for OS-specific priorities.
751 typedef int ACE_Sched_Priority;
753 # if !defined (ACE_DEFAULT_SYNCH_TYPE)
754 # if defined (ACE_VXWORKS)
755 // Types include these options: SEM_Q_PRIORITY, SEM_Q_FIFO,
756 // SEM_DELETE_SAFE, and SEM_INVERSION_SAFE. SEM_Q_FIFO is
757 // used as the default because that is VxWorks' default.
758 # define ACE_DEFAULT_SYNCH_TYPE SEM_Q_FIFO
759 # else
760 # define ACE_DEFAULT_SYNCH_TYPE USYNC_THREAD
761 # endif /* ACE_VXWORKS */
762 #endif /* ! ACE_DEFAULT_SYNCH_TYPE */
764 // forward declaration
765 class ACE_Sched_Params;
766 class ACE_Time_Value;
768 #if defined (ACE_WIN32)
769 typedef int ACE_idtype_t;
770 typedef DWORD ACE_id_t;
771 typedef int ACE_pri_t;
772 # define ACE_SELF (0)
773 #else /* !defined (ACE_WIN32) */
774 # if defined (ACE_HAS_IDTYPE_T)
775 typedef idtype_t ACE_idtype_t;
776 # else
777 typedef int ACE_idtype_t;
778 # endif /* ACE_HAS_IDTYPE_T */
779 # if defined (ACE_HAS_STHREADS)
780 # if defined (ACE_LACKS_PRI_T)
781 typedef int pri_t;
782 # endif /* ACE_LACKS_PRI_T */
783 typedef id_t ACE_id_t;
784 # define ACE_SELF P_MYID
785 typedef pri_t ACE_pri_t;
786 # else /* ! ACE_HAS_STHREADS */
787 typedef long ACE_id_t;
788 # define ACE_SELF (-1)
789 typedef short ACE_pri_t;
790 # endif /* ! ACE_HAS_STHREADS */
791 #endif /* !defined (ACE_WIN32) */
793 # if defined (ACE_HAS_TSS_EMULATION)
794 // Allow config.h to set the default number of thread keys.
795 # if !defined (ACE_DEFAULT_THREAD_KEYS)
796 # define ACE_DEFAULT_THREAD_KEYS 64
797 # endif /* ! ACE_DEFAULT_THREAD_KEYS */
799 // forward declaration
800 class ACE_TSS_Keys;
803 * @class ACE_TSS_Emulation
805 * @brief Thread-specific storage emulation.
807 * This provides a thread-specific storage implementation.
808 * It is intended for use on platforms that don't have a
809 * native TSS, or have a TSS with limitations such as the
810 * number of keys or lack of support for removing keys.
812 class ACE_Export ACE_TSS_Emulation
814 public:
815 typedef void (*ACE_TSS_DESTRUCTOR)(void *value);
817 /// Maximum number of TSS keys allowed over the life of the program.
818 enum { ACE_TSS_THREAD_KEYS_MAX = ACE_DEFAULT_THREAD_KEYS };
820 /// Returns the total number of keys allocated so far.
821 static u_int total_keys ();
823 /// Sets the argument to the next available key. Returns 0 on success,
824 /// -1 if no keys are available.
825 static int next_key (ACE_thread_key_t &key);
827 /// Release a key that was used. This way the key can be given out in a
828 /// new request. Returns 0 on success, 1 if the key was not reserved.
829 static int release_key (ACE_thread_key_t key);
831 /// Check a key for validity.
832 static int is_key (ACE_thread_key_t key);
834 /// Returns the exit hook associated with the key. Does _not_ check
835 /// for a valid key.
836 static ACE_TSS_DESTRUCTOR tss_destructor (const ACE_thread_key_t key);
838 /// Associates the TSS destructor with the key. Does _not_ check
839 /// for a valid key.
840 static void tss_destructor (const ACE_thread_key_t key,
841 ACE_TSS_DESTRUCTOR destructor);
843 /// Accesses the object referenced by key in the current thread's TSS array.
844 /// Does _not_ check for a valid key.
845 static void *&ts_object (const ACE_thread_key_t key);
848 * Setup an array to be used for local TSS. Returns the array
849 * address on success. Returns 0 if local TSS had already been
850 * setup for this thread. There is no corresponding tss_close ()
851 * because it is not needed.
852 * @note tss_open () is called by ACE for threads that it spawns.
853 * If your application spawns threads without using ACE, and it uses
854 * ACE's TSS emulation, each of those threads should call tss_open
855 * (). See the ace_thread_adapter () implementation for an example.
857 static void *tss_open (void *ts_storage[ACE_TSS_THREAD_KEYS_MAX]);
859 /// Shutdown TSS emulation. For use only by ACE_OS::cleanup_tss ().
860 static void tss_close ();
862 private:
863 // Global TSS structures.
864 /// Contains the possible value of the next key to be allocated. Which key
865 /// is actually allocated is based on the tss_keys_used
866 static u_int total_keys_;
868 /// Array of thread exit hooks (TSS destructors) that are called for each
869 /// key (that has one) when the thread exits.
870 static ACE_TSS_DESTRUCTOR tss_destructor_ [ACE_TSS_THREAD_KEYS_MAX];
872 /// TSS_Keys instance to administrate whether a specific key is in used
873 /// or not.
874 /// or not.
875 // Static construction in VxWorks 5.4 and later is slightly broken.
876 // If the static object is more complex than an integral type, static
877 // construction will occur twice. The tss_keys_used_ object is
878 // statically constructed and then modified by ACE_Log_Msg::instance()
879 // when two keys are created and TSS data is stored. However, at
880 // the end of static construction the tss_keys_used_ object is again
881 // initialized and therefore it will appear to next_key() that no
882 // TSS keys have been handed out. That is all true unless the
883 // tss_keys_used object is a static pointer instead of a static object.
884 static ACE_TSS_Keys* tss_keys_used_;
886 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
887 /// Location of current thread's TSS array.
888 static void **tss_base (void* ts_storage[] = 0, u_int *ts_created = 0);
889 # else /* ! ACE_HAS_THREAD_SPECIFIC_STORAGE */
890 /// Location of current thread's TSS array.
891 static void **&tss_base ();
893 # if defined (ACE_HAS_VXTHREADS)
894 # if (defined (_WRS_CONFIG_SMP) || defined (INCLUDE_AMP_CPU))
895 static __thread void* ace_tss_keys;
896 # else /* ! VxWorks SMP */
897 static void* ace_tss_keys;
898 # endif /* ! VxWorks SMP */
899 # endif /* ACE_HAS_VXTHREADS */
901 # endif /* ! ACE_HAS_THREAD_SPECIFIC_STORAGE */
903 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
904 // Rely on native thread specific storage for the implementation,
905 // but just use one key.
906 static ACE_OS_thread_key_t native_tss_key_;
908 // Used to indicate if native tss key has been allocated
909 static bool key_created_;
910 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
912 # endif /* ACE_HAS_TSS_EMULATION */
914 // moved ACE_TSS_Ref, ACE_TSS_Info, and ACE_TSS_Keys class
915 // declarations from OS.cpp so they are visible to the single
916 // file of template instantiations.
917 # if defined (ACE_WIN32) || defined (ACE_HAS_TSS_EMULATION)
919 * @class ACE_TSS_Ref
921 * @brief "Reference count" for thread-specific storage keys.
923 * Since the <ACE_Unbounded_Stack> doesn't allow duplicates, the
924 * "reference count" is the identify of the thread_id.
926 class ACE_TSS_Ref
928 public:
929 /// Constructor
930 ACE_TSS_Ref (ACE_thread_t id);
932 /// Default constructor
933 ACE_TSS_Ref (void);
935 /// Check for equality.
936 bool operator== (const ACE_TSS_Ref &) const;
938 /// Check for inequality.
939 bool operator!= (const ACE_TSS_Ref &) const;
941 // private:
943 /// ID of thread using a specific key.
944 ACE_thread_t tid_;
948 * @class ACE_TSS_Info
950 * @brief Thread Specific Key management.
952 * This class maps a key to a "destructor."
954 class ACE_TSS_Info
956 public:
957 /// Declare pointer to function to destroy tss object.
958 typedef void (*Destructor)(void *);
960 /// Constructor
961 ACE_TSS_Info (ACE_thread_key_t key,
962 Destructor dest = 0);
964 /// Default constructor
965 ACE_TSS_Info (void);
967 /// Returns 1 if the key is in use, 0 if not.
968 int key_in_use (void) const { return thread_count_ != -1; }
970 /// Mark the key as being in use if the flag is non-zero, or
971 /// not in use if the flag is 0.
972 void key_in_use (int flag) { thread_count_ = flag == 0 ? -1 : 1; }
974 /// Check for equality.
975 bool operator== (const ACE_TSS_Info &) const;
977 /// Check for inequality.
978 bool operator!= (const ACE_TSS_Info &) const;
980 /// Dump the state.
981 void dump (void);
983 private:
984 /// Key to the thread-specific storage item.
985 ACE_thread_key_t key_;
987 /// "Destructor" that gets called when the item is finally released.
988 Destructor destructor_;
990 /// Count of threads that are using this key. Contains -1 when the
991 /// key is not in use.
992 int thread_count_;
994 friend class ACE_TSS_Cleanup;
998 * @class ACE_TSS_Keys
1000 * @brief Collection of in-use flags for a thread's TSS keys.
1001 * For internal use only by ACE_TSS_Cleanup; it is public because
1002 * some compilers can't use nested classes for template instantiation
1003 * parameters.
1005 * Wrapper around array of whether each key is in use. A simple
1006 * typedef doesn't work with Sun C++ 4.2.
1008 class ACE_TSS_Keys
1010 public:
1011 ACE_ALLOC_HOOK_DECLARE;
1013 /// Default constructor, to initialize all bits to zero (unused).
1014 ACE_TSS_Keys (void);
1016 /// Mark the specified key as being in use, if it was not already so marked.
1017 /// Returns 1 if the had already been marked, 0 if not.
1018 int test_and_set (const ACE_thread_key_t key);
1020 /// Mark the specified key as not being in use, if it was not already so
1021 /// cleared. Returns 1 if the key had already been cleared, 0 if not.
1022 int test_and_clear (const ACE_thread_key_t key);
1024 /// Return whether the specific key is marked as in use.
1025 /// Returns 1 if the key is been marked, 0 if not.
1026 int is_set (const ACE_thread_key_t key) const;
1028 private:
1029 /// For a given key, find the word and bit number that represent it.
1030 static void find (const u_int key, u_int &word, u_int &bit);
1032 enum
1034 # if ACE_SIZEOF_LONG == 8
1035 ACE_BITS_PER_WORD = 64,
1036 # elif ACE_SIZEOF_LONG == 4
1037 ACE_BITS_PER_WORD = 32,
1038 # else
1039 # error ACE_TSS_Keys only supports 32 or 64 bit longs.
1040 # endif /* ACE_SIZEOF_LONG == 8 */
1041 ACE_WORDS = (ACE_DEFAULT_THREAD_KEYS - 1) / ACE_BITS_PER_WORD + 1
1044 /// Bit flag collection. A bit value of 1 indicates that the key is in
1045 /// use by this thread.
1046 u_long key_bit_words_[ACE_WORDS];
1049 # endif /* defined (ACE_WIN32) || defined (ACE_HAS_TSS_EMULATION) */
1051 ACE_END_VERSIONED_NAMESPACE_DECL
1053 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) && ACE_HAS_VERSIONED_NAMESPACE == 1)
1054 # define ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _ace_mutex_lock_cleanup_adapter)
1055 #endif /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
1057 # if defined (ACE_HAS_THR_C_FUNC)
1058 // This is necessary to work around nasty problems with MVS C++.
1059 extern "C" ACE_Export void ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME (void *args);
1060 # define ACE_PTHREAD_CLEANUP_PUSH(A) pthread_cleanup_push (ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME, (void *) A);
1061 # define ACE_PTHREAD_CLEANUP_POP(A) pthread_cleanup_pop(A)
1062 # elif defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CLEANUP)
1063 // Though we are defining a extern "C" function to match the prototype of
1064 // pthread_cleanup_push, it is undone by the Solaris header file
1065 // /usr/include/pthread.h. So this macro generates a warning under Solaris
1066 // with SunCC. This is a bug in the Solaris header file.
1067 extern "C" ACE_Export void ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME (void *args);
1068 # define ACE_PTHREAD_CLEANUP_PUSH(A) pthread_cleanup_push (ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME, (void *) A);
1069 # define ACE_PTHREAD_CLEANUP_POP(A) pthread_cleanup_pop(A)
1070 # else
1071 # define ACE_PTHREAD_CLEANUP_PUSH(A)
1072 # define ACE_PTHREAD_CLEANUP_POP(A)
1073 # endif /* ACE_HAS_THR_C_FUNC */
1075 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1077 # if !defined (ACE_WIN32)
1078 // forward decl's
1079 class ACE_event_t;
1080 # endif
1082 class ACE_Base_Thread_Adapter;
1084 namespace ACE_OS {
1085 //@{ @name A set of wrappers for threads
1087 /// This is necessary to deal with POSIX pthreads and their use of
1088 /// structures for thread ids.
1089 extern ACE_Export ACE_thread_t NULL_thread;
1091 /// This is necessary to deal with POSIX pthreads and their use of
1092 /// structures for thread handles.
1093 extern ACE_Export ACE_hthread_t NULL_hthread;
1095 /// This is necessary to deal with POSIX pthreads and their use of
1096 /// structures for TSS keys.
1097 extern ACE_Export ACE_thread_key_t NULL_key;
1098 //@}
1101 * Call TSS destructors for the current thread. If the current
1102 * thread is the main thread, then the argument must be 1.
1103 * For private use of ACE_Object_Manager and ACE_Thread_Adapter only.
1105 extern ACE_Export
1106 void cleanup_tss (const u_int main_thread);
1108 //@{ @name A set of wrappers for condition variables.
1109 ACE_NAMESPACE_INLINE_FUNCTION
1110 int condattr_init (ACE_condattr_t &attributes,
1111 int type = ACE_DEFAULT_SYNCH_TYPE);
1113 ACE_NAMESPACE_INLINE_FUNCTION
1114 int condattr_synctype (ACE_condattr_t &attributes, int& type);
1116 ACE_NAMESPACE_INLINE_FUNCTION
1117 int condattr_destroy (ACE_condattr_t &attributes);
1119 ACE_NAMESPACE_INLINE_FUNCTION
1120 int condattr_setclock(ACE_condattr_t &attributes,
1121 clockid_t clock_id);
1123 #if defined (ACE_LACKS_COND_T)
1124 extern ACE_Export
1125 #else
1126 ACE_NAMESPACE_INLINE_FUNCTION
1127 #endif /* ACE_LACKS_COND_T */
1128 int cond_broadcast (ACE_cond_t *cv);
1130 #if defined (ACE_LACKS_COND_T)
1131 extern ACE_Export
1132 #else
1133 ACE_NAMESPACE_INLINE_FUNCTION
1134 #endif /* ACE_LACKS_COND_T */
1135 int cond_destroy (ACE_cond_t *cv);
1137 extern ACE_Export
1138 int cond_init (ACE_cond_t *cv,
1139 short type = ACE_DEFAULT_SYNCH_TYPE,
1140 const char *name = 0,
1141 void *arg = 0);
1143 #if defined (ACE_LACKS_COND_T)
1144 extern ACE_Export
1145 #else
1146 ACE_NAMESPACE_INLINE_FUNCTION
1147 #endif /* ACE_LACKS_COND_T */
1148 int cond_init (ACE_cond_t *cv,
1149 ACE_condattr_t &attributes,
1150 const char *name = 0,
1151 void *arg = 0);
1153 # if defined (ACE_HAS_WCHAR)
1154 # if defined (ACE_LACKS_COND_T)
1155 extern ACE_Export
1156 # else
1157 ACE_NAMESPACE_INLINE_FUNCTION
1158 # endif /* ACE_LACKS_COND_T */
1159 int cond_init (ACE_cond_t *cv,
1160 short type,
1161 const wchar_t *name,
1162 void *arg = 0);
1164 # if defined (ACE_LACKS_COND_T)
1165 extern ACE_Export
1166 # else
1167 ACE_NAMESPACE_INLINE_FUNCTION
1168 # endif /* ACE_LACKS_COND_T */
1169 int cond_init (ACE_cond_t *cv,
1170 ACE_condattr_t &attributes,
1171 const wchar_t *name,
1172 void *arg = 0);
1173 # endif /* ACE_HAS_WCHAR */
1175 #if defined (ACE_LACKS_COND_T)
1176 extern ACE_Export
1177 #else
1178 ACE_NAMESPACE_INLINE_FUNCTION
1179 #endif /* ACE_LACKS_COND_T */
1180 int cond_signal (ACE_cond_t *cv);
1182 #if defined (ACE_LACKS_COND_T)
1183 extern ACE_Export
1184 #else
1185 ACE_NAMESPACE_INLINE_FUNCTION
1186 #endif /* ACE_LACKS_COND_T */
1187 int cond_timedwait (ACE_cond_t *cv,
1188 ACE_mutex_t *m,
1189 ACE_Time_Value *timeout);
1191 #if defined (ACE_LACKS_COND_T)
1192 extern ACE_Export
1193 #else
1194 ACE_NAMESPACE_INLINE_FUNCTION
1195 #endif /* ACE_LACKS_COND_T */
1196 int cond_wait (ACE_cond_t *cv,
1197 ACE_mutex_t *m);
1199 # if defined (ACE_WIN32) && defined (ACE_HAS_WTHREADS)
1200 extern ACE_Export
1201 int cond_timedwait (ACE_cond_t *cv,
1202 ACE_thread_mutex_t *m,
1203 ACE_Time_Value *timeout);
1205 extern ACE_Export
1206 int cond_wait (ACE_cond_t *cv,
1207 ACE_thread_mutex_t *m);
1208 # endif /* ACE_WIN32 && ACE_HAS_WTHREADS */
1210 //@{ @name A set of wrappers for auto-reset and manual events.
1212 extern ACE_Export
1213 int event_destroy (ACE_event_t *event);
1215 ACE_NAMESPACE_INLINE_FUNCTION
1216 int event_init (ACE_event_t *event,
1217 int manual_reset = 0,
1218 int initial_state = 0,
1219 int type = ACE_DEFAULT_SYNCH_TYPE,
1220 const char *name = 0,
1221 void *arg = 0,
1222 LPSECURITY_ATTRIBUTES sa = 0);
1224 extern ACE_Export
1225 int event_init (ACE_event_t *event,
1226 int type,
1227 ACE_condattr_t *attributes,
1228 int manual_reset = 0,
1229 int initial_state = 0,
1230 const char *name = 0,
1231 void *arg = 0,
1232 LPSECURITY_ATTRIBUTES sa = 0);
1234 # if defined (ACE_HAS_WCHAR)
1235 ACE_NAMESPACE_INLINE_FUNCTION
1236 int event_init (ACE_event_t *event,
1237 int manual_reset,
1238 int initial_state,
1239 int type,
1240 const wchar_t *name,
1241 void *arg = 0,
1242 LPSECURITY_ATTRIBUTES sa = 0);
1244 ACE_NAMESPACE_INLINE_FUNCTION
1245 int event_init (ACE_event_t *event,
1246 int type,
1247 ACE_condattr_t *attributes,
1248 int manual_reset,
1249 int initial_state,
1250 const wchar_t *name,
1251 void *arg = 0,
1252 LPSECURITY_ATTRIBUTES sa = 0);
1253 # endif /* ACE_HAS_WCHAR */
1255 extern ACE_Export
1256 int event_pulse (ACE_event_t *event);
1258 extern ACE_Export
1259 int event_reset (ACE_event_t *event);
1261 extern ACE_Export
1262 int event_signal (ACE_event_t *event);
1264 extern ACE_Export
1265 int event_timedwait (ACE_event_t *event,
1266 ACE_Time_Value *timeout,
1267 int use_absolute_time = 1);
1269 ACE_NAMESPACE_INLINE_FUNCTION
1270 int event_wait (ACE_event_t *event);
1272 //@}
1274 extern ACE_Export
1275 int lwp_getparams (ACE_Sched_Params &);
1277 extern ACE_Export
1278 int lwp_setparams (const ACE_Sched_Params &);
1281 //@{ @name A set of wrappers for mutex locks.
1283 extern ACE_Export
1284 int mutex_destroy (ACE_mutex_t *m);
1286 extern ACE_Export
1287 int mutex_init (ACE_mutex_t *m,
1288 int lock_scope = ACE_DEFAULT_SYNCH_TYPE,
1289 const char *name = 0,
1290 ACE_mutexattr_t *arg = 0,
1291 LPSECURITY_ATTRIBUTES sa = 0,
1292 int lock_type = 0);
1294 #if defined (ACE_HAS_WCHAR)
1295 extern ACE_Export
1296 int mutex_init (ACE_mutex_t *m,
1297 int lock_scope,
1298 const wchar_t *name,
1299 ACE_mutexattr_t *arg = 0,
1300 LPSECURITY_ATTRIBUTES sa = 0,
1301 int lock_type = 0);
1302 #endif /* ACE_HAS_WCHAR */
1304 /// Win32 note: Abandoned mutexes are not treated differently. 0 is
1305 /// returned since the calling thread does get the ownership.
1306 extern ACE_Export
1307 int mutex_lock (ACE_mutex_t *m);
1309 /// This method is only implemented for Win32. For abandoned
1310 /// mutexes, @a abandoned is set to 1 and 0 is returned.
1311 extern ACE_Export
1312 int mutex_lock (ACE_mutex_t *m,
1313 int &abandoned);
1316 * This method attempts to acquire a lock, but gives up if the lock
1317 * has not been acquired by the given time. If the lock is not
1318 * acquired within the given amount of time, then this method
1319 * returns -1 with an @c ETIME errno on platforms that actually
1320 * support timed mutexes. The timeout should be an absolute time.
1321 * Note that the mutex should not be a recursive one, i.e., it
1322 * should only be a standard mutex or an error checking mutex since
1323 * some implementations of this method don't support recursive
1324 * mutexes. If you want to use a recursive mutex see the methods
1325 * below.
1327 extern ACE_Export
1328 int mutex_lock (ACE_mutex_t *m,
1329 const ACE_Time_Value &timeout);
1332 * If @a timeout == 0, calls <ACE_OS::mutex_lock(m)>. Otherwise,
1333 * this method attempts to acquire a lock, but gives up if the lock
1334 * has not been acquired by the given time, in which case it returns
1335 * -1 with an @c ETIME errno on platforms that actually support timed
1336 * mutexes. The timeout should be an absolute time. Note that the
1337 * mutex should not be a recursive one, i.e., it should only be a
1338 * standard mutex or an error checking mutex since some
1339 * implementations of this method don't support recursive mutexes.
1340 * If you want to use a recursive mutex see the methods below.
1342 ACE_NAMESPACE_INLINE_FUNCTION
1343 int mutex_lock (ACE_mutex_t *m,
1344 const ACE_Time_Value *timeout);
1346 /// Handle asynchronous thread cancellation cleanup.
1347 extern ACE_Export
1348 void mutex_lock_cleanup (void *mutex);
1350 /// Win32 note: Abandoned mutexes are not treated differently. 0 is
1351 /// returned since the calling thread does get the ownership.
1352 extern ACE_Export
1353 int mutex_trylock (ACE_mutex_t *m);
1355 /// This method is only implemented for Win32. For abandoned
1356 /// mutexes, @a abandoned is set to 1 and 0 is returned.
1357 extern ACE_Export
1358 int mutex_trylock (ACE_mutex_t *m,
1359 int &abandoned);
1361 extern ACE_Export
1362 int mutex_unlock (ACE_mutex_t *m);
1364 //@}
1366 /// Low-level interface to @c priocntl(2).
1368 * Can't call the following priocntl, because that's a macro on
1369 * Solaris.
1371 ACE_NAMESPACE_INLINE_FUNCTION
1372 long priority_control (ACE_idtype_t, ACE_id_t, int, void *);
1374 //@{ @name A set of wrappers for recursive mutex locks.
1376 // These two methods are primarily in support of
1377 // ACE_Condition<ACE_Recursive_Thread_Mutex> and should probably not
1378 // be called outside that context.
1379 ACE_NAMESPACE_INLINE_FUNCTION
1380 int recursive_mutex_cond_unlock (ACE_recursive_thread_mutex_t *m,
1381 ACE_recursive_mutex_state &state);
1383 ACE_NAMESPACE_INLINE_FUNCTION
1384 void recursive_mutex_cond_relock (ACE_recursive_thread_mutex_t *m,
1385 ACE_recursive_mutex_state &state);
1387 ACE_NAMESPACE_INLINE_FUNCTION
1388 int recursive_mutex_destroy (ACE_recursive_thread_mutex_t *m);
1390 ACE_NAMESPACE_INLINE_FUNCTION
1391 int recursive_mutex_init (ACE_recursive_thread_mutex_t *m,
1392 const ACE_TCHAR *name = 0,
1393 ACE_mutexattr_t *arg = 0,
1394 LPSECURITY_ATTRIBUTES sa = 0);
1396 ACE_NAMESPACE_INLINE_FUNCTION
1397 int recursive_mutex_lock (ACE_recursive_thread_mutex_t *m);
1399 ACE_NAMESPACE_INLINE_FUNCTION
1400 int recursive_mutex_lock (ACE_recursive_thread_mutex_t *m,
1401 const ACE_Time_Value &timeout);
1403 ACE_NAMESPACE_INLINE_FUNCTION
1404 int recursive_mutex_lock (ACE_recursive_thread_mutex_t *m,
1405 const ACE_Time_Value *timeout);
1407 ACE_NAMESPACE_INLINE_FUNCTION
1408 int recursive_mutex_trylock (ACE_recursive_thread_mutex_t *m);
1410 ACE_NAMESPACE_INLINE_FUNCTION
1411 int recursive_mutex_unlock (ACE_recursive_thread_mutex_t *m);
1413 //@}
1416 //@{ @name A set of wrappers for readers/writer locks.
1418 ACE_NAMESPACE_INLINE_FUNCTION
1419 int rw_rdlock (ACE_rwlock_t *rw);
1421 ACE_NAMESPACE_INLINE_FUNCTION
1422 int rw_tryrdlock (ACE_rwlock_t *rw);
1424 ACE_NAMESPACE_INLINE_FUNCTION
1425 int rw_trywrlock (ACE_rwlock_t *rw);
1427 ACE_NAMESPACE_INLINE_FUNCTION
1428 int rw_trywrlock_upgrade (ACE_rwlock_t *rw);
1430 ACE_NAMESPACE_INLINE_FUNCTION
1431 int rw_unlock (ACE_rwlock_t *rw);
1433 ACE_NAMESPACE_INLINE_FUNCTION
1434 int rw_wrlock (ACE_rwlock_t *rw);
1436 ACE_NAMESPACE_INLINE_FUNCTION
1437 int rwlock_destroy (ACE_rwlock_t *rw);
1439 extern ACE_Export
1440 int rwlock_init (ACE_rwlock_t *rw,
1441 int type = ACE_DEFAULT_SYNCH_TYPE,
1442 const ACE_TCHAR *name = 0,
1443 void *arg = 0);
1445 //@}
1447 //@{ @name Thread scheduler interface.
1448 /// Set scheduling parameters. An id of ACE_SELF indicates, e.g.,
1449 /// set the parameters on the calling thread.
1450 extern ACE_Export
1451 int sched_params (const ACE_Sched_Params &, ACE_id_t id = ACE_SELF);
1452 //@}
1454 /// Find the scheduling class ID that corresponds to the class name.
1455 extern ACE_Export
1456 int scheduling_class (const char *class_name, ACE_id_t &);
1458 //@{ @name A set of wrappers for semaphores.
1460 ACE_NAMESPACE_INLINE_FUNCTION
1461 int sema_destroy (ACE_sema_t *s);
1463 ACE_NAMESPACE_INLINE_FUNCTION
1464 int sema_init (ACE_sema_t *s,
1465 u_int count,
1466 int type = ACE_DEFAULT_SYNCH_TYPE,
1467 const char *name = 0,
1468 void *arg = 0,
1469 int max = 0x7fffffff,
1470 LPSECURITY_ATTRIBUTES sa = 0);
1472 ACE_NAMESPACE_INLINE_FUNCTION
1473 int sema_init (ACE_sema_t *s,
1474 u_int count,
1475 int type,
1476 ACE_condattr_t *attributes,
1477 const char *name = 0,
1478 void *arg = 0,
1479 int max = 0x7fffffff,
1480 LPSECURITY_ATTRIBUTES sa = 0);
1482 # if defined (ACE_HAS_WCHAR)
1483 ACE_NAMESPACE_INLINE_FUNCTION
1484 int sema_init (ACE_sema_t *s,
1485 u_int count,
1486 int type,
1487 const wchar_t *name,
1488 void *arg = 0,
1489 int max = 0x7fffffff,
1490 LPSECURITY_ATTRIBUTES sa = 0);
1492 ACE_NAMESPACE_INLINE_FUNCTION
1493 int sema_init (ACE_sema_t *s,
1494 u_int count,
1495 int type,
1496 ACE_condattr_t *attributes,
1497 const wchar_t *name,
1498 void *arg = 0,
1499 int max = 0x7fffffff,
1500 LPSECURITY_ATTRIBUTES sa = 0);
1501 # endif /* ACE_HAS_WCHAR */
1503 ACE_NAMESPACE_INLINE_FUNCTION
1504 void sema_avoid_unlink (ACE_sema_t *s, bool avoid_unlink);
1506 ACE_NAMESPACE_INLINE_FUNCTION
1507 int sema_unlink (const char *name);
1509 ACE_NAMESPACE_INLINE_FUNCTION
1510 int sema_post (ACE_sema_t *s);
1512 ACE_NAMESPACE_INLINE_FUNCTION
1513 int sema_post (ACE_sema_t *s,
1514 u_int release_count);
1516 ACE_NAMESPACE_INLINE_FUNCTION
1517 int sema_trywait (ACE_sema_t *s);
1519 ACE_NAMESPACE_INLINE_FUNCTION
1520 int sema_wait (ACE_sema_t *s);
1522 ACE_NAMESPACE_INLINE_FUNCTION
1523 int sema_wait (ACE_sema_t *s,
1524 ACE_Time_Value &tv);
1526 ACE_NAMESPACE_INLINE_FUNCTION
1527 int sema_wait (ACE_sema_t *s,
1528 ACE_Time_Value *tv);
1529 //@}
1531 //@{ @name A set of wrappers for System V semaphores.
1532 ACE_NAMESPACE_INLINE_FUNCTION
1533 int semctl (int int_id,
1534 int semnum,
1535 int cmd,
1536 semun);
1538 ACE_NAMESPACE_INLINE_FUNCTION
1539 int semget (key_t key,
1540 int nsems,
1541 int flags);
1543 ACE_NAMESPACE_INLINE_FUNCTION
1544 int semop (int int_id,
1545 struct sembuf *sops,
1546 size_t nsops);
1547 //@}
1549 /// Friendly interface to @c priocntl(2).
1550 extern ACE_Export
1551 int set_scheduling_params (const ACE_Sched_Params &,
1552 ACE_id_t id = ACE_SELF);
1554 ACE_NAMESPACE_INLINE_FUNCTION
1555 int sigtimedwait (const sigset_t *set,
1556 siginfo_t *info,
1557 const ACE_Time_Value *timeout);
1559 ACE_NAMESPACE_INLINE_FUNCTION
1560 int sigwait (sigset_t *set,
1561 int *sig = 0);
1563 ACE_NAMESPACE_INLINE_FUNCTION
1564 int sigwaitinfo (const sigset_t *set,
1565 siginfo_t *info);
1567 ACE_NAMESPACE_INLINE_FUNCTION
1568 int thr_cancel (ACE_thread_t t_id);
1570 ACE_NAMESPACE_INLINE_FUNCTION
1571 int thr_cmp (ACE_hthread_t t1,
1572 ACE_hthread_t t2);
1574 // These are non-portable since they use ACE_thread_t and
1575 // ACE_hthread_t and will go away in a future release.
1576 ACE_NAMESPACE_INLINE_FUNCTION
1577 int thr_continue (ACE_hthread_t target_thread);
1580 * Creates a new thread having @a flags attributes and running @a func
1581 * with @a args (if @a thread_adapter is non-0 then @a func and @a args
1582 * are ignored and are obtained from @a thread_adapter). @a thr_id
1583 * and @a t_handle are set to the thread's ID and handle (?),
1584 * respectively. The thread runs at @a priority priority (see
1585 * below).
1587 * The @a flags are a bitwise-OR of the following:
1588 * = BEGIN<INDENT>
1589 * THR_CANCEL_DISABLE, THR_CANCEL_ENABLE, THR_CANCEL_DEFERRED,
1590 * THR_CANCEL_ASYNCHRONOUS, THR_BOUND, THR_NEW_LWP, THR_DETACHED,
1591 * THR_SUSPENDED, THR_DAEMON, THR_JOINABLE, THR_SCHED_FIFO,
1592 * THR_SCHED_RR, THR_SCHED_DEFAULT, THR_EXPLICIT_SCHED,
1593 * THR_SCOPE_SYSTEM, THR_SCOPE_PROCESS
1594 * = END<INDENT>
1596 * By default, or if @a priority is set to
1597 * ACE_DEFAULT_THREAD_PRIORITY, an "appropriate" priority value for
1598 * the given scheduling policy (specified in @a flags, e.g.,
1599 * @c THR_SCHED_DEFAULT) is used. This value is calculated
1600 * dynamically, and is the median value between the minimum and
1601 * maximum priority values for the given policy. If an explicit
1602 * value is given, it is used. Note that actual priority values are
1603 * EXTREMEMLY implementation-dependent, and are probably best
1604 * avoided.
1606 * Note that @a thread_adapter is always deleted by @c thr_create,
1607 * therefore it must be allocated with global operator new.
1609 * At the moment for @a thr_name a valid string is passed then this
1610 * will be used on VxWorks to set the task name. If we just pass a pointer
1611 * the name of the task is returned
1613 extern ACE_Export
1614 int thr_create (ACE_THR_FUNC func,
1615 void *args,
1616 long flags,
1617 ACE_thread_t *thr_id,
1618 ACE_hthread_t *t_handle = 0,
1619 long priority = ACE_DEFAULT_THREAD_PRIORITY,
1620 void *stack = 0,
1621 size_t stacksize = ACE_DEFAULT_THREAD_STACKSIZE,
1622 ACE_Base_Thread_Adapter *thread_adapter = 0,
1623 const char** thr_name = 0);
1625 ACE_NAMESPACE_INLINE_FUNCTION
1626 int thr_equal (ACE_thread_t t1, ACE_thread_t t2);
1628 extern ACE_Export
1629 void thr_exit (ACE_THR_FUNC_RETURN status = 0);
1631 ACE_NAMESPACE_INLINE_FUNCTION
1632 int thr_getconcurrency (void);
1634 ACE_NAMESPACE_INLINE_FUNCTION
1635 int thr_getprio (ACE_hthread_t id,
1636 int &priority);
1638 ACE_NAMESPACE_INLINE_FUNCTION
1639 int thr_getprio (ACE_hthread_t id,
1640 int &priority,
1641 int &policy);
1643 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
1644 ACE_NAMESPACE_INLINE_FUNCTION
1645 /// for internal use only. Applications should call thr_getspecific
1646 int thr_getspecific_native (ACE_OS_thread_key_t key, void **data);
1647 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
1649 ACE_NAMESPACE_INLINE_FUNCTION
1650 int thr_getspecific (ACE_thread_key_t key, void **data);
1652 #if defined (ACE_HAS_VXTHREADS)
1653 extern ACE_Export
1654 #else
1655 ACE_NAMESPACE_INLINE_FUNCTION
1656 #endif /* ACE_HAS_VXTHREADS */
1657 int thr_join (ACE_hthread_t waiter_id, ACE_THR_FUNC_RETURN *status);
1659 #if defined (ACE_HAS_VXTHREADS)
1660 extern ACE_Export
1661 #else
1662 ACE_NAMESPACE_INLINE_FUNCTION
1663 #endif /* ACE_HAS_VXTHREADS */
1664 int thr_join (ACE_thread_t waiter_id,
1665 ACE_thread_t *thr_id,
1666 ACE_THR_FUNC_RETURN *status);
1669 * Get the thread affinity
1671 * @param thr_id For NPTL-threads, when ACE_HAS_PTHREAD_SETAFFINITY_NP
1672 * defined, this is the thread-id. For linux-threads, when
1673 * ACE_HAS_SCHED_SETAFFINITY defined, it expects a process-id. Since for
1674 * linux-threads a thread is seen as a process, it does the job.
1675 * @param cpu_set_size The size of the cpu_mask, in bytes.
1676 * @param cpu_mask Is a bitmask of CPUs to bind to, e.g value 1 binds the
1677 * thread to the "CPU 0", etc
1679 extern ACE_Export
1680 int thr_get_affinity (ACE_hthread_t thr_id,
1681 size_t cpu_set_size,
1682 cpu_set_t * cpu_mask);
1686 * Set the thread affinity
1688 * @param thr_id For NPTL-threads, when ACE_HAS_PTHREAD_SETAFFINITY_NP
1689 * defined, this is the thread-id. For linux-threads, when
1690 * ACE_HAS_SCHED_SETAFFINITY defined, it expects a process-id. Since for
1691 * linux-threads a thread is seen as a process, it does the job.
1692 * @param cpu_set_size The size of the cpu_mask, in bytes.
1693 * @param cpu_mask Is a bitmask of CPUs to bind to, e.g value 1 binds the
1694 * thread to the "CPU 0", etc
1696 extern ACE_Export
1697 int thr_set_affinity (ACE_hthread_t thr_id,
1698 size_t cpu_set_size,
1699 const cpu_set_t * cpu_mask);
1701 extern ACE_Export
1702 int thr_key_detach (ACE_thread_key_t key);
1704 extern ACE_Export
1705 int thr_key_used (ACE_thread_key_t key);
1707 # if defined (ACE_HAS_THR_C_DEST)
1708 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
1709 /// @internal Applications should call thr_keycreate
1710 extern ACE_Export
1711 int thr_keycreate_native (ACE_OS_thread_key_t *key, ACE_THR_C_DEST);
1712 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
1714 extern ACE_Export
1715 int thr_keycreate (ACE_thread_key_t *key, ACE_THR_C_DEST);
1717 # else
1718 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
1719 /// @internal Applications should call thr_keycreate instead
1720 extern ACE_Export
1721 int thr_keycreate_native (ACE_OS_thread_key_t *key,
1722 ACE_THR_DEST);
1723 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
1725 extern ACE_Export
1726 int thr_keycreate (ACE_thread_key_t *key, ACE_THR_DEST);
1728 # endif /* ACE_HAS_THR_C_DEST */
1730 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
1731 /// @internal Applications should call thr_keyfree instead
1732 extern ACE_Export
1733 int thr_keyfree_native (ACE_OS_thread_key_t key);
1734 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
1736 extern ACE_Export
1737 int thr_keyfree (ACE_thread_key_t key);
1739 ACE_NAMESPACE_INLINE_FUNCTION
1740 int thr_kill (ACE_thread_t thr_id, int signum);
1742 ACE_NAMESPACE_INLINE_FUNCTION
1743 size_t thr_min_stack (void);
1745 ACE_NAMESPACE_INLINE_FUNCTION
1746 ACE_thread_t thr_self (void);
1748 ACE_NAMESPACE_INLINE_FUNCTION
1749 void thr_self (ACE_hthread_t &);
1751 ACE_NAMESPACE_INLINE_FUNCTION
1752 const char* thr_name (void);
1754 /// Stores a string version of the current thread id into buffer and
1755 /// returns the size of this thread id in bytes.
1756 ACE_NAMESPACE_INLINE_FUNCTION
1757 ssize_t thr_id (char buffer[], size_t buffer_length);
1760 * For systems that support it (Only Linux as of writing), this is a wrapper
1761 * for pid_t gettid().
1763 * It returns the system-wide thread id (TID) for the current thread. These
1764 * are similar to PIDs and, for x86 Linux at least, are much shorter than
1765 * what is returned from thr_self(), which is an address.
1767 * For older Linux (pre 2.4.11) and other systems that don't have gettid(),
1768 * this uses ACE_NOTSUP_RETURN (-1).
1770 pid_t thr_gettid ();
1773 * Puts the string representation of pid_t thr_gettid() into the buffer and
1774 * returns number of bytes added.
1776 ACE_NAMESPACE_INLINE_FUNCTION
1777 ssize_t thr_gettid (char buffer[], size_t buffer_length);
1779 /// State is THR_CANCEL_ENABLE or THR_CANCEL_DISABLE
1780 ACE_NAMESPACE_INLINE_FUNCTION
1781 int thr_setcancelstate (int new_state, int *old_state);
1783 /// Type is THR_CANCEL_DEFERRED or THR_CANCEL_ASYNCHRONOUS
1784 ACE_NAMESPACE_INLINE_FUNCTION
1785 int thr_setcanceltype (int new_type, int *old_type);
1787 ACE_NAMESPACE_INLINE_FUNCTION
1788 int thr_setconcurrency (int hint);
1790 ACE_NAMESPACE_INLINE_FUNCTION
1791 int thr_setprio (ACE_hthread_t ht_id, int priority, int policy = -1);
1793 extern ACE_Export
1794 int thr_setprio (const ACE_Sched_Priority prio);
1796 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
1797 /// @internal Applications should call thr_setspecific
1798 extern ACE_Export
1799 int thr_setspecific_native (ACE_OS_thread_key_t key, void *data);
1800 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
1802 extern ACE_Export
1803 int thr_setspecific (ACE_thread_key_t key, void *data);
1805 ACE_NAMESPACE_INLINE_FUNCTION
1806 int thr_sigsetmask (int how, const sigset_t *nsm, sigset_t *osm);
1808 ACE_NAMESPACE_INLINE_FUNCTION
1809 int thr_suspend (ACE_hthread_t target_thread);
1811 ACE_NAMESPACE_INLINE_FUNCTION
1812 void thr_testcancel (void);
1814 ACE_NAMESPACE_INLINE_FUNCTION
1815 void thr_yield (void);
1817 //@{ @name A set of wrappers for mutex locks that only work within a single process.
1819 ACE_NAMESPACE_INLINE_FUNCTION
1820 int thread_mutex_destroy (ACE_thread_mutex_t *m);
1822 ACE_NAMESPACE_INLINE_FUNCTION
1823 int thread_mutex_init (ACE_thread_mutex_t *m,
1824 int lock_type = 0,
1825 const char *name = 0,
1826 ACE_mutexattr_t *arg = 0);
1828 #if defined (ACE_HAS_WCHAR)
1829 ACE_NAMESPACE_INLINE_FUNCTION
1830 int thread_mutex_init (ACE_thread_mutex_t *m,
1831 int lock_type,
1832 const wchar_t *name,
1833 ACE_mutexattr_t *arg = 0);
1834 #endif /* ACE_HAS_WCHAR */
1836 ACE_NAMESPACE_INLINE_FUNCTION
1837 int thread_mutex_lock (ACE_thread_mutex_t *m);
1839 ACE_NAMESPACE_INLINE_FUNCTION
1840 int thread_mutex_lock (ACE_thread_mutex_t *m,
1841 const ACE_Time_Value &timeout);
1843 ACE_NAMESPACE_INLINE_FUNCTION
1844 int thread_mutex_lock (ACE_thread_mutex_t *m,
1845 const ACE_Time_Value *timeout);
1847 ACE_NAMESPACE_INLINE_FUNCTION
1848 int thread_mutex_trylock (ACE_thread_mutex_t *m);
1850 ACE_NAMESPACE_INLINE_FUNCTION
1851 int thread_mutex_unlock (ACE_thread_mutex_t *m);
1853 //@}
1856 * This method uses process id and object pointer to come up with a
1857 * machine wide unique name. The process ID will provide uniqueness
1858 * between processes on the same machine. The "this" pointer of the
1859 * @a object will provide uniqueness between other "live" objects in
1860 * the same process. The uniqueness of this name is therefore only
1861 * valid for the life of @a object.
1863 extern ACE_Export
1864 void unique_name (const void *object,
1865 char *name,
1866 size_t length);
1867 #if defined (ACE_USES_WCHAR)
1868 extern ACE_Export
1869 void unique_name (const void *object,
1870 wchar_t *name,
1871 size_t length);
1872 #endif /* ACE_USES_WCHAR */
1873 } /* namespace ACE_OS */
1875 #if !defined (ACE_WIN32)
1877 /// Implementation details of Event emulation on Unix, may be in shared memory
1878 struct ACE_eventdata_t
1880 /// Protect critical section.
1881 ACE_mutex_t lock_;
1883 /// Keeps track of waiters.
1884 ACE_cond_t condition_;
1886 /// Object type.
1887 int type_;
1889 /// Specifies if this is an auto- or manual-reset event.
1890 int manual_reset_;
1892 /// "True" if signaled.
1893 int is_signaled_;
1895 /// Special bool for auto_events alone
1897 * The semantics of auto events forces us to introduce this extra
1898 * variable to ensure that the thread is not woken up
1899 * spuriously. Please see event_timedwait () to see
1900 * how this is used for auto_events.
1901 * @todo This is a hack that needs revisiting after x.4
1903 bool auto_event_signaled_;
1905 /// Number of waiting threads.
1906 unsigned long waiting_threads_;
1908 /// Signal count
1909 unsigned long signal_count_;
1911 ACE_ALLOC_HOOK_DECLARE;
1914 # if !defined ACE_USES_FIFO_SEM \
1915 && !(defined ACE_HAS_POSIX_SEM && defined ACE_HAS_POSIX_SEM_TIMEOUT \
1916 && !defined ACE_LACKS_NAMED_POSIX_SEM)
1917 # define ACE_EVENT_NO_FIFO_SEM
1918 # endif
1920 # if (defined ACE_HAS_PTHREADS && defined _POSIX_THREAD_PROCESS_SHARED \
1921 && !defined ACE_LACKS_MUTEXATTR_PSHARED) || defined ACE_EVENT_NO_FIFO_SEM
1922 # define ACE_EVENT_USE_MUTEX_PSHARED 1
1923 # else
1924 # define ACE_EVENT_USE_MUTEX_PSHARED 0
1925 # endif
1927 # if (defined ACE_HAS_PTHREADS && defined _POSIX_THREAD_PROCESS_SHARED \
1928 && !defined ACE_LACKS_CONDATTR_PSHARED \
1929 && !defined ACE_LACKS_MUTEXATTR_PSHARED) || defined ACE_EVENT_NO_FIFO_SEM
1930 # define ACE_EVENT_USE_COND_PSHARED 1
1931 # else
1932 # define ACE_EVENT_USE_COND_PSHARED 0
1933 # endif
1936 * @class ACE_event_t
1938 * @brief Wrapper for NT events on UNIX.
1940 class ACE_Export ACE_event_t
1942 friend int ACE_OS::event_init (ACE_event_t *, int, int, int, const char *,
1943 void *, int);
1944 friend int ACE_OS::event_init (ACE_event_t *, int, ACE_condattr_t *, int,
1945 int, const char *, void *, int);
1946 friend int ACE_OS::event_destroy (ACE_event_t *);
1947 friend int ACE_OS::event_wait (ACE_event_t *);
1948 friend int ACE_OS::event_timedwait (ACE_event_t *, ACE_Time_Value *, int);
1949 friend int ACE_OS::event_signal (ACE_event_t *);
1950 friend int ACE_OS::event_pulse (ACE_event_t *);
1951 friend int ACE_OS::event_reset (ACE_event_t *);
1953 public:
1954 /// Constructor initializing all pointer fields to null
1955 ACE_event_t (void);
1957 private:
1958 /// Lock the internal mutex/semaphore
1959 int lock (void);
1961 /// Unlock the internal mutex/semaphore
1962 int unlock (void);
1964 /// Use the internal semaphore or condition variable to unblock one thread
1965 int wake_one (void);
1967 /// Event name if process shared.
1968 char *name_;
1970 /// Event data
1971 ACE_eventdata_t *eventdata_;
1973 # if !ACE_EVENT_USE_COND_PSHARED
1974 /// Keeps track of waiters.
1975 ACE_sema_t semaphore_;
1976 # endif
1978 # if !ACE_EVENT_USE_MUTEX_PSHARED
1979 /// Protect critical section.
1980 ACE_sema_t lock_;
1981 # endif
1984 #endif /* ACE_WIN32 */
1986 ACE_END_VERSIONED_NAMESPACE_DECL
1988 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
1990 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1993 * @class ACE_OS_Thread_Mutex_Guard
1995 * This data structure is meant to be used within an ACE_OS
1996 * function. It performs automatic aquisition and release of
1997 * an ACE_thread_mutex_t.
1999 * If an object of this class is instantiated before ACE_Object_Manager is
2000 * initialized, it will not do anything. This is because this class is
2001 * used only with the ACE_OS_GUARD macro which is passing a reference to
2002 * one of the preallocated Object Manager locks. If the object manager
2003 * hasn't been initialized yet, the lock reference is bogus. This is an
2004 * acceptable tradeoff since in cases where the lock reference is bogus,
2005 * there isn't multithreaded access. Please see detailed comments in
2006 * Object_Manager.h for further information.
2008 * For internal use only by ACE_OS.
2010 class ACE_OS_Thread_Mutex_Guard
2012 public:
2013 /// Implicitly and automatically acquire the lock.
2014 ACE_OS_Thread_Mutex_Guard (ACE_thread_mutex_t &m);
2016 /// Implicitly release the lock.
2017 ~ACE_OS_Thread_Mutex_Guard (void);
2019 /// Explicitly acquire the lock.
2020 int acquire (void);
2022 /// Explicitly release the lock.
2023 int release (void);
2025 protected:
2026 /// Reference to the mutex.
2027 ACE_thread_mutex_t &lock_;
2029 /// Keeps track of whether we acquired the lock or failed.
2030 int owner_;
2032 // = Prevent assignment and initialization.
2033 ACE_OS_Thread_Mutex_Guard &operator= (const ACE_OS_Thread_Mutex_Guard &);
2034 ACE_OS_Thread_Mutex_Guard (const ACE_OS_Thread_Mutex_Guard &);
2038 * @class ACE_OS_Recursive_Thread_Mutex_Guard
2040 * @brief For internal use only by ACE_OS.
2042 * This data structure is meant to be used within an ACE_OS
2043 * function. It performs automatic aquisition and release of
2044 * an ACE_recursive_thread_mutex_t.
2046 * If an object of this class is instantiated before ACE_Object_Manager is
2047 * initialized, it will not do anything. This is because this class is
2048 * used only with the ACE_TSS_GUARD macro which is passing a reference to
2049 * one of the preallocated Object Manager locks. If the object manager
2050 * hasn't been initialized yet, the lock reference is bogus. This is an
2051 * acceptable tradeoff since in cases where the lock reference is bogus,
2052 * there isn't multithreaded access. Please see detailed comments in
2053 * Object_Manager.h for further information.
2055 class ACE_OS_Recursive_Thread_Mutex_Guard
2057 public:
2058 /// Implicitly and automatically acquire the lock.
2059 ACE_OS_Recursive_Thread_Mutex_Guard (ACE_recursive_thread_mutex_t &m);
2061 /// Implicitly release the lock.
2062 ~ACE_OS_Recursive_Thread_Mutex_Guard (void);
2064 /// Explicitly acquire the lock.
2065 int acquire (void);
2067 /// Explicitly release the lock.
2068 int release (void);
2070 protected:
2071 /// Reference to the mutex.
2072 ACE_recursive_thread_mutex_t &lock_;
2074 /// Keeps track of whether we acquired the lock or failed.
2075 int owner_;
2077 // = Prevent assignment and initialization.
2078 ACE_OS_Recursive_Thread_Mutex_Guard &operator= (
2079 const ACE_OS_Recursive_Thread_Mutex_Guard &);
2080 ACE_OS_Recursive_Thread_Mutex_Guard (
2081 const ACE_OS_Recursive_Thread_Mutex_Guard &);
2084 ACE_END_VERSIONED_NAMESPACE_DECL
2086 // used in time and unistd
2087 # define ACE_OS_GUARD \
2088 ACE_OS_Thread_Mutex_Guard ace_os_guard__ (*(ACE_thread_mutex_t *) \
2089 ACE_OS_Object_Manager::preallocated_object[ \
2090 ACE_OS_Object_Manager::ACE_OS_MONITOR_LOCK]);
2092 // used in Thread
2093 # define ACE_TSS_CLEANUP_GUARD \
2094 ACE_OS_Recursive_Thread_Mutex_Guard ace_tss_cleanup_guard__ (*(ACE_recursive_thread_mutex_t *) \
2095 ACE_OS_Object_Manager::preallocated_object[ \
2096 ACE_OS_Object_Manager::ACE_TSS_CLEANUP_LOCK]);
2098 // used in Thread
2099 # define ACE_TSS_BASE_GUARD \
2100 ACE_OS_Recursive_Thread_Mutex_Guard ace_tss_base_guard__ (*(ACE_recursive_thread_mutex_t *) \
2101 ACE_OS_Object_Manager::preallocated_object[ \
2102 ACE_OS_Object_Manager::ACE_TSS_BASE_LOCK]);
2104 #else /* ! ACE_MT_SAFE */
2105 # define ACE_OS_GUARD
2106 # define ACE_TSS_CLEANUP_GUARD
2107 # define ACE_TSS_BASE_GUARD
2108 #endif /* ! ACE_MT_SAFE */
2110 # if defined (ACE_HAS_INLINED_OSCALLS)
2111 # if defined (ACE_INLINE)
2112 # undef ACE_INLINE
2113 # endif /* ACE_INLINE */
2114 # define ACE_INLINE inline
2115 # include "ace/OS_NS_Thread.inl"
2116 # endif /* ACE_HAS_INLINED_OSCALLS */
2118 # include /**/ "ace/post.h"
2119 #endif /* ACE_OS_NS_THREAD_H */