3 //==========================================================================
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //==========================================================================
11 #ifndef ACE_CONDITION_T_H
12 #define ACE_CONDITION_T_H
14 #include /**/ "ace/pre.h"
16 #include "ace/OS_NS_Thread.h"
17 #include "ace/Condition_Attributes.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #if defined (ACE_HAS_THREADS) /* ACE platform supports some form of threading. */
25 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 * @class ACE_Condition
32 * @brief ACE_Condition variable wrapper, which allows threads to block
33 * until shared data changes state.
35 * A condition variable enables threads to atomically block and
36 * test the condition under the protection of a mutual exclusion
37 * lock (mutex) until the condition is satisfied. That is,
38 * the mutex must have been held by the thread before calling
39 * wait or signal on the condition. If the condition is false,
40 * a thread blocks on a condition variable and atomically
41 * releases the mutex that is waiting for the condition to
42 * change. If another thread changes the condition, it may wake
43 * up waiting threads by signaling the associated condition
44 * variable. The waiting threads, upon awakening, reacquire the
45 * mutex and re-evaluate the condition.
46 * Note, you can only parameterize <ACE_Condition> with
47 * @a ACE_Thread_Mutex, @a ACE_Recursive_Thread_Mutex, or @a ACE_Null_Mutex.
49 template <class MUTEX
>
53 /// Initialize the condition variable.
54 ACE_Condition (MUTEX
&m
, int type
= USYNC_THREAD
,
55 const ACE_TCHAR
*name
= 0, void *arg
= 0);
57 /// Initialize the condition variable.
58 ACE_Condition (MUTEX
&m
,
59 const ACE_Condition_Attributes
&attributes
,
60 const ACE_TCHAR
*name
= 0,
63 /// Implicitly destroy the condition variable.
68 * Block on condition, or until absolute time-of-day has passed. If
69 * @a abstime == 0 use "blocking" <wait> semantics. Else, if @a abstime
70 * != 0 and the call times out before the condition is signaled
71 * wait() returns -1 and sets errno to ETIME.
73 int wait (const ACE_Time_Value
*abstime
);
75 /// Block on condition.
79 * Block on condition or until absolute time-of-day has passed. If
80 * @a abstime == 0 use "blocking" wait() semantics on the @a mutex
81 * passed as a parameter (this is useful if you need to store the
82 * <Condition> in shared memory). Else, if @a abstime != 0 and the
83 * call times out before the condition is signaled wait() returns -1
84 * and sets errno to ETIME.
86 int wait (MUTEX
&mutex
, const ACE_Time_Value
*abstime
= 0);
88 /// Signal one waiting thread.
91 /// Signal *all* waiting threads.
95 /// Explicitly destroy the condition variable.
98 /// Returns a reference to the underlying mutex_;
101 /// Dump the state of an object.
104 /// Declare the dynamic allocation hooks.
105 ACE_ALLOC_HOOK_DECLARE
;
108 /// Condition variable.
111 /// Reference to mutex lock.
115 void operator= (const ACE_Condition
<MUTEX
> &) = delete;
116 ACE_Condition (const ACE_Condition
<MUTEX
> &) = delete;
120 * @class ACE_Thread_Condition
122 * @brief ACE_Condition variable wrapper that works within processes.
124 * A condition variable enables threads to atomically block and
125 * test the condition under the protection of a mutual exclu-
126 * sion lock (mutex) until the condition is satisfied. That is,
127 * the mutex must have been held by the thread before calling
128 * wait or signal on the condition. If the condition is false,
129 * a thread blocks on a condition variable and atomically
130 * releases the mutex that is waiting for the condition to
131 * change. If another thread changes the condition, it may wake
132 * up waiting threads by signaling the associated condition
133 * variable. The waiting threads, upon awakening, reacquire the
134 * mutex and re-evaluate the condition.
136 template <class MUTEX
>
137 class ACE_Thread_Condition
: public ACE_Condition
<MUTEX
>
140 ACE_Thread_Condition (MUTEX
&m
, const ACE_TCHAR
*name
= 0, void *arg
= 0);
142 /// Dump the state of an object.
145 /// Declare the dynamic allocation hooks.
146 ACE_ALLOC_HOOK_DECLARE
;
149 ACE_END_VERSIONED_NAMESPACE_DECL
151 #if defined (__ACE_INLINE__)
152 #include "ace/Condition_T.inl"
153 #endif /* __ACE_INLINE__ */
155 #include "ace/Condition_T.cpp"
157 #endif /* ACE_HAS_THREADS */
159 #include /**/ "ace/post.h"
160 #endif /* ACE_CONDITION_T_H */