3 //==========================================================================
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //==========================================================================
11 #ifndef ACE_RW_MUTEX_H
12 #define ACE_RW_MUTEX_H
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/ACE_export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 // ACE platform supports some form of threading.
23 #if defined (ACE_HAS_THREADS)
25 #include "ace/OS_NS_Thread.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
32 * @brief Wrapper for readers/writer locks.
34 * These are most useful for applications that have many more
35 * parallel readers than writers...
37 class ACE_Export ACE_RW_Mutex
40 /// Initialize a readers/writer lock.
41 ACE_RW_Mutex (int type
= USYNC_THREAD
,
42 const ACE_TCHAR
*name
= 0,
45 /// Implicitly destroy a readers/writer lock
49 * Explicitly destroy a readers/writer lock. Note that only one
50 * thread should call this method since it doesn't protect against
55 /// Acquire a read lock, but block if a writer hold the lock.
58 /// Acquire a write lock, but block if any readers or a
59 /// writer hold the lock.
63 * Conditionally acquire a read lock (i.e., won't block). Returns
64 * -1 on failure. If we "failed" because someone else already had
65 * the lock, @c errno is set to @c EBUSY.
67 int tryacquire_read ();
69 /// Conditionally acquire a write lock (i.e., won't block).
70 int tryacquire_write ();
73 * Conditionally upgrade a read lock to a write lock. This only
74 * works if there are no other readers present, in which case the
75 * method returns 0. Otherwise, the method returns -1 and sets
76 * @c errno to @c EBUSY. Note that the caller of this method *must*
77 * already possess this lock as a read lock (but this condition is
78 * not checked by the current implementation).
80 int tryacquire_write_upgrade ();
83 * Note, for interface uniformity with other synchronization
84 * wrappers we include the <acquire> method. This is implemented as
85 * a write-lock to safe...
90 * Note, for interface uniformity with other synchronization
91 * wrappers we include the tryacquire() method. This is implemented
92 * as a write-lock to be safe... Returns -1 on failure. If we
93 * "failed" because someone else already had the lock, @c errno is
98 /// Unlock a readers/writer lock.
101 /// Return the underlying lock.
102 const ACE_rwlock_t
&lock () const;
104 /// Dump the state of an object.
107 /// Declare the dynamic allocation hooks.
108 ACE_ALLOC_HOOK_DECLARE
;
111 /// Readers/writer lock.
114 /// Keeps track of whether remove() has been called yet to avoid
115 /// multiple remove() calls, e.g., explicitly and implicitly in the
116 /// destructor. This flag isn't protected by a lock, so make sure
117 /// that you don't have multiple threads simultaneously calling
118 /// remove() on the same object, which is a bad idea anyway...
122 void operator= (const ACE_RW_Mutex
&) = delete;
123 ACE_RW_Mutex (const ACE_RW_Mutex
&) = delete;
126 ACE_END_VERSIONED_NAMESPACE_DECL
128 #if defined (__ACE_INLINE__)
129 #include "ace/RW_Mutex.inl"
130 #endif /* __ACE_INLINE__ */
132 #endif /* ACE_HAS_THREADS */
134 #include /**/ "ace/post.h"
136 #endif /* ACE_RW_MUTEX_H */