3 //==========================================================================
5 * @file Condition_Thread_Mutex.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //==========================================================================
11 #ifndef ACE_CONDITION_THREAD_MUTEX_H
12 #define ACE_CONDITION_THREAD_MUTEX_H
13 #include /**/ "ace/pre.h"
15 #include /**/ "ace/ACE_export.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #if !defined (ACE_HAS_THREADS)
22 # include "ace/Null_Condition.h"
23 #else /* ACE_HAS_THREADS */
24 // ACE platform supports some form of threading.
26 #include "ace/Thread_Mutex.h"
27 #include "ace/Condition_Attributes.h"
28 #include "ace/Condition_T.h"
30 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
35 * @brief ACE_Condition template specialization written using
36 * ACE_Mutexes. This allows threads to block until shared data
38 * A condition variable enables threads to atomically block and
39 * test the condition under the protection of a mutual exclu-
40 * sion lock (mutex) until the condition is satisfied. That is,
41 * the mutex must have been held by the thread before calling
42 * wait or signal on the condition. If the condition is false,
43 * a thread blocks on a condition variable and atomically
44 * releases the mutex that is waiting for the condition to
45 * change. If another thread changes the condition, it may wake
46 * up waiting threads by signaling the associated condition
47 * variable. The waiting threads, upon awakening, reacquire the
48 * mutex and re-evaluate the condition.
51 class ACE_Export ACE_Condition
<ACE_Thread_Mutex
>
54 /// Initialize the condition variable.
55 ACE_Condition (ACE_Thread_Mutex
&m
,
56 const ACE_TCHAR
*name
= 0,
59 /// Initialize the condition variable.
60 ACE_Condition (ACE_Thread_Mutex
&m
,
61 const ACE_Condition_Attributes
&attributes
,
62 const ACE_TCHAR
*name
= 0,
65 /// Implicitly destroy the condition variable.
69 * Explicitly destroy the condition variable. Note that only one
70 * thread should call this method since it doesn't protect against
76 * Block on condition, or until absolute time-of-day has passed. If
77 * abstime == 0 use "blocking" wait semantics. Else, if @a abstime
78 * != 0 and the call times out before the condition is signaled
79 * wait() returns -1 and sets errno to ETIME.
81 int wait (const ACE_Time_Value
*abstime
);
83 /// Block on condition.
87 * Block on condition or until absolute time-of-day has passed. If
88 * abstime == 0 use "blocking" wait() semantics on the @a mutex
89 * passed as a parameter (this is useful if you need to store the
90 * <Condition> in shared memory). Else, if @a abstime != 0 and the
91 * call times out before the condition is signaled <wait> returns -1
92 * and sets errno to ETIME.
94 int wait (ACE_Thread_Mutex
&mutex
, const ACE_Time_Value
*abstime
= 0);
96 /// Signal one waiting thread.
99 /// Signal *all* waiting threads.
102 /// Returns a reference to the underlying mutex;
103 ACE_Thread_Mutex
&mutex ();
105 /// Dump the state of an object.
108 /// Declare the dynamic allocation hooks.
109 ACE_ALLOC_HOOK_DECLARE
;
112 /// Condition variable.
115 /// Reference to mutex lock.
116 ACE_Thread_Mutex
&mutex_
;
118 /// Keeps track of whether remove() has been called yet to avoid
119 /// multiple remove() calls, e.g., explicitly and implicitly in the
120 /// destructor. This flag isn't protected by a lock, so make sure
121 /// that you don't have multiple threads simultaneously calling
122 /// remove() on the same object, which is a bad idea anyway...
126 void operator= (const ACE_Condition
<ACE_Thread_Mutex
> &) = delete;
127 ACE_Condition (const ACE_Condition
<ACE_Thread_Mutex
> &) = delete;
130 typedef ACE_Condition
<ACE_Thread_Mutex
> ACE_Condition_Thread_Mutex
;
132 ACE_END_VERSIONED_NAMESPACE_DECL
134 #if defined (__ACE_INLINE__)
135 #include "ace/Condition_Thread_Mutex.inl"
136 #endif /* __ACE_INLINE__ */
138 #endif /* !ACE_HAS_THREADS */
140 #include /**/ "ace/post.h"
141 #endif /* ACE_CONDITION_THREAD_MUTEX_H */