Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / Condition_Thread_Mutex.h
blob693ff0820aa04092d13e9c065694ea931c36d56e
1 // -*- C++ -*-
3 //==========================================================================
4 /**
5 * @file Condition_Thread_Mutex.h
7 * $Id: Condition_Thread_Mutex.h 80826 2008-03-04 14:51:23Z wotte $
9 * Moved from Synch.h.
11 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
13 //==========================================================================
15 #ifndef ACE_CONDITION_THREAD_MUTEX_H
16 #define ACE_CONDITION_THREAD_MUTEX_H
17 #include /**/ "ace/pre.h"
19 #include /**/ "ace/ACE_export.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # pragma once
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #if !defined (ACE_HAS_THREADS)
26 # include "ace/Null_Condition.h"
27 #else /* ACE_HAS_THREADS */
28 // ACE platform supports some form of threading.
30 #include "ace/Thread_Mutex.h"
32 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
34 class ACE_Time_Value;
36 class ACE_Export ACE_Condition_Attributes
38 public:
39 /// Constructor
40 ACE_Condition_Attributes (int type = ACE_DEFAULT_SYNCH_TYPE);
42 /// Destructor
43 ~ACE_Condition_Attributes (void);
45 private:
46 friend class ACE_Condition_Thread_Mutex;
48 /// The attributes
49 ACE_condattr_t attributes_;
51 private:
52 // = Prevent assignment and initialization.
53 void operator= (const ACE_Condition_Attributes &);
54 ACE_Condition_Attributes (const ACE_Condition_Attributes &);
57 /**
58 * @class ACE_Condition_Thread_Mutex
60 * @brief ACE_Condition variable wrapper written using ACE_Mutexes This
61 * allows threads to block until shared data changes state.
62 * A condition variable enables threads to atomically block and
63 * test the condition under the protection of a mutual exclu-
64 * sion lock (mutex) until the condition is satisfied. That is,
65 * the mutex must have been held by the thread before calling
66 * wait or signal on the condition. If the condition is false,
67 * a thread blocks on a condition variable and atomically
68 * releases the mutex that is waiting for the condition to
69 * change. If another thread changes the condition, it may wake
70 * up waiting threads by signaling the associated condition
71 * variable. The waiting threads, upon awakening, reacquire the
72 * mutex and re-evaluate the condition.
74 * This should be an instantiation of ACE_Condition but problems
75 * with compilers precludes this...
77 class ACE_Export ACE_Condition_Thread_Mutex
79 public:
80 /// Initialize the condition variable.
81 ACE_Condition_Thread_Mutex (ACE_Thread_Mutex &m,
82 const ACE_TCHAR *name = 0,
83 void *arg = 0);
85 /// Initialize the condition variable.
86 ACE_Condition_Thread_Mutex (ACE_Thread_Mutex &m,
87 ACE_Condition_Attributes &attributes,
88 const ACE_TCHAR *name = 0,
89 void *arg = 0);
91 /// Implicitly destroy the condition variable.
92 ~ACE_Condition_Thread_Mutex (void);
94 /**
95 * Explicitly destroy the condition variable. Note that only one
96 * thread should call this method since it doesn't protect against
97 * race conditions.
99 int remove (void);
102 * Block on condition, or until absolute time-of-day has passed. If
103 * abstime == 0 use "blocking" <wait> semantics. Else, if @a abstime
104 * != 0 and the call times out before the condition is signaled
105 * <wait> returns -1 and sets errno to ETIME.
107 int wait (const ACE_Time_Value *abstime);
109 /// Block on condition.
110 int wait (void);
113 * Block on condition or until absolute time-of-day has passed. If
114 * abstime == 0 use "blocking" wait() semantics on the <mutex>
115 * passed as a parameter (this is useful if you need to store the
116 * <Condition> in shared memory). Else, if @a abstime != 0 and the
117 * call times out before the condition is signaled <wait> returns -1
118 * and sets errno to ETIME.
120 int wait (ACE_Thread_Mutex &mutex, const ACE_Time_Value *abstime = 0);
122 /// Signal one waiting thread.
123 int signal (void);
125 /// Signal *all* waiting threads.
126 int broadcast (void);
128 /// Returns a reference to the underlying mutex;
129 ACE_Thread_Mutex &mutex (void);
131 /// Dump the state of an object.
132 void dump (void) const;
134 /// Declare the dynamic allocation hooks.
135 ACE_ALLOC_HOOK_DECLARE;
137 protected:
138 /// Condition variable.
139 ACE_cond_t cond_;
141 /// Reference to mutex lock.
142 ACE_Thread_Mutex &mutex_;
144 /// Keeps track of whether <remove> has been called yet to avoid
145 /// multiple <remove> calls, e.g., explicitly and implicitly in the
146 /// destructor. This flag isn't protected by a lock, so make sure
147 /// that you don't have multiple threads simultaneously calling
148 /// <remove> on the same object, which is a bad idea anyway...
149 bool removed_;
151 private:
152 // = Prevent assignment and initialization.
153 void operator= (const ACE_Condition_Thread_Mutex &);
154 ACE_Condition_Thread_Mutex (const ACE_Condition_Thread_Mutex &);
157 #if 0
158 // The following class is commented out since there doesn't
159 // appear to be a portable and robust means of implementing this
160 // functionality across platforms. If you know of a portable and
161 // robust way to implement this functionality please let us know.
164 * @class ACE_Process_Condition
166 * @brief ACE_Condition variable wrapper that works across processes.
168 class ACE_Export ACE_Process_Condition
170 public:
171 ACE_Process_Condition (MUTEX &m, const ACE_TCHAR *name = 0, void *arg = 0);
173 /// Dump the state of an object.
174 void dump (void) const;
176 // ACE_ALLOC_HOOK_DECLARE;
177 // Declare the dynamic allocation hooks.
179 #endif /* 0 */
181 ACE_END_VERSIONED_NAMESPACE_DECL
183 #if defined (__ACE_INLINE__)
184 #include "ace/Condition_Thread_Mutex.inl"
185 #endif /* __ACE_INLINE__ */
187 #endif /* !ACE_HAS_THREADS */
189 #include /**/ "ace/post.h"
190 #endif /* ACE_CONDITION_THREAD_MUTEX_H */