Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / RW_Mutex.h
blob7dd515a84d3bb5137c8ce2803200436b782065b3
1 // -*- C++ -*-
3 //==========================================================================
4 /**
5 * @file RW_Mutex.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
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)
19 # 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
29 /**
30 * @class ACE_RW_Mutex
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
39 public:
40 /// Initialize a readers/writer lock.
41 ACE_RW_Mutex (int type = USYNC_THREAD,
42 const ACE_TCHAR *name = 0,
43 void *arg = 0);
45 /// Implicitly destroy a readers/writer lock
46 ~ACE_RW_Mutex ();
48 /**
49 * Explicitly destroy a readers/writer lock. Note that only one
50 * thread should call this method since it doesn't protect against
51 * race conditions.
53 int remove ();
55 /// Acquire a read lock, but block if a writer hold the lock.
56 int acquire_read ();
58 /// Acquire a write lock, but block if any readers or a
59 /// writer hold the lock.
60 int acquire_write ();
62 /**
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 ();
72 /**
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 ();
82 /**
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...
87 int acquire ();
89 /**
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
94 * set to @c EBUSY.
96 int tryacquire ();
98 /// Unlock a readers/writer lock.
99 int release ();
101 /// Return the underlying lock.
102 const ACE_rwlock_t &lock () const;
104 /// Dump the state of an object.
105 void dump () const;
107 /// Declare the dynamic allocation hooks.
108 ACE_ALLOC_HOOK_DECLARE;
110 protected:
111 /// Readers/writer lock.
112 ACE_rwlock_t 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...
119 bool removed_;
121 private:
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 */