OS_NS_Thread.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   OS_NS_Thread.h
00006  *
00007  *  $Id: OS_NS_Thread.h 81014 2008-03-19 11:41:31Z johnnyw $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  *  @author Jesper S. M|ller<stophph@diku.dk>
00011  *  @author and a cast of thousands...
00012  *
00013  *  Originally in OS.h.
00014  */
00015 //=============================================================================
00016 
00017 #ifndef ACE_OS_NS_THREAD_H
00018 # define ACE_OS_NS_THREAD_H
00019 
00020 # include /**/ "ace/pre.h"
00021 
00022 # include "ace/config-all.h"
00023 
00024 # if !defined (ACE_LACKS_PRAGMA_ONCE)
00025 #  pragma once
00026 # endif /* ACE_LACKS_PRAGMA_ONCE */
00027 
00028 # include "ace/Global_Macros.h"
00029 # include "ace/Basic_Types.h"
00030 # include "ace/Default_Constants.h"
00031 # include "ace/os_include/os_pthread.h"
00032 # include "ace/os_include/os_sched.h"
00033 # include "ace/Base_Thread_Adapter.h"
00034 # include "ace/os_include/sys/os_sem.h"
00035 # include "ace/os_include/os_semaphore.h"
00036 # include "ace/OS_Memory.h"
00037 # include "ace/OS_NS_signal.h"
00038 # include "ace/ACE_export.h"
00039 # include "ace/Object_Manager_Base.h"
00040 
00041 # if defined (ACE_EXPORT_MACRO)
00042 #   undef ACE_EXPORT_MACRO
00043 # endif
00044 # define ACE_EXPORT_MACRO ACE_Export
00045 
00046 # if defined (ACE_HAS_PRIOCNTL)
00047   // Need to #include thread.h before #defining THR_BOUND, etc.,
00048   // when building without threads on SunOS 5.x.
00049 #   if defined (sun)
00050 #     include /**/ <thread.h>
00051 #   endif /* sun */
00052 
00053   // Need to #include these before #defining USYNC_PROCESS on SunOS 5.x.
00054 #   include /**/ <sys/rtpriocntl.h>
00055 #   include /**/ <sys/tspriocntl.h>
00056 # endif /* ACE_HAS_PRIOCNTL */
00057 
00058 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00059 
00060 # if defined (ACE_WIN32)
00061 typedef DWORD ACE_thread_t;
00062 typedef HANDLE ACE_hthread_t;
00063 // Native TSS key type
00064 typedef DWORD ACE_OS_thread_key_t;
00065 // Application TSS key type (use this type except in TSS Emulation)
00066 #   if defined (ACE_HAS_TSS_EMULATION)
00067       typedef u_int ACE_thread_key_t;
00068 #   else  /* ! ACE_HAS_TSS_EMULATION */
00069       typedef ACE_OS_thread_key_t ACE_thread_key_t;
00070 #   endif /* ! ACE_HAS_TSS_EMULATION */
00071 # endif /* ACE_WIN32 */
00072 
00073 ACE_END_VERSIONED_NAMESPACE_DECL
00074 
00075 # if !defined (ACE_HAS_POSIX_SEM) && defined (ACE_USES_FIFO_SEM)
00076 
00077 extern "C" {
00078   typedef struct
00079   {
00080     char* name_;
00081     ACE_HANDLE fd_[2];
00082   } ACE_sema_t;
00083 }
00084 
00085 #endif /* !ACE_HAS_POSIX_SEM && ACE_USES_FIFO_SEM */
00086 
00087 # if defined (ACE_HAS_THREADS)
00088 
00089 #   if defined (ACE_HAS_STHREADS)
00090 #     include /**/ <synch.h>
00091 #     include /**/ <thread.h>
00092 #     define ACE_SCOPE_PROCESS P_PID
00093 #     define ACE_SCOPE_LWP P_LWPID
00094 #     define ACE_SCOPE_THREAD (ACE_SCOPE_LWP + 1)
00095 #   else
00096 #     define ACE_SCOPE_PROCESS 0
00097 #     define ACE_SCOPE_LWP 1
00098 #     define ACE_SCOPE_THREAD 2
00099 #   endif /* ACE_HAS_STHREADS */
00100 
00101 #   if !defined (ACE_HAS_PTHREADS)
00102 #     define ACE_SCHED_OTHER 0
00103 #     define ACE_SCHED_FIFO 1
00104 #     define ACE_SCHED_RR 2
00105 #   endif /* ! ACE_HAS_PTHREADS */
00106 
00107 #   if defined (ACE_HAS_PTHREADS)
00108 // moved to pthread.h
00109 #   elif defined (ACE_HAS_STHREADS)
00110 
00111 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00112 
00113 // Solaris threads, without PTHREADS.
00114 // Typedefs to help compatibility with Windows NT and Pthreads.
00115 typedef thread_t ACE_thread_t;
00116 // Native TSS key type (not for general use)
00117 typedef thread_key_t ACE_OS_thread_key_t;
00118 // Application TSS key type (use this type except in TSS Emulation)
00119 #   if defined (ACE_HAS_TSS_EMULATION)
00120       typedef u_int ACE_thread_key_t;
00121 #   else  /* ! ACE_HAS_TSS_EMULATION */
00122       typedef ACE_OS_thread_key_t ACE_thread_key_t;
00123 #   endif /* ! ACE_HAS_TSS_EMULATION */
00124 typedef mutex_t ACE_mutex_t;
00125 #     if !defined (ACE_LACKS_RWLOCK_T)
00126 typedef rwlock_t ACE_rwlock_t;
00127 #     endif /* !ACE_LACKS_RWLOCK_T */
00128 #     if !defined (ACE_HAS_POSIX_SEM) && !defined (ACE_USES_FIFO_SEM)
00129 typedef sema_t ACE_sema_t;
00130 #     endif /* !ACE_HAS_POSIX_SEM */
00131 
00132 typedef cond_t ACE_cond_t;
00133 struct ACE_Export ACE_condattr_t
00134 {
00135   int type;
00136 };
00137 struct ACE_Export ACE_mutexattr_t
00138 {
00139   int type;
00140 };
00141 typedef ACE_thread_t ACE_hthread_t;
00142 typedef ACE_mutex_t ACE_thread_mutex_t;
00143 
00144 ACE_END_VERSIONED_NAMESPACE_DECL
00145 
00146 #     define THR_CANCEL_DISABLE      0
00147 #     define THR_CANCEL_ENABLE       0
00148 #     define THR_CANCEL_DEFERRED     0
00149 #     define THR_CANCEL_ASYNCHRONOUS 0
00150 #     define THR_JOINABLE            0
00151 #     define THR_SCHED_FIFO          0
00152 #     define THR_SCHED_RR            0
00153 #     define THR_SCHED_DEFAULT       0
00154 #     define THR_INHERIT_SCHED       0
00155 #     define THR_SCOPE_PROCESS       0
00156 
00157 #   elif defined (ACE_VXWORKS)
00158 #     include /**/ <sysLib.h> // for sysClkRateGet()
00159 #     if !defined (__RTP__)
00160 #       include /**/ <taskLib.h>
00161 #       include /**/ <taskHookLib.h>
00162 #     endif
00163 
00164 // make sure these are included for VXWORKS.
00165 // @todo move these to a common place, perhaps the top of the file.
00166 #     include "ace/os_include/os_fcntl.h"
00167 #     include "ace/os_include/os_netdb.h"
00168 #     include "ace/os_include/os_semaphore.h"
00169 #     include "ace/os_include/os_signal.h"
00170 #     include "ace/os_include/os_stdio.h"
00171 #     include "ace/os_include/os_stdlib.h"
00172 #     include "ace/os_include/os_stropts.h"
00173 #     include "ace/os_include/os_unistd.h"
00174 #     include "ace/os_include/arpa/os_inet.h"
00175 #     include "ace/os_include/sys/os_select.h"
00176 #     include "ace/os_include/sys/os_socket.h"
00177 
00178 // task options:  the other options are either obsolete, internal, or for
00179 // Fortran or Ada support
00180 #     define VX_UNBREAKABLE        0x0002  /* breakpoints ignored */
00181 #     if !defined (VX_FP_TASK)
00182 #       define VX_FP_TASK          0x0008  /* floating point coprocessor */
00183 #     endif
00184 #     define VX_PRIVATE_ENV        0x0080  /* private environment support */
00185 #     define VX_NO_STACK_FILL      0x0100  /* do not stack fill for
00186                                               checkstack () */
00187 
00188 #     define THR_CANCEL_DISABLE      0
00189 #     define THR_CANCEL_ENABLE       0
00190 #     define THR_CANCEL_DEFERRED     0
00191 #     define THR_CANCEL_ASYNCHRONOUS 0
00192 #     define THR_BOUND               0
00193 #     define THR_NEW_LWP             0
00194 #     define THR_DETACHED            0
00195 #     define THR_SUSPENDED           0
00196 #     define THR_DAEMON              0
00197 #     define THR_JOINABLE            0
00198 #     define THR_SCHED_FIFO          0
00199 #     define THR_SCHED_RR            0
00200 #     define THR_SCHED_DEFAULT       0
00201 #     define THR_INHERIT_SCHED       0
00202 #     define THR_EXPLICIT_SCHED      0
00203 #     define THR_SCHED_IO            0
00204 #     define THR_SCOPE_SYSTEM        0
00205 #     define THR_SCOPE_PROCESS       0
00206 #     define USYNC_THREAD            0
00207 #     define USYNC_PROCESS           1 /* It's all global on VxWorks
00208                                           (without MMU option). */
00209 
00210 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00211 
00212 typedef SEM_ID ACE_mutex_t;
00213 // Implement ACE_thread_mutex_t with ACE_mutex_t because there's just
00214 // one process . . .
00215 typedef ACE_mutex_t ACE_thread_mutex_t;
00216 #     if !defined (ACE_HAS_POSIX_SEM)
00217 // Use VxWorks semaphores, wrapped ...
00218 typedef struct
00219 {
00220   /// Semaphore handle.  This is allocated by VxWorks.
00221   SEM_ID sema_;
00222 
00223   /// Name of the semaphore:  always NULL with VxWorks.
00224   char *name_;
00225 } ACE_sema_t;
00226 #     endif /* !ACE_HAS_POSIX_SEM */
00227 typedef int ACE_thread_t;
00228 typedef int ACE_hthread_t;
00229 // Key type: the ACE TSS emulation requires the key type be unsigned,
00230 // for efficiency.  (Current POSIX and Solaris TSS implementations also
00231 // use u_int, so the ACE TSS emulation is compatible with them.)
00232 // Native TSS key type
00233 typedef u_int ACE_OS_thread_key_t;
00234 // Application TSS key type (use this type except in TSS Emulation)
00235 #   if defined (ACE_HAS_TSS_EMULATION)
00236       typedef u_int ACE_thread_key_t;
00237 #   else  /* ! ACE_HAS_TSS_EMULATION */
00238       typedef ACE_OS_thread_key_t ACE_thread_key_t;
00239 #   endif /* ! ACE_HAS_TSS_EMULATION */
00240 
00241 ACE_END_VERSIONED_NAMESPACE_DECL
00242 
00243 #   elif defined (ACE_HAS_WTHREADS)
00244 
00245 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00246 
00247 typedef CRITICAL_SECTION ACE_thread_mutex_t;
00248 
00249 typedef struct
00250 {
00251   /// Either USYNC_THREAD or USYNC_PROCESS
00252   int type_;
00253   union
00254   {
00255     HANDLE proc_mutex_;
00256     CRITICAL_SECTION thr_mutex_;
00257   };
00258 } ACE_mutex_t;
00259 
00260 // Wrapper for NT Events.
00261 typedef HANDLE ACE_event_t;
00262 
00263 #     if defined (ACE_WIN32)
00264 //@@ ACE_USES_WINCE_SEMA_SIMULATION is used to debug
00265 //   semaphore simulation on WinNT.  It should be
00266 //   changed to ACE_USES_HAS_WINCE at some later point.
00267 #       if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
00268 typedef HANDLE ACE_sema_t;
00269 #       else
00270 /**
00271  * @class ACE_sema_t
00272  *
00273  * @brief Semaphore simulation for Windows CE.
00274  */
00275 class ACE_Export ACE_sema_t
00276 {
00277 public:
00278   /// Serializes access to @c count_.
00279   ACE_thread_mutex_t lock_;
00280 
00281   /// This event is signaled whenever the count becomes non-zero.
00282   ACE_event_t count_nonzero_;
00283 
00284   /// Current count of the semaphore.
00285   u_int count_;
00286 };
00287 
00288 #       endif /* ACE_USES_WINCE_SEMA_SIMULATION */
00289 #     endif /* defined (ACE_WIN32) */
00290 
00291 ACE_END_VERSIONED_NAMESPACE_DECL
00292 
00293 // These need to be different values, neither of which can be 0...
00294 #     define USYNC_THREAD 1
00295 #     define USYNC_PROCESS 2
00296 
00297 #     define THR_CANCEL_DISABLE      0
00298 #     define THR_CANCEL_ENABLE       0
00299 #     define THR_CANCEL_DEFERRED     0
00300 #     define THR_CANCEL_ASYNCHRONOUS 0
00301 #     define THR_DETACHED            0x02000000 /* ignore in most places */
00302 #     define THR_BOUND               0          /* ignore in most places */
00303 #     define THR_NEW_LWP             0          /* ignore in most places */
00304 #     define THR_DAEMON              0          /* ignore in most places */
00305 #     define THR_JOINABLE            0          /* ignore in most places */
00306 #     define THR_SUSPENDED   CREATE_SUSPENDED
00307 #     define THR_USE_AFX             0x01000000
00308 #     define THR_SCHED_FIFO          0
00309 #     define THR_SCHED_RR            0
00310 #     define THR_SCHED_DEFAULT       0
00311 #     define THR_INHERIT_SCHED       0
00312 #     define THR_EXPLICIT_SCHED      0
00313 #     define THR_SCOPE_PROCESS       0
00314 #     define THR_SCOPE_SYSTEM        0
00315 #   endif /* ACE_HAS_PTHREADS / STHREADS / VXWORKS / WTHREADS **********/
00316 
00317 #   if defined (ACE_LACKS_COND_T)
00318 
00319 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00320 
00321 /**
00322  * @class ACE_cond_t
00323  *
00324  * @brief This structure is used to implement condition variables on
00325  * platforms that lack it natively, such as VxWorks, and Win32.
00326  *
00327  * At the current time, this stuff only works for threads
00328  * within the same process.
00329  */
00330 class ACE_Export ACE_cond_t
00331 {
00332 public:
00333 
00334   /// Returns the number of waiters.
00335   long waiters (void) const;
00336 
00337 //protected:
00338   /// Number of waiting threads.
00339   long waiters_;
00340 
00341   /// Serialize access to the waiters count.
00342   ACE_thread_mutex_t waiters_lock_;
00343 
00344   /// Queue up threads waiting for the condition to become signaled.
00345   ACE_sema_t sema_;
00346 
00347 #     if defined (ACE_VXWORKS)
00348   /**
00349    * A semaphore used by the broadcast/signal thread to wait for all
00350    * the waiting thread(s) to wake up and be released from the
00351    * semaphore.
00352    */
00353   ACE_sema_t waiters_done_;
00354 #     elif defined (ACE_WIN32)
00355   /**
00356    * An auto reset event used by the broadcast/signal thread to wait
00357    * for the waiting thread(s) to wake up and get a chance at the
00358    * semaphore.
00359    */
00360   HANDLE waiters_done_;
00361 #     else
00362 #       error "Please implement this feature or check your config.h file!"
00363 #     endif /* ACE_VXWORKS */
00364 
00365   /// Keeps track of whether we were broadcasting or just signaling.
00366   size_t was_broadcast_;
00367 };
00368 
00369 struct ACE_Export ACE_condattr_t
00370 {
00371   int type;
00372 };
00373 
00374 struct ACE_Export ACE_mutexattr_t
00375 {
00376   int type;
00377 };
00378 
00379 ACE_END_VERSIONED_NAMESPACE_DECL
00380 
00381 #   endif /* ACE_LACKS_COND_T */
00382 
00383 #   if defined (ACE_LACKS_RWLOCK_T) && !defined (ACE_HAS_PTHREADS_UNIX98_EXT)
00384 
00385 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00386 
00387 /**
00388  * @class ACE_rwlock_t
00389  *
00390  * @brief This is used to implement readers/writer locks on NT,
00391  *     VxWorks, and POSIX pthreads.
00392  *
00393  *     At the current time, this stuff only works for threads
00394  *     within the same process.
00395  */
00396 struct ACE_Export ACE_rwlock_t
00397 {
00398 public:
00399 //protected:
00400 
00401   /// Serialize access to internal state.
00402   ACE_mutex_t lock_;
00403 
00404   /// Reader threads waiting to acquire the lock.
00405   ACE_cond_t waiting_readers_;
00406 
00407   /// Number of waiting readers.
00408   int num_waiting_readers_;
00409 
00410   /// Writer threads waiting to acquire the lock.
00411   ACE_cond_t waiting_writers_;
00412 
00413   /// Number of waiting writers.
00414   int num_waiting_writers_;
00415 
00416   /// Value is -1 if writer has the lock, else this keeps track of the
00417   /// number of readers holding the lock.
00418   int ref_count_;
00419 
00420   /// Indicate that a reader is trying to upgrade
00421   int important_writer_;
00422 
00423   /// Condition for the upgrading reader
00424   ACE_cond_t waiting_important_writer_;
00425 };
00426 
00427 ACE_END_VERSIONED_NAMESPACE_DECL
00428 
00429 #   elif defined (ACE_HAS_PTHREADS_UNIX98_EXT)
00430 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00431 typedef pthread_rwlock_t ACE_rwlock_t;
00432 ACE_END_VERSIONED_NAMESPACE_DECL
00433 #   elif defined (ACE_HAS_STHREADS)
00434 #     include /**/ <synch.h>
00435 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00436 typedef rwlock_t ACE_rwlock_t;
00437 ACE_END_VERSIONED_NAMESPACE_DECL
00438 #   endif /* ACE_LACKS_RWLOCK_T */
00439 
00440 // Define some default thread priorities on all threaded platforms, if
00441 // not defined above or in the individual platform config file.
00442 // ACE_THR_PRI_FIFO_DEF should be used by applications for default
00443 // real-time thread priority.  ACE_THR_PRI_OTHER_DEF should be used
00444 // for non-real-time priority.
00445 #   if !defined(ACE_THR_PRI_FIFO_DEF)
00446 #     if defined (ACE_WTHREADS)
00447       // It would be more in spirit to use THREAD_PRIORITY_NORMAL.  But,
00448       // using THREAD_PRIORITY_ABOVE_NORMAL should give preference to the
00449       // threads in this process, even if the process is not in the
00450       // REALTIME_PRIORITY_CLASS.
00451 #       define ACE_THR_PRI_FIFO_DEF THREAD_PRIORITY_ABOVE_NORMAL
00452 #     else  /* ! ACE_WTHREADS */
00453 #       define ACE_THR_PRI_FIFO_DEF 0
00454 #     endif /* ! ACE_WTHREADS */
00455 #   endif /* ! ACE_THR_PRI_FIFO_DEF */
00456 
00457 #   if !defined(ACE_THR_PRI_OTHER_DEF)
00458 #     if defined (ACE_WTHREADS)
00459       // It would be more in spirit to use THREAD_PRIORITY_NORMAL.  But,
00460       // using THREAD_PRIORITY_ABOVE_NORMAL should give preference to the
00461       // threads in this process, even if the process is not in the
00462       // REALTIME_PRIORITY_CLASS.
00463 #       define ACE_THR_PRI_OTHER_DEF THREAD_PRIORITY_NORMAL
00464 #     else  /* ! ACE_WTHREADS */
00465 #       define ACE_THR_PRI_OTHER_DEF 0
00466 #     endif /* ! ACE_WTHREADS */
00467 #   endif /* ! ACE_THR_PRI_OTHER_DEF */
00468 
00469 // Recursive mutex support.
00470 //
00471 // There are two parts to this:
00472 // 1. The mutex type itself. This is based on whether or not the
00473 //    platform supports recursive mutexes natively or they're emulated.
00474 // 2. Support for using the recursive mutex with a condition variable.
00475 //    When a thread waits on a condition variable, it has to relinquish
00476 //    the lock and wait atomically, then reacquire it after the condition
00477 //    variable is signaled. In non-recursive mutexes, the platform
00478 //    handles this automatically. But in recursive mutexes, especially
00479 //    when emulated, the recursion count needs to be maintained across
00480 //    the wait. Since another thread needs to be able to acquire the
00481 //    lock, it needs to appear free, even if the waiting thread had done
00482 //    multiple acquires. Thus, there's another structure to hold this
00483 //    information, and is used with the recursive_mutex_cond_unlock()
00484 //    and recursive_mutex_cond_relock() methods to maintain the expected
00485 //    state when the wait finishes.
00486 #   if defined (ACE_HAS_RECURSIVE_MUTEXES)
00487 
00488 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00489 
00490 typedef ACE_thread_mutex_t ACE_recursive_thread_mutex_t;
00491 #     if defined (ACE_WIN32)
00492 // Windows has recursive mutexes, but doesn't have condition variables,
00493 // so there's no built-in support for this. Thus, the condition-related
00494 // unlock/relock is augmented in ACE.
00495 struct ACE_recursive_mutex_state
00496 {
00497   // On Windows the augmented processing is simply unlocking/relocking
00498   // the recursive locks - the condition handles a single lock ok.
00499   LONG relock_count_;
00500 };
00501 #     else
00502 // No need for special handling; just need a type for method signatures.
00503 typedef int ACE_recursive_mutex_state;
00504 #     endif /* ACE_WIN32 */
00505 
00506 ACE_END_VERSIONED_NAMESPACE_DECL
00507 
00508 #   else
00509 
00510 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00511 
00512 /**
00513  * @class ACE_recursive_thread_mutex_t
00514  *
00515  * @brief Implement a thin C++ wrapper that allows nested acquisition
00516  * and release of a mutex that occurs in the same thread.
00517  *
00518  * This implementation is based on an algorithm sketched by Dave
00519  * Butenhof <butenhof@zko.dec.com>.  Naturally, I take the
00520  * credit for any mistakes ;-)
00521  */
00522 class ACE_recursive_thread_mutex_t
00523 {
00524 public:
00525   /// Guards the state of the nesting level and thread id.
00526   ACE_thread_mutex_t nesting_mutex_;
00527 
00528   /// This condition variable suspends other waiting threads until the
00529   /// mutex is available.
00530   ACE_cond_t lock_available_;
00531 
00532   /// Current nesting level of the recursion.
00533   int nesting_level_;
00534 
00535   /// Current owner of the lock.
00536   ACE_thread_t owner_id_;
00537 };
00538 
00539 // Since recursive mutex is emulated, the state saving needs to be handled
00540 // in ACE as well. These members save those from ACE_recursive_thread_mutex_t.
00541 struct ACE_recursive_mutex_state
00542 {
00543   int nesting_level_;
00544   ACE_thread_t owner_id_;
00545 };
00546 
00547 ACE_END_VERSIONED_NAMESPACE_DECL
00548 
00549 #   endif /* ACE_HAS_RECURSIVE_MUTEXES */
00550 
00551 # else /* !ACE_HAS_THREADS, i.e., the OS/platform doesn't support threading. */
00552 
00553 // Give these things some reasonable value...
00554 #   define ACE_SCOPE_PROCESS 0
00555 #   define ACE_SCOPE_LWP 1
00556 #   define ACE_SCOPE_THREAD 2
00557 #   define ACE_SCHED_OTHER 0
00558 #   define ACE_SCHED_FIFO 1
00559 #   define ACE_SCHED_RR 2
00560 #   if !defined (THR_CANCEL_DISABLE)
00561 #     define THR_CANCEL_DISABLE      0
00562 #   endif /* ! THR_CANCEL_DISABLE */
00563 #   if !defined (THR_CANCEL_ENABLE)
00564 #     define THR_CANCEL_ENABLE       0
00565 #   endif /* ! THR_CANCEL_ENABLE */
00566 #   if !defined (THR_CANCEL_DEFERRED)
00567 #     define THR_CANCEL_DEFERRED     0
00568 #   endif /* ! THR_CANCEL_DEFERRED */
00569 #   if !defined (THR_CANCEL_ASYNCHRONOUS)
00570 #     define THR_CANCEL_ASYNCHRONOUS 0
00571 #   endif /* ! THR_CANCEL_ASYNCHRONOUS */
00572 #   if !defined (THR_JOINABLE)
00573 #     define THR_JOINABLE    0     /* ignore in most places */
00574 #   endif /* ! THR_JOINABLE */
00575 #   if !defined (THR_DETACHED)
00576 #     define THR_DETACHED    0     /* ignore in most places */
00577 #   endif /* ! THR_DETACHED */
00578 #   if !defined (THR_DAEMON)
00579 #     define THR_DAEMON      0     /* ignore in most places */
00580 #   endif /* ! THR_DAEMON */
00581 #   if !defined (THR_BOUND)
00582 #     define THR_BOUND       0     /* ignore in most places */
00583 #   endif /* ! THR_BOUND */
00584 #   if !defined (THR_NEW_LWP)
00585 #     define THR_NEW_LWP     0     /* ignore in most places */
00586 #   endif /* ! THR_NEW_LWP */
00587 #   if !defined (THR_SUSPENDED)
00588 #     define THR_SUSPENDED   0     /* ignore in most places */
00589 #   endif /* ! THR_SUSPENDED */
00590 #   if !defined (THR_SCHED_FIFO)
00591 #     define THR_SCHED_FIFO 0
00592 #   endif /* ! THR_SCHED_FIFO */
00593 #   if !defined (THR_SCHED_RR)
00594 #     define THR_SCHED_RR 0
00595 #   endif /* ! THR_SCHED_RR */
00596 #   if !defined (THR_SCHED_DEFAULT)
00597 #     define THR_SCHED_DEFAULT 0
00598 #   endif /* ! THR_SCHED_DEFAULT */
00599 #   if !defined (THR_INHERIT_SCHED)
00600 #     define THR_INHERIT_SCHED 0
00601 #   endif /* ! THR_INHERIT_SCHED */
00602 #   if !defined (USYNC_THREAD)
00603 #     define USYNC_THREAD 0
00604 #   endif /* ! USYNC_THREAD */
00605 #   if !defined (USYNC_PROCESS)
00606 #     define USYNC_PROCESS 0
00607 #   endif /* ! USYNC_PROCESS */
00608 #   if !defined (THR_SCOPE_PROCESS)
00609 #     define THR_SCOPE_PROCESS 0
00610 #   endif /* ! THR_SCOPE_PROCESS */
00611 #   if !defined (THR_SCOPE_SYSTEM)
00612 #     define THR_SCOPE_SYSTEM 0
00613 #   endif /* ! THR_SCOPE_SYSTEM */
00614 
00615 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00616 
00617 // These are dummies needed for class OS.h
00618 typedef int ACE_cond_t;
00619 struct ACE_Export ACE_condattr_t
00620 {
00621   int type;
00622 };
00623 struct ACE_Export ACE_mutexattr_t
00624 {
00625   int type;
00626 };
00627 typedef int ACE_mutex_t;
00628 typedef int ACE_thread_mutex_t;
00629 typedef int ACE_recursive_thread_mutex_t;
00630 typedef int ACE_recursive_mutex_state;
00631 #   if !defined (ACE_HAS_POSIX_SEM) && !defined (ACE_USES_FIFO_SEM)
00632 typedef int ACE_sema_t;
00633 #   endif /* !ACE_HAS_POSIX_SEM && !ACE_USES_FIFO_SEM */
00634 typedef int ACE_rwlock_t;
00635 typedef int ACE_thread_t;
00636 typedef int ACE_hthread_t;
00637 // Native TSS key type
00638 typedef unsigned int ACE_OS_thread_key_t;
00639 // Application TSS key type (use this type except in TSS Emulation)
00640 #   if defined (ACE_HAS_TSS_EMULATION)
00641       typedef u_int ACE_thread_key_t;
00642 #   else  /* ! ACE_HAS_TSS_EMULATION */
00643       typedef ACE_OS_thread_key_t ACE_thread_key_t;
00644 #   endif /* ! ACE_HAS_TSS_EMULATION */
00645 
00646 ACE_END_VERSIONED_NAMESPACE_DECL
00647 
00648 // Ensure that ACE_THR_PRI_FIFO_DEF and ACE_THR_PRI_OTHER_DEF are
00649 // defined on non-threaded platforms, to support application source
00650 // code compatibility.  ACE_THR_PRI_FIFO_DEF should be used by
00651 // applications for default real-time thread priority.
00652 // ACE_THR_PRI_OTHER_DEF should be used for non-real-time priority.
00653 #   if !defined(ACE_THR_PRI_FIFO_DEF)
00654 #     define ACE_THR_PRI_FIFO_DEF 0
00655 #   endif /* ! ACE_THR_PRI_FIFO_DEF */
00656 #   if !defined(ACE_THR_PRI_OTHER_DEF)
00657 #     define ACE_THR_PRI_OTHER_DEF 0
00658 #   endif /* ! ACE_THR_PRI_OTHER_DEF */
00659 
00660 # endif /* ACE_HAS_THREADS ***********************************************/
00661 
00662 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00663 
00664 /**
00665  * @class ACE_Thread_ID
00666  *
00667  * @brief Defines a platform-independent thread ID class.  Note that
00668  *  this class should be defined within the scope of a thread, rather
00669  *  than at global scope!
00670  */
00671 class ACE_Export ACE_Thread_ID
00672 {
00673 public:
00674   /// Initialize the object using the thread id and thread handle
00675   /// passed as parameters.
00676   ACE_Thread_ID (ACE_thread_t thr_id,
00677                  ACE_hthread_t thr_handle);
00678 
00679   /// Initialize the object using calls to ACE_OS::thr_self().
00680   ACE_Thread_ID (void);
00681 
00682   /// Copy constructor.
00683   ACE_Thread_ID (const ACE_Thread_ID &rhs);
00684 
00685   /// Get the thread id.
00686   ACE_thread_t id (void) const;
00687 
00688   /// Set the thread id.
00689   void id (ACE_thread_t);
00690 
00691   /// Get the thread handle.
00692   ACE_hthread_t handle (void) const;
00693 
00694   /// Set the thread handle.
00695   void handle (ACE_hthread_t);
00696 
00697   // Create a string representation of the thread id.
00698   void to_string (char *thr_string) const;
00699 
00700   /// Equality operator.
00701   bool operator== (const ACE_Thread_ID &) const;
00702 
00703   /// Inequality operator.
00704   bool operator!= (const ACE_Thread_ID &) const;
00705 
00706 private:
00707   /// Identify the thread.
00708   ACE_thread_t thread_id_;
00709 
00710   /// Handle to the thread (typically used to "wait" on Win32).
00711   ACE_hthread_t thread_handle_;
00712 };
00713 
00714 // = The ACE_Sched_Priority type should be used for platform-
00715 //   independent thread and process priorities, by convention.
00716 //   int should be used for OS-specific priorities.
00717 typedef int ACE_Sched_Priority;
00718 
00719 # if !defined (ACE_DEFAULT_SYNCH_TYPE)
00720 #   if defined (ACE_VXWORKS)
00721       // Types include these options: SEM_Q_PRIORITY, SEM_Q_FIFO,
00722       // SEM_DELETE_SAFE, and SEM_INVERSION_SAFE.  SEM_Q_FIFO is
00723       // used as the default because that is VxWorks' default.
00724 #     define ACE_DEFAULT_SYNCH_TYPE SEM_Q_FIFO
00725 #   else
00726 #     define ACE_DEFAULT_SYNCH_TYPE USYNC_THREAD
00727 #   endif /* ACE_VXWORKS */
00728 #endif /* ! ACE_DEFAULT_SYNCH_TYPE */
00729 
00730 // forward declaration
00731 class ACE_Sched_Params;
00732 class ACE_Time_Value;
00733 
00734 #if defined (ACE_WIN32)
00735 typedef int ACE_idtype_t;
00736 typedef DWORD ACE_id_t;
00737 typedef int ACE_pri_t;
00738 #   define ACE_SELF (0)
00739 #else /* !defined (ACE_WIN32) */
00740 #   if defined (ACE_HAS_IDTYPE_T)
00741   typedef idtype_t ACE_idtype_t;
00742 #   else
00743   typedef int ACE_idtype_t;
00744 #   endif /* ACE_HAS_IDTYPE_T */
00745 #   if defined (ACE_HAS_STHREADS) || defined (DIGITAL_UNIX)
00746 #     if defined (ACE_LACKS_PRI_T)
00747     typedef int pri_t;
00748 #     endif /* ACE_LACKS_PRI_T */
00749   typedef id_t ACE_id_t;
00750 #     define ACE_SELF P_MYID
00751   typedef pri_t ACE_pri_t;
00752 #   else  /* ! ACE_HAS_STHREADS && ! DIGITAL_UNIX */
00753   typedef long ACE_id_t;
00754 #     define ACE_SELF (-1)
00755   typedef short ACE_pri_t;
00756 #   endif /* ! ACE_HAS_STHREADS && ! DIGITAL_UNIX */
00757 #endif /* !defined (ACE_WIN32) */
00758 
00759 # if defined (ACE_HAS_TSS_EMULATION)
00760     // Allow config.h to set the default number of thread keys.
00761 #   if !defined (ACE_DEFAULT_THREAD_KEYS)
00762 #     define ACE_DEFAULT_THREAD_KEYS 64
00763 #   endif /* ! ACE_DEFAULT_THREAD_KEYS */
00764 
00765 // forward declaration
00766 class ACE_TSS_Keys;
00767 
00768 /**
00769  * @class ACE_TSS_Emulation
00770  *
00771  * @brief Thread-specific storage emulation.
00772  *
00773  * This provides a thread-specific storage implementation.
00774  * It is intended for use on platforms that don't have a
00775  * native TSS, or have a TSS with limitations such as the
00776  * number of keys or lack of support for removing keys.
00777  */
00778 class ACE_Export ACE_TSS_Emulation
00779 {
00780 public:
00781   typedef void (*ACE_TSS_DESTRUCTOR)(void *value) /* throw () */;
00782 
00783   /// Maximum number of TSS keys allowed over the life of the program.
00784   enum { ACE_TSS_THREAD_KEYS_MAX = ACE_DEFAULT_THREAD_KEYS };
00785 
00786   /// Returns the total number of keys allocated so far.
00787   static u_int total_keys ();
00788 
00789   /// Sets the argument to the next available key.  Returns 0 on success,
00790   /// -1 if no keys are available.
00791   static int next_key (ACE_thread_key_t &key);
00792 
00793   /// Release a key that was used. This way the key can be given out in a
00794   /// new request. Returns 0 on success, 1 if the key was not reserved.
00795   static int release_key (ACE_thread_key_t key);
00796 
00797   /// Check a key for validity.
00798   static int is_key (ACE_thread_key_t key);
00799 
00800   /// Returns the exit hook associated with the key.  Does _not_ check
00801   /// for a valid key.
00802   static ACE_TSS_DESTRUCTOR tss_destructor (const ACE_thread_key_t key);
00803 
00804   /// Associates the TSS destructor with the key.  Does _not_ check
00805   /// for a valid key.
00806   static void tss_destructor (const ACE_thread_key_t key,
00807                               ACE_TSS_DESTRUCTOR destructor);
00808 
00809   /// Accesses the object referenced by key in the current thread's TSS array.
00810   /// Does _not_ check for a valid key.
00811   static void *&ts_object (const ACE_thread_key_t key);
00812 
00813   /**
00814    * Setup an array to be used for local TSS.  Returns the array
00815    * address on success.  Returns 0 if local TSS had already been
00816    * setup for this thread.  There is no corresponding tss_close ()
00817    * because it is not needed.
00818    * @note tss_open () is called by ACE for threads that it spawns.
00819    * If your application spawns threads without using ACE, and it uses
00820    * ACE's TSS emulation, each of those threads should call tss_open
00821    * ().  See the ace_thread_adapter () implementation for an example.
00822    */
00823   static void *tss_open (void *ts_storage[ACE_TSS_THREAD_KEYS_MAX]);
00824 
00825   /// Shutdown TSS emulation.  For use only by ACE_OS::cleanup_tss ().
00826   static void tss_close ();
00827 
00828 private:
00829   // Global TSS structures.
00830   /// Contains the possible value of the next key to be allocated. Which key
00831   /// is actually allocated is based on the tss_keys_used
00832   static u_int total_keys_;
00833 
00834   /// Array of thread exit hooks (TSS destructors) that are called for each
00835   /// key (that has one) when the thread exits.
00836   static ACE_TSS_DESTRUCTOR tss_destructor_ [ACE_TSS_THREAD_KEYS_MAX];
00837 
00838   /// TSS_Keys instance to administrate whether a specific key is in used
00839   /// or not.
00840   /// or not.
00841   // Static construction in VxWorks 5.4 and later is slightly broken.
00842   // If the static object is more complex than an integral type, static
00843   // construction will occur twice.  The tss_keys_used_ object is
00844   // statically constructed and then modified by ACE_Log_Msg::instance()
00845   // when two keys are created and TSS data is stored.  However, at
00846   // the end of static construction the tss_keys_used_ object is again
00847   // initialized and therefore it will appear to next_key() that no
00848   // TSS keys have been handed out.  That is all true unless the
00849   // tss_keys_used object is a static pointer instead of a static object.
00850   static ACE_TSS_Keys* tss_keys_used_;
00851 
00852 #   if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
00853   /// Location of current thread's TSS array.
00854   static void **tss_base (void* ts_storage[] = 0, u_int *ts_created = 0);
00855 #   else  /* ! ACE_HAS_THREAD_SPECIFIC_STORAGE */
00856   /// Location of current thread's TSS array.
00857   static void **&tss_base ();
00858 #   endif /* ! ACE_HAS_THREAD_SPECIFIC_STORAGE */
00859 
00860 #   if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
00861   // Rely on native thread specific storage for the implementation,
00862   // but just use one key.
00863   static ACE_OS_thread_key_t native_tss_key_;
00864 
00865   // Used to indicate if native tss key has been allocated
00866   static bool key_created_;
00867 #   endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
00868 };
00869 # endif /* ACE_HAS_TSS_EMULATION */
00870 
00871 // moved ACE_TSS_Ref, ACE_TSS_Info, and ACE_TSS_Keys class
00872 // declarations from OS.cpp so they are visible to the single
00873 // file of template instantiations.
00874 # if defined (ACE_WIN32) || defined (ACE_HAS_TSS_EMULATION)
00875 /**
00876  * @class ACE_TSS_Ref
00877  *
00878  * @brief "Reference count" for thread-specific storage keys.
00879  *
00880  * Since the <ACE_Unbounded_Stack> doesn't allow duplicates, the
00881  * "reference count" is the identify of the thread_id.
00882  */
00883 class ACE_TSS_Ref
00884 {
00885 public:
00886   /// Constructor
00887   ACE_TSS_Ref (ACE_thread_t id);
00888 
00889   /// Default constructor
00890   ACE_TSS_Ref (void);
00891 
00892   /// Check for equality.
00893   bool operator== (const ACE_TSS_Ref &) const;
00894 
00895   /// Check for inequality.
00896   bool operator!= (const ACE_TSS_Ref &) const;
00897 
00898 // private:
00899 
00900   /// ID of thread using a specific key.
00901   ACE_thread_t tid_;
00902 };
00903 
00904 /**
00905  * @class ACE_TSS_Info
00906  *
00907  * @brief Thread Specific Key management.
00908  *
00909  * This class maps a key to a "destructor."
00910  */
00911 class ACE_TSS_Info
00912 {
00913 public:
00914   /// Declare pointer to function to destroy tss object.
00915   typedef void (*Destructor)(void *);
00916 
00917   /// Constructor
00918   ACE_TSS_Info (ACE_thread_key_t key,
00919                 Destructor dest = 0);
00920 
00921   /// Default constructor
00922   ACE_TSS_Info (void);
00923 
00924   /// Returns 1 if the key is in use, 0 if not.
00925   int key_in_use (void) const { return thread_count_ != -1; }
00926 
00927   /// Mark the key as being in use if the flag is non-zero, or
00928   /// not in use if the flag is 0.
00929   void key_in_use (int flag) { thread_count_ = flag == 0  ?  -1  :  1; }
00930 
00931   /// Check for equality.
00932   bool operator== (const ACE_TSS_Info &) const;
00933 
00934   /// Check for inequality.
00935   bool operator!= (const ACE_TSS_Info &) const;
00936 
00937   /// Dump the state.
00938   void dump (void);
00939 
00940 private:
00941   /// Key to the thread-specific storage item.
00942   ACE_thread_key_t key_;
00943 
00944   /// "Destructor" that gets called when the item is finally released.
00945   Destructor destructor_;
00946 
00947   /// Count of threads that are using this key.  Contains -1 when the
00948   /// key is not in use.
00949   int thread_count_;
00950 
00951   friend class ACE_TSS_Cleanup;
00952 };
00953 
00954 /**
00955  * @class ACE_TSS_Keys
00956  *
00957  * @brief Collection of in-use flags for a thread's TSS keys.
00958  * For internal use only by ACE_TSS_Cleanup; it is public because
00959  * some compilers can't use nested classes for template instantiation
00960  * parameters.
00961  *
00962  * Wrapper around array of whether each key is in use.  A simple
00963  * typedef doesn't work with Sun C++ 4.2.
00964  */
00965 class ACE_TSS_Keys
00966 {
00967 public:
00968   /// Default constructor, to initialize all bits to zero (unused).
00969   ACE_TSS_Keys (void);
00970 
00971   /// Mark the specified key as being in use, if it was not already so marked.
00972   /// Returns 1 if the had already been marked, 0 if not.
00973   int test_and_set (const ACE_thread_key_t key);
00974 
00975   /// Mark the specified key as not being in use, if it was not already so
00976   /// cleared.  Returns 1 if the key had already been cleared, 0 if not.
00977   int test_and_clear (const ACE_thread_key_t key);
00978 
00979   /// Return whether the specific key is marked as in use.
00980   /// Returns 1 if the key is been marked, 0 if not.
00981   int is_set (const ACE_thread_key_t key) const;
00982 
00983 private:
00984   /// For a given key, find the word and bit number that represent it.
00985   static void find (const u_int key, u_int &word, u_int &bit);
00986 
00987   enum
00988     {
00989 #   if ACE_SIZEOF_LONG == 8
00990       ACE_BITS_PER_WORD = 64,
00991 #   elif ACE_SIZEOF_LONG == 4
00992       ACE_BITS_PER_WORD = 32,
00993 #   else
00994 #     error ACE_TSS_Keys only supports 32 or 64 bit longs.
00995 #   endif /* ACE_SIZEOF_LONG == 8 */
00996       ACE_WORDS = (ACE_DEFAULT_THREAD_KEYS - 1) / ACE_BITS_PER_WORD + 1
00997     };
00998 
00999   /// Bit flag collection.  A bit value of 1 indicates that the key is in
01000   /// use by this thread.
01001   u_long key_bit_words_[ACE_WORDS];
01002 };
01003 
01004 # endif /* defined (ACE_WIN32) || defined (ACE_HAS_TSS_EMULATION) */
01005 
01006 // Support non-scalar thread keys, such as with some POSIX
01007 // implementations, e.g., MVS.
01008 # if defined (ACE_HAS_NONSCALAR_THREAD_KEY_T)
01009 #   define ACE_KEY_INDEX(OBJ,KEY) \
01010   u_int OBJ; \
01011   ACE_OS::memcpy (&OBJ, &KEY, sizeof (u_int))
01012 # else
01013 #   define ACE_KEY_INDEX(OBJ,KEY) u_int OBJ = KEY
01014 # endif /* ACE_HAS_NONSCALAR_THREAD_KEY_T */
01015 
01016 ACE_END_VERSIONED_NAMESPACE_DECL
01017 
01018 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) && ACE_HAS_VERSIONED_NAMESPACE == 1)
01019 # define ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _ace_mutex_lock_cleanup_adapter)
01020 #endif  /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
01021 
01022 
01023 # if defined (ACE_HAS_THR_C_FUNC)
01024 // This is necessary to work around nasty problems with MVS C++.
01025 extern "C" ACE_Export void ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME (void *args);
01026 #   define ACE_PTHREAD_CLEANUP_PUSH(A) pthread_cleanup_push (ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME, (void *) A);
01027 #   define ACE_PTHREAD_CLEANUP_POP(A) pthread_cleanup_pop(A)
01028 # elif defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CLEANUP)
01029 // Though we are defining a extern "C" function to match the prototype of
01030 // pthread_cleanup_push, it is undone by the Solaris header file
01031 // /usr/include/pthread.h. So this macro generates a warning under Solaris
01032 // with SunCC. This is a bug in the Solaris header file.
01033 extern "C" ACE_Export void ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME (void *args);
01034 #   define ACE_PTHREAD_CLEANUP_PUSH(A) pthread_cleanup_push (ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME, (void *) A);
01035 #   define ACE_PTHREAD_CLEANUP_POP(A) pthread_cleanup_pop(A)
01036 # else
01037 #   define ACE_PTHREAD_CLEANUP_PUSH(A)
01038 #   define ACE_PTHREAD_CLEANUP_POP(A)
01039 # endif /* ACE_HAS_THR_C_FUNC */
01040 
01041 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
01042 
01043 # if !defined (ACE_WIN32)
01044 // forward decl's
01045 class ACE_event_t;
01046 # endif
01047 
01048 class ACE_Base_Thread_Adapter;
01049 
01050 namespace ACE_OS {
01051   //@{ @name A set of wrappers for threads
01052 
01053   /// This is necessary to deal with POSIX pthreads and their use of
01054   /// structures for thread ids.
01055   extern ACE_Export ACE_thread_t NULL_thread;
01056 
01057   /// This is necessary to deal with POSIX pthreads and their use of
01058   /// structures for thread handles.
01059   extern ACE_Export ACE_hthread_t NULL_hthread;
01060 
01061   /// This is necessary to deal with POSIX pthreads and their use of
01062   /// structures for TSS keys.
01063   extern ACE_Export ACE_thread_key_t NULL_key;
01064   //@}
01065 
01066   /**
01067    * Call TSS destructors for the current thread.  If the current
01068    * thread is the main thread, then the argument must be 1.
01069    * For private use of ACE_Object_Manager and ACE_Thread_Adapter only.
01070    */
01071   extern ACE_Export
01072   void cleanup_tss (const u_int main_thread);
01073 
01074   //@{ @name A set of wrappers for condition variables.
01075 #if defined (ACE_LACKS_COND_T)
01076   extern ACE_Export
01077 #else
01078   ACE_NAMESPACE_INLINE_FUNCTION
01079 #endif /* ACE_LACKS_COND_T */
01080   int condattr_init (ACE_condattr_t &attributes,
01081                      int type = ACE_DEFAULT_SYNCH_TYPE);
01082 
01083 #if defined (ACE_LACKS_COND_T)
01084   extern ACE_Export
01085 #else
01086   ACE_NAMESPACE_INLINE_FUNCTION
01087 #endif /* ACE_LACKS_COND_T */
01088   int condattr_destroy (ACE_condattr_t &attributes);
01089 
01090 #if defined (ACE_LACKS_COND_T)
01091   extern ACE_Export
01092 #else
01093   ACE_NAMESPACE_INLINE_FUNCTION
01094 #endif /* ACE_LACKS_COND_T */
01095   int cond_broadcast (ACE_cond_t *cv);
01096 
01097 #if defined (ACE_LACKS_COND_T)
01098   extern ACE_Export
01099 #else
01100   ACE_NAMESPACE_INLINE_FUNCTION
01101 #endif /* ACE_LACKS_COND_T */
01102   int cond_destroy (ACE_cond_t *cv);
01103 
01104   extern ACE_Export
01105   int cond_init (ACE_cond_t *cv,
01106                  short type = ACE_DEFAULT_SYNCH_TYPE,
01107                  const char *name = 0,
01108                  void *arg = 0);
01109 
01110 #if defined (ACE_LACKS_COND_T)
01111   extern ACE_Export
01112 #else
01113   ACE_NAMESPACE_INLINE_FUNCTION
01114 #endif /* ACE_LACKS_COND_T */
01115   int cond_init (ACE_cond_t *cv,
01116                  ACE_condattr_t &attributes,
01117                  const char *name = 0,
01118                  void *arg = 0);
01119 
01120 # if defined (ACE_HAS_WCHAR)
01121 #   if defined (ACE_LACKS_COND_T)
01122   extern ACE_Export
01123 #   else
01124   ACE_NAMESPACE_INLINE_FUNCTION
01125 #   endif /* ACE_LACKS_COND_T */
01126   int cond_init (ACE_cond_t *cv,
01127                  short type,
01128                  const wchar_t *name,
01129                  void *arg = 0);
01130 
01131 #   if defined (ACE_LACKS_COND_T)
01132   extern ACE_Export
01133 #   else
01134   ACE_NAMESPACE_INLINE_FUNCTION
01135 #   endif /* ACE_LACKS_COND_T */
01136   int cond_init (ACE_cond_t *cv,
01137                  ACE_condattr_t &attributes,
01138                  const wchar_t *name,
01139                  void *arg = 0);
01140 # endif /* ACE_HAS_WCHAR */
01141 
01142 #if defined (ACE_LACKS_COND_T)
01143   extern ACE_Export
01144 #else
01145   ACE_NAMESPACE_INLINE_FUNCTION
01146 #endif /* ACE_LACKS_COND_T */
01147   int cond_signal (ACE_cond_t *cv);
01148 
01149 #if defined (ACE_LACKS_COND_T)
01150   extern ACE_Export
01151 #else
01152   ACE_NAMESPACE_INLINE_FUNCTION
01153 #endif /* ACE_LACKS_COND_T */
01154   int cond_timedwait (ACE_cond_t *cv,
01155                       ACE_mutex_t *m,
01156                       ACE_Time_Value *);
01157 
01158 #if defined (ACE_LACKS_COND_T)
01159   extern ACE_Export
01160 #else
01161   ACE_NAMESPACE_INLINE_FUNCTION
01162 #endif /* ACE_LACKS_COND_T */
01163   int cond_wait (ACE_cond_t *cv,
01164                  ACE_mutex_t *m);
01165 
01166 # if defined (ACE_WIN32) && defined (ACE_HAS_WTHREADS)
01167 #   if defined (ACE_LACKS_COND_T)
01168   extern ACE_Export
01169 #   else
01170   ACE_NAMESPACE_INLINE_FUNCTION
01171 #   endif /* ACE_LACKS_COND_T */
01172   int cond_timedwait (ACE_cond_t *cv,
01173                       ACE_thread_mutex_t *m,
01174                       ACE_Time_Value *);
01175 
01176 #   if defined (ACE_LACKS_COND_T)
01177   extern ACE_Export
01178 #   else
01179   ACE_NAMESPACE_INLINE_FUNCTION
01180 #   endif /* ACE_LACKS_COND_T */
01181   int cond_wait (ACE_cond_t *cv,
01182                  ACE_thread_mutex_t *m);
01183 # endif /* ACE_WIN32 && ACE_HAS_WTHREADS */
01184 
01185   //@{ @name A set of wrappers for auto-reset and manual events.
01186 
01187   extern ACE_Export
01188   int event_destroy (ACE_event_t *event);
01189 
01190   extern ACE_Export
01191   int event_init (ACE_event_t *event,
01192                   int manual_reset = 0,
01193                   int initial_state = 0,
01194                   int type = ACE_DEFAULT_SYNCH_TYPE,
01195                   const char *name = 0,
01196                   void *arg = 0,
01197                   LPSECURITY_ATTRIBUTES sa = 0);
01198 
01199 # if defined (ACE_HAS_WCHAR)
01200   ACE_NAMESPACE_INLINE_FUNCTION
01201   int event_init (ACE_event_t *event,
01202                   int manual_reset,
01203                   int initial_state,
01204                   int type,
01205                   const wchar_t *name,
01206                   void *arg = 0,
01207                   LPSECURITY_ATTRIBUTES sa = 0);
01208 # endif /* ACE_HAS_WCHAR */
01209 
01210   extern ACE_Export
01211   int event_pulse (ACE_event_t *event);
01212 
01213   extern ACE_Export
01214   int event_reset (ACE_event_t *event);
01215 
01216   extern ACE_Export
01217   int event_signal (ACE_event_t *event);
01218 
01219   extern ACE_Export
01220   int event_timedwait (ACE_event_t *event,
01221                        ACE_Time_Value *timeout,
01222                        int use_absolute_time = 1);
01223 
01224   extern ACE_Export
01225   int event_wait (ACE_event_t *event);
01226 
01227   //@}
01228 
01229   extern ACE_Export
01230   int lwp_getparams (ACE_Sched_Params &);
01231 
01232   extern ACE_Export
01233   int lwp_setparams (const ACE_Sched_Params &);
01234 
01235 
01236   //@{ @name A set of wrappers for mutex locks.
01237 
01238   extern ACE_Export
01239   int mutex_destroy (ACE_mutex_t *m);
01240 
01241   extern ACE_Export
01242   int mutex_init (ACE_mutex_t *m,
01243                   int lock_scope = ACE_DEFAULT_SYNCH_TYPE,
01244                   const char *name = 0,
01245                   ACE_mutexattr_t *arg = 0,
01246                   LPSECURITY_ATTRIBUTES sa = 0,
01247                   int lock_type = 0);
01248 
01249 #if defined (ACE_HAS_WCHAR)
01250   extern ACE_Export
01251   int mutex_init (ACE_mutex_t *m,
01252                   int lock_scope,
01253                   const wchar_t *name,
01254                   ACE_mutexattr_t *arg = 0,
01255                   LPSECURITY_ATTRIBUTES sa = 0,
01256                   int lock_type = 0);
01257 #endif /* ACE_HAS_WCHAR */
01258 
01259   /// Win32 note: Abandoned mutexes are not treated differently. 0 is
01260   /// returned since the calling thread does get the ownership.
01261   extern ACE_Export
01262   int mutex_lock (ACE_mutex_t *m);
01263 
01264   /// This method is only implemented for Win32.  For abandoned
01265   /// mutexes, @a abandoned is set to 1 and 0 is returned.
01266   extern ACE_Export
01267   int mutex_lock (ACE_mutex_t *m,
01268                   int &abandoned);
01269 
01270   /**
01271    * This method attempts to acquire a lock, but gives up if the lock
01272    * has not been acquired by the given time.  If the lock is not
01273    * acquired within the given amount of time, then this method
01274    * returns -1 with an @c ETIME errno on platforms that actually
01275    * support timed mutexes.  The timeout should be an absolute time.
01276    * Note that the mutex should not be a recursive one, i.e., it
01277    * should only be a standard mutex or an error checking mutex since
01278    * some implementations of this method don't support recursive
01279    * mutexes.  If you want to use a recursive mutex see the methods
01280    * below.
01281    */
01282   extern ACE_Export
01283   int mutex_lock (ACE_mutex_t *m,
01284                   const ACE_Time_Value &timeout);
01285 
01286   /**
01287    * If <timeout> == 0, calls <ACE_OS::mutex_lock(m)>.  Otherwise,
01288    * this method attempts to acquire a lock, but gives up if the lock
01289    * has not been acquired by the given time, in which case it returns
01290    * -1 with an @c ETIME errno on platforms that actually support timed
01291    * mutexes.  The timeout should be an absolute time.  Note that the
01292    * mutex should not be a recursive one, i.e., it should only be a
01293    * standard mutex or an error checking mutex since some
01294    * implementations of this method don't support recursive mutexes.
01295    * If you want to use a recursive mutex see the methods below.
01296    */
01297   ACE_NAMESPACE_INLINE_FUNCTION
01298   int mutex_lock (ACE_mutex_t *m,
01299                   const ACE_Time_Value *timeout);
01300 
01301   /// Handle asynchronous thread cancellation cleanup.
01302   extern ACE_Export
01303   void mutex_lock_cleanup (void *mutex);
01304 
01305   /// Win32 note: Abandoned mutexes are not treated differently. 0 is
01306   /// returned since the calling thread does get the ownership.
01307   extern ACE_Export
01308   int mutex_trylock (ACE_mutex_t *m);
01309 
01310   /// This method is only implemented for Win32.  For abandoned
01311   /// mutexes, <abandoned> is set to 1 and 0 is returned.
01312   extern ACE_Export
01313   int mutex_trylock (ACE_mutex_t *m,
01314                      int &abandoned);
01315 
01316   extern ACE_Export
01317   int mutex_unlock (ACE_mutex_t *m);
01318 
01319   //@}
01320 
01321   /// Low-level interface to <priocntl>(2).
01322   /**
01323    * Can't call the following priocntl, because that's a macro on
01324    * Solaris.
01325    */
01326   ACE_NAMESPACE_INLINE_FUNCTION
01327   long priority_control (ACE_idtype_t, ACE_id_t, int, void *);
01328 
01329   //@{ @name A set of wrappers for recursive mutex locks.
01330 
01331   // These two methods are primarily in support of
01332   // ACE_Condition<ACE_Recursive_Thread_Mutex> and should probably not
01333   // be called outside that context.
01334   ACE_NAMESPACE_INLINE_FUNCTION
01335   int recursive_mutex_cond_unlock (ACE_recursive_thread_mutex_t *m,
01336                                    ACE_recursive_mutex_state &state);
01337 
01338   ACE_NAMESPACE_INLINE_FUNCTION
01339   void recursive_mutex_cond_relock (ACE_recursive_thread_mutex_t *m,
01340                                     ACE_recursive_mutex_state &state);
01341 
01342   ACE_NAMESPACE_INLINE_FUNCTION
01343   int recursive_mutex_destroy (ACE_recursive_thread_mutex_t *m);
01344 
01345   ACE_NAMESPACE_INLINE_FUNCTION
01346   int recursive_mutex_init (ACE_recursive_thread_mutex_t *m,
01347                             const ACE_TCHAR *name = 0,
01348                             ACE_mutexattr_t *arg = 0,
01349                             LPSECURITY_ATTRIBUTES sa = 0);
01350 
01351   ACE_NAMESPACE_INLINE_FUNCTION
01352   int recursive_mutex_lock (ACE_recursive_thread_mutex_t *m);
01353 
01354   ACE_NAMESPACE_INLINE_FUNCTION
01355   int recursive_mutex_lock (ACE_recursive_thread_mutex_t *m,
01356                             const ACE_Time_Value &timeout);
01357 
01358   ACE_NAMESPACE_INLINE_FUNCTION
01359   int recursive_mutex_lock (ACE_recursive_thread_mutex_t *m,
01360                             const ACE_Time_Value *timeout);
01361 
01362   ACE_NAMESPACE_INLINE_FUNCTION
01363   int recursive_mutex_trylock (ACE_recursive_thread_mutex_t *m);
01364 
01365   ACE_NAMESPACE_INLINE_FUNCTION
01366   int recursive_mutex_unlock (ACE_recursive_thread_mutex_t *m);
01367 
01368   //@}
01369 
01370 
01371   //@{ @name A set of wrappers for readers/writer locks.
01372 
01373   ACE_NAMESPACE_INLINE_FUNCTION
01374   int rw_rdlock (ACE_rwlock_t *rw);
01375 
01376   ACE_NAMESPACE_INLINE_FUNCTION
01377   int rw_tryrdlock (ACE_rwlock_t *rw);
01378 
01379   ACE_NAMESPACE_INLINE_FUNCTION
01380   int rw_trywrlock (ACE_rwlock_t *rw);
01381 
01382   ACE_NAMESPACE_INLINE_FUNCTION
01383   int rw_trywrlock_upgrade (ACE_rwlock_t *rw);
01384 
01385   ACE_NAMESPACE_INLINE_FUNCTION
01386   int rw_unlock (ACE_rwlock_t *rw);
01387 
01388   ACE_NAMESPACE_INLINE_FUNCTION
01389   int rw_wrlock (ACE_rwlock_t *rw);
01390 
01391   ACE_NAMESPACE_INLINE_FUNCTION
01392   int rwlock_destroy (ACE_rwlock_t *rw);
01393 
01394   extern ACE_Export
01395   int rwlock_init (ACE_rwlock_t *rw,
01396                    int type = ACE_DEFAULT_SYNCH_TYPE,
01397                    const ACE_TCHAR *name = 0,
01398                    void *arg = 0);
01399 
01400   //@}
01401 
01402   //@{ @name Thread scheduler interface.
01403   /// Set scheduling parameters.  An id of ACE_SELF indicates, e.g.,
01404   /// set the parameters on the calling thread.
01405   extern ACE_Export
01406   int sched_params (const ACE_Sched_Params &, ACE_id_t id = ACE_SELF);
01407   //@}
01408 
01409   /// Find the schedling class ID that corresponds to the class name.
01410   extern ACE_Export
01411   int scheduling_class (const char *class_name, ACE_id_t &);
01412 
01413   //@{ @name A set of wrappers for semaphores.
01414 
01415   ACE_NAMESPACE_INLINE_FUNCTION
01416   int sema_destroy (ACE_sema_t *s);
01417 
01418   ACE_NAMESPACE_INLINE_FUNCTION
01419   int sema_init (ACE_sema_t *s,
01420                  u_int count,
01421                  int type = ACE_DEFAULT_SYNCH_TYPE,
01422                  const char *name = 0,
01423                  void *arg = 0,
01424                  int max = 0x7fffffff,
01425                  LPSECURITY_ATTRIBUTES sa = 0);
01426 
01427 # if defined (ACE_HAS_WCHAR)
01428   ACE_NAMESPACE_INLINE_FUNCTION
01429   int sema_init (ACE_sema_t *s,
01430                  u_int count,
01431                  int type,
01432                  const wchar_t *name,
01433                  void *arg = 0,
01434                  int max = 0x7fffffff,
01435                  LPSECURITY_ATTRIBUTES sa = 0);
01436 # endif /* ACE_HAS_WCHAR */
01437 
01438   ACE_NAMESPACE_INLINE_FUNCTION
01439   int sema_post (ACE_sema_t *s);
01440 
01441   ACE_NAMESPACE_INLINE_FUNCTION
01442   int sema_post (ACE_sema_t *s,
01443                  u_int release_count);
01444 
01445   ACE_NAMESPACE_INLINE_FUNCTION
01446   int sema_trywait (ACE_sema_t *s);
01447 
01448   ACE_NAMESPACE_INLINE_FUNCTION
01449   int sema_wait (ACE_sema_t *s);
01450 
01451   ACE_NAMESPACE_INLINE_FUNCTION
01452   int sema_wait (ACE_sema_t *s,
01453                  ACE_Time_Value &tv);
01454 
01455   ACE_NAMESPACE_INLINE_FUNCTION
01456   int sema_wait (ACE_sema_t *s,
01457                  ACE_Time_Value *tv);
01458   //@}
01459 
01460   //@{ @name A set of wrappers for System V semaphores.
01461   ACE_NAMESPACE_INLINE_FUNCTION
01462   int semctl (int int_id,
01463               int semnum,
01464               int cmd,
01465               semun);
01466 
01467   ACE_NAMESPACE_INLINE_FUNCTION
01468   int semget (key_t key,
01469               int nsems,
01470               int flags);
01471 
01472   ACE_NAMESPACE_INLINE_FUNCTION
01473   int semop (int int_id,
01474              struct sembuf *sops,
01475              size_t nsops);
01476   //@}
01477 
01478   /// Friendly interface to <priocntl>(2).
01479   extern ACE_Export
01480   int set_scheduling_params (const ACE_Sched_Params &,
01481                              ACE_id_t id = ACE_SELF);
01482 
01483   ACE_NAMESPACE_INLINE_FUNCTION
01484   int sigtimedwait (const sigset_t *set,
01485                     siginfo_t *info,
01486                     const ACE_Time_Value *timeout);
01487 
01488   ACE_NAMESPACE_INLINE_FUNCTION
01489   int sigwait (sigset_t *set,
01490                int *sig = 0);
01491 
01492   ACE_NAMESPACE_INLINE_FUNCTION
01493   int sigwaitinfo (const sigset_t *set,
01494                    siginfo_t *info);
01495 
01496   ACE_NAMESPACE_INLINE_FUNCTION
01497   int thr_cancel (ACE_thread_t t_id);
01498 
01499   ACE_NAMESPACE_INLINE_FUNCTION
01500   int thr_cmp (ACE_hthread_t t1,
01501                ACE_hthread_t t2);
01502 
01503   // These are non-portable since they use ACE_thread_t and
01504   // ACE_hthread_t and will go away in a future release.
01505   ACE_NAMESPACE_INLINE_FUNCTION
01506   int thr_continue (ACE_hthread_t target_thread);
01507 
01508   /*
01509    * Creates a new thread having @a flags attributes and running @a func
01510    * with @a args (if @a thread_adapter is non-0 then @a func and @a args
01511    * are ignored and are obtained from @a thread_adapter).  @a thr_id
01512    * and @a t_handle are set to the thread's ID and handle (?),
01513    * respectively.  The thread runs at @a priority priority (see
01514    * below).
01515    *
01516    * The @a flags are a bitwise-OR of the following:
01517    * = BEGIN<INDENT>
01518    * THR_CANCEL_DISABLE, THR_CANCEL_ENABLE, THR_CANCEL_DEFERRED,
01519    * THR_CANCEL_ASYNCHRONOUS, THR_BOUND, THR_NEW_LWP, THR_DETACHED,
01520    * THR_SUSPENDED, THR_DAEMON, THR_JOINABLE, THR_SCHED_FIFO,
01521    * THR_SCHED_RR, THR_SCHED_DEFAULT, THR_EXPLICIT_SCHED,
01522    * THR_SCOPE_SYSTEM, THR_SCOPE_PROCESS
01523    * = END<INDENT>
01524    *
01525    * By default, or if @a priority is set to
01526    * ACE_DEFAULT_THREAD_PRIORITY, an "appropriate" priority value for
01527    * the given scheduling policy (specified in @a flags, e.g.,
01528    * @c THR_SCHED_DEFAULT) is used.  This value is calculated
01529    * dynamically, and is the median value between the minimum and
01530    * maximum priority values for the given policy.  If an explicit
01531    * value is given, it is used.  Note that actual priority values are
01532    * EXTREMEMLY implementation-dependent, and are probably best
01533    * avoided.
01534    *
01535    * Note that @a thread_adapter is always deleted by @c thr_create,
01536    * therefore it must be allocated with global operator new.
01537    *
01538    * At the moment for @a thr_name a valid string is passed then this
01539    * will be used on VxWorks to set the task name. If we just pass a pointer
01540    * the name of the task is returned
01541    */
01542   extern ACE_Export
01543   int thr_create (ACE_THR_FUNC func,
01544                   void *args,
01545                   long flags,
01546                   ACE_thread_t *thr_id,
01547                   ACE_hthread_t *t_handle = 0,
01548                   long priority = ACE_DEFAULT_THREAD_PRIORITY,
01549                   void *stack = 0,
01550                   size_t stacksize = ACE_DEFAULT_THREAD_STACKSIZE,
01551                   ACE_Base_Thread_Adapter *thread_adapter = 0,
01552                   const char** thr_name = 0);
01553 
01554   ACE_NAMESPACE_INLINE_FUNCTION
01555   int thr_equal (ACE_thread_t t1,
01556                  ACE_thread_t t2);
01557 
01558   extern ACE_Export
01559   void thr_exit (ACE_THR_FUNC_RETURN status = 0);
01560 
01561   ACE_NAMESPACE_INLINE_FUNCTION
01562   int thr_getconcurrency (void);
01563 
01564   ACE_NAMESPACE_INLINE_FUNCTION
01565   int thr_getprio (ACE_hthread_t id,
01566                    int &priority);
01567 
01568   ACE_NAMESPACE_INLINE_FUNCTION
01569   int thr_getprio (ACE_hthread_t id,
01570                    int &priority,
01571                    int &policy);
01572 
01573 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
01574   ACE_NAMESPACE_INLINE_FUNCTION
01575   /// for internal use only.  Applications should call thr_getspecific
01576   int thr_getspecific_native (ACE_OS_thread_key_t key,
01577                               void **data);
01578 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
01579 
01580   ACE_NAMESPACE_INLINE_FUNCTION
01581   int thr_getspecific (ACE_thread_key_t key,
01582                        void **data);
01583 
01584 #if defined (ACE_HAS_VXTHREADS)
01585   extern ACE_Export
01586 #else
01587   ACE_NAMESPACE_INLINE_FUNCTION
01588 #endif /* ACE_HAS_VXTHREADS */
01589   int thr_join (ACE_hthread_t waiter_id,
01590                 ACE_THR_FUNC_RETURN *status);
01591 
01592 #if defined (ACE_HAS_VXTHREADS)
01593   extern ACE_Export
01594 #else
01595   ACE_NAMESPACE_INLINE_FUNCTION
01596 #endif /* ACE_HAS_VXTHREADS */
01597   int thr_join (ACE_thread_t waiter_id,
01598                 ACE_thread_t *thr_id,
01599                 ACE_THR_FUNC_RETURN *status);
01600 
01601   /**
01602    * Get the thread affinity
01603    *
01604    * @param thr_id For NPTL-threads, when ACE_HAS_PTHREAD_SETAFFINITY_NP
01605    * defined, this is the thread-id. For linux-threads, when
01606    * ACE_HAS_SCHED_SETAFFINITY defined, it expects a process-id. Since for
01607    * linux-threads a thread is seen as a process, it does the job.
01608    * @param cpu_set_size The size of the cpu_mask
01609    * @param cpu_mask Is a bitmask of CPUs to bind to, e.g value 1 binds the
01610    * thread to the "CPU 0", etc
01611    */
01612   extern ACE_Export
01613   int thr_get_affinity (ACE_hthread_t thr_id,
01614                         size_t cpu_set_size,
01615                         cpu_set_t * cpu_mask);
01616 
01617 
01618   /**
01619    * Set the thread affinity
01620    *
01621    * @param thr_id For NPTL-threads, when ACE_HAS_PTHREAD_SETAFFINITY_NP
01622    * defined, this is the thread-id. For linux-threads, when
01623    * ACE_HAS_SCHED_SETAFFINITY defined, it expects a process-id. Since for
01624    * linux-threads a thread is seen as a process, it does the job.
01625    * @param cpu_set_size The size of the cpu_mask
01626    * @param cpu_mask Is a bitmask of CPUs to bind to, e.g value 1 binds the
01627    * thread to the "CPU 0", etc
01628    */
01629   extern ACE_Export
01630   int thr_set_affinity (ACE_hthread_t thr_id,
01631                         size_t cpu_set_size,
01632                         const cpu_set_t * cpu_mask);
01633 
01634   /**
01635    * @note the "inst" arg is deprecated.  It will be ignored.
01636    */
01637   extern ACE_Export
01638   int thr_key_detach (ACE_thread_key_t key, void * inst);
01639 
01640   extern ACE_Export
01641   int thr_key_used (ACE_thread_key_t key);
01642 
01643 # if defined (ACE_HAS_THR_C_DEST)
01644 #   if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
01645   /// @internal Applications should call thr_keycreate
01646   extern ACE_Export
01647   int thr_keycreate_native (ACE_OS_thread_key_t *key,
01648                      ACE_THR_C_DEST);
01649 #   endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
01650 
01651   /**
01652    * @note the "inst" arge is deprecated.  It will be ignored.
01653    */
01654   extern ACE_Export
01655   int thr_keycreate (ACE_thread_key_t *key,
01656                      ACE_THR_C_DEST,
01657                      void *inst = 0);
01658 # else
01659 #   if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
01660   /// @internal Applications should call thr_keycreate instead
01661   extern ACE_Export
01662   int thr_keycreate_native (ACE_OS_thread_key_t *key,
01663                      ACE_THR_DEST);
01664 #   endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
01665   /**
01666    * @note the "inst" arge is deprecated.  It will be ignored.
01667    */
01668   extern ACE_Export
01669   int thr_keycreate (ACE_thread_key_t *key,
01670                      ACE_THR_DEST,
01671                      void *inst = 0);
01672 
01673 # endif /* ACE_HAS_THR_C_DEST */
01674 
01675 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
01676   /// @internal Applications should call thr_keyfree instead
01677   extern ACE_Export
01678   int thr_keyfree_native (ACE_OS_thread_key_t key);
01679 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
01680 
01681   extern ACE_Export
01682   int thr_keyfree (ACE_thread_key_t key);
01683 
01684   ACE_NAMESPACE_INLINE_FUNCTION
01685   int thr_kill (ACE_thread_t thr_id,
01686                 int signum);
01687 
01688   ACE_NAMESPACE_INLINE_FUNCTION
01689   size_t thr_min_stack (void);
01690 
01691   ACE_NAMESPACE_INLINE_FUNCTION
01692   ACE_thread_t thr_self (void);
01693 
01694   ACE_NAMESPACE_INLINE_FUNCTION
01695   void thr_self (ACE_hthread_t &);
01696 
01697   ACE_NAMESPACE_INLINE_FUNCTION
01698   const char* thr_name (void);
01699 
01700   ACE_NAMESPACE_INLINE_FUNCTION
01701   int thr_setcancelstate (int new_state,
01702                           int *old_state);
01703 
01704   ACE_NAMESPACE_INLINE_FUNCTION
01705   int thr_setcanceltype (int new_type,
01706                          int *old_type);
01707 
01708   ACE_NAMESPACE_INLINE_FUNCTION
01709   int thr_setconcurrency (int hint);
01710 
01711   ACE_NAMESPACE_INLINE_FUNCTION
01712   int thr_setprio (ACE_hthread_t ht_id,
01713                    int priority,
01714                    int policy = -1);
01715 
01716   extern ACE_Export
01717   int thr_setprio (const ACE_Sched_Priority prio);
01718 
01719 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
01720   /// @internal Applications should call thr_setspecific
01721   extern ACE_Export
01722   int thr_setspecific_native (ACE_OS_thread_key_t key,
01723                               void *data);
01724 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
01725 
01726   extern ACE_Export
01727   int thr_setspecific (ACE_thread_key_t key,
01728                        void *data);
01729 
01730   ACE_NAMESPACE_INLINE_FUNCTION
01731   int thr_sigsetmask (int how,
01732                       const sigset_t *nsm,
01733                       sigset_t *osm);
01734 
01735   ACE_NAMESPACE_INLINE_FUNCTION
01736   int thr_suspend (ACE_hthread_t target_thread);
01737 
01738   ACE_NAMESPACE_INLINE_FUNCTION
01739   void thr_testcancel (void);
01740 
01741   ACE_NAMESPACE_INLINE_FUNCTION
01742   void thr_yield (void);
01743 
01744   //@{ @name A set of wrappers for mutex locks that only work within a single process.
01745 
01746   ACE_NAMESPACE_INLINE_FUNCTION
01747   int thread_mutex_destroy (ACE_thread_mutex_t *m);
01748 
01749   ACE_NAMESPACE_INLINE_FUNCTION
01750   int thread_mutex_init (ACE_thread_mutex_t *m,
01751                          int lock_type = 0,
01752                          const char *name = 0,
01753                          ACE_mutexattr_t *arg = 0);
01754 
01755 #if defined (ACE_HAS_WCHAR)
01756   ACE_NAMESPACE_INLINE_FUNCTION
01757   int thread_mutex_init (ACE_thread_mutex_t *m,
01758                          int lock_type,
01759                          const wchar_t *name,
01760                          ACE_mutexattr_t *arg = 0);
01761 #endif /* ACE_HAS_WCHAR */
01762 
01763   ACE_NAMESPACE_INLINE_FUNCTION
01764   int thread_mutex_lock (ACE_thread_mutex_t *m);
01765 
01766   ACE_NAMESPACE_INLINE_FUNCTION
01767   int thread_mutex_lock (ACE_thread_mutex_t *m,
01768                          const ACE_Time_Value &timeout);
01769 
01770   ACE_NAMESPACE_INLINE_FUNCTION
01771   int thread_mutex_lock (ACE_thread_mutex_t *m,
01772                          const ACE_Time_Value *timeout);
01773 
01774   ACE_NAMESPACE_INLINE_FUNCTION
01775   int thread_mutex_trylock (ACE_thread_mutex_t *m);
01776 
01777   ACE_NAMESPACE_INLINE_FUNCTION
01778   int thread_mutex_unlock (ACE_thread_mutex_t *m);
01779 
01780   //@}
01781 
01782   /**
01783    * This method uses process id and object pointer to come up with a
01784    * machine wide unique name.  The process ID will provide uniqueness
01785    * between processes on the same machine. The "this" pointer of the
01786    * @a object will provide uniqueness between other "live" objects in
01787    * the same process. The uniqueness of this name is therefore only
01788    * valid for the life of @a object.
01789    */
01790   extern ACE_Export
01791   void unique_name (const void *object,
01792                     char *name,
01793                     size_t length);
01794 #if defined (ACE_USES_WCHAR)
01795   extern ACE_Export
01796   void unique_name (const void *object,
01797                     wchar_t *name,
01798                     size_t length);
01799 #endif /* ACE_USES_WCHAR */
01800 } /* namespace ACE_OS */
01801 
01802 ACE_END_VERSIONED_NAMESPACE_DECL
01803 
01804 #if !defined (ACE_WIN32)
01805 
01806 extern "C"
01807 {
01808   typedef struct
01809   {
01810 #if (defined (ACE_HAS_PTHREADS) && defined (_POSIX_THREAD_PROCESS_SHARED) && !defined (ACE_LACKS_CONDATTR_PSHARED)) || \
01811     (!defined (ACE_USES_FIFO_SEM) && \
01812       (!defined (ACE_HAS_POSIX_SEM) || !defined (ACE_HAS_POSIX_SEM_TIMEOUT) || defined (ACE_LACKS_NAMED_POSIX_SEM)))
01813     /// Protect critical section.
01814     ACE_mutex_t lock_;
01815     /// Keeps track of waiters.
01816     ACE_cond_t condition_;
01817 #else
01818 # if (defined (ACE_HAS_PTHREADS) && defined (_POSIX_THREAD_PROCESS_SHARED) && !defined (ACE_LACKS_MUTEXATTR_PSHARED)) || \
01819      (!defined (ACE_USES_FIFO_SEM) && (!defined (ACE_HAS_POSIX_SEM) || defined (ACE_LACKS_NAMED_POSIX_SEM)))
01820     /// Protect critical section.
01821     ACE_mutex_t lock_;
01822 # endif
01823 #endif
01824 
01825     /// Object type.
01826     int type_;
01827 
01828     /// Specifies if this is an auto- or manual-reset event.
01829     int manual_reset_;
01830 
01831     /// "True" if signaled.
01832     int is_signaled_;
01833 
01834     /// Special bool for auto_events alone
01835     /**
01836      * The semantics of auto events forces us to introduce this extra
01837      * variable to ensure that the thread is not woken up
01838      * spuriously. Please see event_wait and event_timedwait () to see
01839      * how this is used for auto_events.
01840      * @todo This is a hack that needs revisiting after x.4
01841      */
01842     bool auto_event_signaled_;
01843 
01844     /// Number of waiting threads.
01845     unsigned long waiting_threads_;
01846 
01847     /// Signal count
01848     unsigned long signal_count_;
01849   } ACE_eventdata_t;
01850 }
01851 
01852 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
01853 
01854 /**
01855  * @class ACE_event_t
01856  *
01857  * @brief Wrapper for NT events on UNIX.
01858  */
01859 class ACE_Export ACE_event_t
01860 {
01861   friend int ACE_OS::event_init(ACE_event_t*, int, int, int, const char*, void*,int);
01862   friend int ACE_OS::event_destroy(ACE_event_t*);
01863   friend int ACE_OS::event_wait(ACE_event_t*);
01864   friend int ACE_OS::event_timedwait(ACE_event_t*, ACE_Time_Value*, int);
01865   friend int ACE_OS::event_signal(ACE_event_t*);
01866   friend int ACE_OS::event_pulse(ACE_event_t*);
01867   friend int ACE_OS::event_reset(ACE_event_t*);
01868 protected:
01869 
01870   /// Event name if process shared.
01871   char* name_;
01872 
01873   /// Event data
01874   ACE_eventdata_t* eventdata_;
01875 
01876 #if (!defined (ACE_HAS_PTHREADS) || !defined (_POSIX_THREAD_PROCESS_SHARED) || defined (ACE_LACKS_CONDATTR_PSHARED)) && \
01877   (defined (ACE_USES_FIFO_SEM) || \
01878     (defined (ACE_HAS_POSIX_SEM) && defined (ACE_HAS_POSIX_SEM_TIMEOUT) && !defined (ACE_LACKS_NAMED_POSIX_SEM)))
01879   /// Keeps track of waiters.
01880   ACE_sema_t semaphore_;
01881 
01882 # if (!defined (ACE_HAS_PTHREADS) || !defined (_POSIX_THREAD_PROCESS_SHARED) || defined (ACE_LACKS_MUTEXATTR_PSHARED)) && \
01883      (defined (ACE_USES_FIFO_SEM) || (defined (ACE_HAS_POSIX_SEM) && !defined (ACE_LACKS_NAMED_POSIX_SEM)))
01884     /// Protect critical section.
01885   ACE_sema_t lock_;
01886 # endif
01887 #endif
01888 };
01889 
01890 ACE_END_VERSIONED_NAMESPACE_DECL
01891 
01892 #endif /* ACE_WIN32 */
01893 
01894 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
01895 
01896 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
01897 
01898 /**
01899  * @class ACE_OS_Thread_Mutex_Guard
01900  *
01901  * This data structure is meant to be used within an ACE_OS
01902  * function.  It performs automatic aquisition and release of
01903  * an ACE_thread_mutex_t.
01904  *
01905  * If an object of this class is instantiated before ACE_Object_Manager is
01906  * initialized, it will not do anything. This is because this class is
01907  * used only with the ACE_OS_GUARD macro which is passing a reference to
01908  * one of the preallocated Object Manager locks. If the object manager
01909  * hasn't been initialized yet, the lock reference is bogus. This is an
01910  * acceptable tradeoff since in cases where the lock reference is bogus,
01911  * there isn't multithreaded access. Please see detailed comments in
01912  * Object_Manager.h for further information.
01913  *
01914  * For internal use only by ACE_OS.
01915  */
01916 class ACE_OS_Thread_Mutex_Guard
01917 {
01918 public:
01919   /// Implicitly and automatically acquire the lock.
01920   ACE_OS_Thread_Mutex_Guard (ACE_thread_mutex_t &m);
01921 
01922   /// Implicitly release the lock.
01923   ~ACE_OS_Thread_Mutex_Guard (void);
01924 
01925   /// Explicitly acquire the lock.
01926   int acquire (void);
01927 
01928   /// Explicitly release the lock.
01929   int release (void);
01930 
01931 protected:
01932   /// Reference to the mutex.
01933   ACE_thread_mutex_t &lock_;
01934 
01935   /// Keeps track of whether we acquired the lock or failed.
01936   int owner_;
01937 
01938   // = Prevent assignment and initialization.
01939   ACE_OS_Thread_Mutex_Guard &operator= (const ACE_OS_Thread_Mutex_Guard &);
01940   ACE_OS_Thread_Mutex_Guard (const ACE_OS_Thread_Mutex_Guard &);
01941 };
01942 
01943 /**
01944  * @class ACE_OS_Recursive_Thread_Mutex_Guard
01945  *
01946  * @brief For internal use only by ACE_OS.
01947  *
01948  * This data structure is meant to be used within an ACE_OS
01949  * function.  It performs automatic aquisition and release of
01950  * an ACE_recursive_thread_mutex_t.
01951  *
01952  * If an object of this class is instantiated before ACE_Object_Manager is
01953  * initialized, it will not do anything. This is because this class is
01954  * used only with the ACE_TSS_GUARD macro which is passing a reference to
01955  * one of the preallocated Object Manager locks. If the object manager
01956  * hasn't been initialized yet, the lock reference is bogus. This is an
01957  * acceptable tradeoff since in cases where the lock reference is bogus,
01958  * there isn't multithreaded access. Please see detailed comments in
01959  * Object_Manager.h for further information.
01960  */
01961 class ACE_OS_Recursive_Thread_Mutex_Guard
01962 {
01963 public:
01964   /// Implicitly and automatically acquire the lock.
01965   ACE_OS_Recursive_Thread_Mutex_Guard (ACE_recursive_thread_mutex_t &m);
01966 
01967   /// Implicitly release the lock.
01968   ~ACE_OS_Recursive_Thread_Mutex_Guard (void);
01969 
01970   /// Explicitly acquire the lock.
01971   int acquire (void);
01972 
01973   /// Explicitly release the lock.
01974   int release (void);
01975 
01976 protected:
01977   /// Reference to the mutex.
01978   ACE_recursive_thread_mutex_t &lock_;
01979 
01980   /// Keeps track of whether we acquired the lock or failed.
01981   int owner_;
01982 
01983   // = Prevent assignment and initialization.
01984   ACE_OS_Recursive_Thread_Mutex_Guard &operator= (
01985     const ACE_OS_Recursive_Thread_Mutex_Guard &);
01986   ACE_OS_Recursive_Thread_Mutex_Guard (
01987     const ACE_OS_Recursive_Thread_Mutex_Guard &);
01988 };
01989 
01990 ACE_END_VERSIONED_NAMESPACE_DECL
01991 
01992 // used in time and unistd
01993 # define ACE_OS_GUARD \
01994   ACE_OS_Thread_Mutex_Guard ace_os_guard__ (*(ACE_thread_mutex_t *) \
01995     ACE_OS_Object_Manager::preallocated_object[ \
01996       ACE_OS_Object_Manager::ACE_OS_MONITOR_LOCK]);
01997 
01998 // used in Thread
01999 # define ACE_TSS_CLEANUP_GUARD \
02000   ACE_OS_Recursive_Thread_Mutex_Guard ace_tss_cleanup_guard__ (*(ACE_recursive_thread_mutex_t *) \
02001     ACE_OS_Object_Manager::preallocated_object[ \
02002       ACE_OS_Object_Manager::ACE_TSS_CLEANUP_LOCK]);
02003 
02004 // used in Thread
02005 # define ACE_TSS_BASE_GUARD \
02006   ACE_OS_Recursive_Thread_Mutex_Guard ace_tss_base_guard__ (*(ACE_recursive_thread_mutex_t *) \
02007     ACE_OS_Object_Manager::preallocated_object[ \
02008       ACE_OS_Object_Manager::ACE_TSS_BASE_LOCK]);
02009 
02010 #else  /* ! ACE_MT_SAFE */
02011 # define ACE_OS_GUARD
02012 # define ACE_TSS_CLEANUP_GUARD
02013 # define ACE_TSS_BASE_GUARD
02014 #endif /* ! ACE_MT_SAFE */
02015 
02016 # if defined (ACE_HAS_INLINED_OSCALLS)
02017 #   if defined (ACE_INLINE)
02018 #     undef ACE_INLINE
02019 #   endif /* ACE_INLINE */
02020 #   define ACE_INLINE inline
02021 #   include "ace/OS_NS_Thread.inl"
02022 # endif /* ACE_HAS_INLINED_OSCALLS */
02023 
02024 # include /**/ "ace/post.h"
02025 #endif /* ACE_OS_NS_THREAD_H */

Generated on Tue Feb 2 17:18:41 2010 for ACE by  doxygen 1.4.7