9#ifndef INCLUDED_BSLMT_READERWRITERMUTEXIMPL
10#define INCLUDED_BSLMT_READERWRITERMUTEXIMPL
77#include <bslscm_version.h>
93template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
100 = 0x0fffffff00000000LL;
102 = 0x0000000100000000LL;
106 bsls::AtomicOperations::AtomicTypes::Int64 d_state;
114 SEMAPHORE d_semaphore;
208template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
212 ATOMIC_OP::initInt64(&d_state);
216template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
229 if (state & (k_WRITER | k_PENDING_WRITER_MASK)) {
231 ATOMIC_OP::addInt64AcqRel(&d_state, k_READER_INC);
237 state = ATOMIC_OP::testAndSwapInt64AcqRel(&d_state,
239 state + k_READER_INC);
240 }
while (state != expState);
243template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
250 ATOMIC_OP::addInt64AcqRel(&d_state, k_PENDING_WRITER_INC);
252 if (ATOMIC_OP::addInt64NvAcqRel(&d_state,
253 k_WRITER - k_PENDING_WRITER_INC)
267template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
278 if (0 == (state & (k_WRITER | k_PENDING_WRITER_MASK))) {
279 if (state == ATOMIC_OP::testAndSwapInt64AcqRel(&d_state,
281 state + k_READER_INC)) {
290 if (0 == d_mutex.tryLock()) {
291 ATOMIC_OP::addInt64AcqRel(&d_state, k_READER_INC);
298template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
305 if (0 == d_mutex.tryLock()) {
308 if (0 == (state & k_READER_MASK)) {
312 ATOMIC_OP::addInt64AcqRel(&d_state, k_WRITER);
321template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
332 if (ATOMIC_OP::getInt64Acquire(&d_state) & k_READER_MASK) {
340template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
354 if (0 == (state & k_READER_MASK) && (state & k_WRITER)) {
359template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
366 ATOMIC_OP::addInt64AcqRel(&d_state, -k_WRITER);
371template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
376 return (state & k_READER_MASK) || (k_WRITER == (state & k_WRITER));
379template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
384 return state & k_READER_MASK;
387template <
class ATOMIC_OP,
class MUTEX,
class SEMAPHORE>
392 return k_WRITER == (state & k_WRITER);
Definition bslmt_readerwritermuteximpl.h:94
bool isLockedRead() const
Definition bslmt_readerwritermuteximpl.h:381
void lockRead()
Definition bslmt_readerwritermuteximpl.h:218
bool isLockedWrite() const
Definition bslmt_readerwritermuteximpl.h:389
void unlock()
Definition bslmt_readerwritermuteximpl.h:323
void unlockRead()
Definition bslmt_readerwritermuteximpl.h:342
void unlockWrite()
Definition bslmt_readerwritermuteximpl.h:361
ReaderWriterMutexImpl()
Construct a reader/writer lock initialized to an unlocked state.
Definition bslmt_readerwritermuteximpl.h:210
int tryLockRead()
Definition bslmt_readerwritermuteximpl.h:269
~ReaderWriterMutexImpl()
Destroy this object.
void lockWrite()
Definition bslmt_readerwritermuteximpl.h:245
bool isLocked() const
Definition bslmt_readerwritermuteximpl.h:373
int tryLockWrite()
Definition bslmt_readerwritermuteximpl.h:300
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bslmt_barrier.h:344
long long Int64
Definition bsls_types.h:132