activemq-cpp-3.6.0
decaf::util::concurrent::locks::ReentrantReadWriteLock Class Reference

#include <src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.h>

Inheritance diagram for decaf::util::concurrent::locks::ReentrantReadWriteLock:

Public Member Functions

 ReentrantReadWriteLock ()
 Creates a new ReentrantReadWriteLock with the default ordering property of Not-Fair.
 ReentrantReadWriteLock (bool fair)
 Creates a new ReentrantReadWriteLock with the given fairness policy.
virtual ~ReentrantReadWriteLock ()
virtual
decaf::util::concurrent::locks::Lock
readLock ()
 Returns the lock used for reading.
Returns
the lock used for reading.

virtual
decaf::util::concurrent::locks::Lock
writeLock ()
 Returns the lock used for writing.
Returns
the lock used for writing.

bool isFair () const
 Returns true if this lock has fairness set true.
int getReadLockCount () const
 Queries the number of read locks held for this lock.
bool isWriteLocked () const
 Queries if the write lock is held by any thread.
bool isWriteLockedByCurrentThread () const
 Queries if the write lock is held by the current thread.
int getWriteHoldCount () const
 Queries the number of reentrant write holds on this lock by the current thread.
int getReadHoldCount () const
 Queries the number of reentrant read holds on this lock by the current thread.
bool hasWaiters (Condition *condition) const
 Queries whether any threads are waiting on the given condition associated with the write lock.
int getWaitQueueLength (Condition *condition) const
 Gets an estimated count of the number of threads that are currently waiting on the given Condition object, this value changes dynamically so the result of this method can be invalid immediately after it is called.
std::string toString () const
 Returns a string identifying this lock, as well as its lock state.
bool hasQueuedThreads () const
 Queries whether any threads are waiting to acquire the read or write lock.
bool hasQueuedThread (decaf::lang::Thread *thread) const
 Queries whether the given thread is waiting to acquire either the read or write lock.
int getQueueLength () const
 Returns an estimate of the number of threads waiting to acquire either the read or write lock.
- Public Member Functions inherited from decaf::util::concurrent::locks::ReadWriteLock
virtual ~ReadWriteLock ()

Protected Member Functions

decaf::util::Collection
< decaf::lang::Thread * > * 
getWaitingThreads (Condition *condition) const
 Creates and returns a new Collection object that contains all the threads that may be waiting on the given Condition object instance at the time this method is called.
decaf::util::Collection
< decaf::lang::Thread * > * 
getQueuedThreads () const
 Returns a collection containing threads that may be waiting to acquire either the read or write lock.
decaf::util::Collection
< decaf::lang::Thread * > * 
getQueuedWriterThreads () const
 Returns a collection containing threads that may be waiting to acquire the write lock.
decaf::util::Collection
< decaf::lang::Thread * > * 
getQueuedReaderThreads () const
 Returns a collection containing threads that may be waiting to acquire the read lock.
decaf::lang::ThreadgetOwner () const
 Returns the thread that currently owns the write lock, or NULL if not owned.

Detailed Description

Since
1.0

Constructor & Destructor Documentation

decaf::util::concurrent::locks::ReentrantReadWriteLock::ReentrantReadWriteLock ( )

Creates a new ReentrantReadWriteLock with the default ordering property of Not-Fair.

decaf::util::concurrent::locks::ReentrantReadWriteLock::ReentrantReadWriteLock ( bool  fair)

Creates a new ReentrantReadWriteLock with the given fairness policy.

Parameters
fairBoolean value indicating whether this lock uses a fair or non-fair policy.
virtual decaf::util::concurrent::locks::ReentrantReadWriteLock::~ReentrantReadWriteLock ( )
virtual

Member Function Documentation

decaf::lang::Thread* decaf::util::concurrent::locks::ReentrantReadWriteLock::getOwner ( ) const
protected

Returns the thread that currently owns the write lock, or NULL if not owned.

When this method is called by a thread that is not the owner, the return value reflects a best-effort approximation of current lock status. For example, the owner may be momentarily NULL even if there are threads trying to acquire the lock but have not yet done so. This method is designed to facilitate construction of subclasses that provide more extensive lock monitoring facilities.

Returns
the owner thread pointer, or NULL if not currently owned.
decaf::util::Collection<decaf::lang::Thread*>* decaf::util::concurrent::locks::ReentrantReadWriteLock::getQueuedReaderThreads ( ) const
protected

Returns a collection containing threads that may be waiting to acquire the read lock.

Because the actual set of threads may change dynamically while constructing this result, the returned collection is only a best-effort estimate. The elements of the returned collection are in no particular order. This method is designed to facilitate construction of subclasses that provide more extensive lock monitoring facilities.

Returns
the collection of threads
decaf::util::Collection<decaf::lang::Thread*>* decaf::util::concurrent::locks::ReentrantReadWriteLock::getQueuedThreads ( ) const
protected

Returns a collection containing threads that may be waiting to acquire either the read or write lock.

Because the actual set of threads may change dynamically while constructing this result, the returned collection is only a best-effort estimate. The elements of the returned collection are in no particular order. This method is designed to facilitate construction of subclasses that provide more extensive monitoring facilities.

Returns
the collection of threads
decaf::util::Collection<decaf::lang::Thread*>* decaf::util::concurrent::locks::ReentrantReadWriteLock::getQueuedWriterThreads ( ) const
protected

Returns a collection containing threads that may be waiting to acquire the write lock.

Because the actual set of threads may change dynamically while constructing this result, the returned collection is only a best-effort estimate. The elements of the returned collection are in no particular order. This method is designed to facilitate construction of subclasses that provide more extensive lock monitoring facilities.

Returns
the collection of threads
int decaf::util::concurrent::locks::ReentrantReadWriteLock::getQueueLength ( ) const

Returns an estimate of the number of threads waiting to acquire either the read or write lock.

The value is only an estimate because the number of threads may change dynamically while this method traverses internal data structures. This method is designed for use in monitoring of the system state, not for synchronization control.

Returns
the estimated number of threads waiting for this lock
int decaf::util::concurrent::locks::ReentrantReadWriteLock::getReadHoldCount ( ) const

Queries the number of reentrant read holds on this lock by the current thread.

A reader thread has a hold on a lock for each lock action that is not matched by an unlock action.

Returns
the number of holds on the read lock by the current thread, or zero if the read lock is not held by the current thread
int decaf::util::concurrent::locks::ReentrantReadWriteLock::getReadLockCount ( ) const

Queries the number of read locks held for this lock.

This method is designed for use in monitoring system state, not for synchronization control.

Returns
the number of read locks held.
decaf::util::Collection<decaf::lang::Thread*>* decaf::util::concurrent::locks::ReentrantReadWriteLock::getWaitingThreads ( Condition condition) const
protected

Creates and returns a new Collection object that contains all the threads that may be waiting on the given Condition object instance at the time this method is called.

Returns
a Collection pointer that contains waiting threads on given Condition object. The caller owns the returned pointer.
Exceptions
NullPointerExceptionif the ConditionObject pointer is NULL.
IllegalArgumentExceptionif the ConditionObject is not associated with this Synchronizer.
IllegalMonitorStateExceptionif the caller does not hold exclusive synchronization.
int decaf::util::concurrent::locks::ReentrantReadWriteLock::getWaitQueueLength ( Condition condition) const

Gets an estimated count of the number of threads that are currently waiting on the given Condition object, this value changes dynamically so the result of this method can be invalid immediately after it is called.

The Condition object must be associated with this Lock or an exception will be thrown.

Returns
an estimate of the number of waiting threads.
Exceptions
NullPointerExceptionif the ConditionObject pointer is NULL.
IllegalArgumentExceptionif the ConditionObject is not associated with this Synchronizer.
IllegalMonitorStateExceptionif the caller does not hold exclusive synchronization.
int decaf::util::concurrent::locks::ReentrantReadWriteLock::getWriteHoldCount ( ) const

Queries the number of reentrant write holds on this lock by the current thread.

A writer thread has a hold on a lock for each lock action that is not matched by an unlock action.

Returns
the number of holds on the write lock by the current thread, or zero if the write lock is not held by the current thread
bool decaf::util::concurrent::locks::ReentrantReadWriteLock::hasQueuedThread ( decaf::lang::Thread thread) const

Queries whether the given thread is waiting to acquire either the read or write lock.

Note that because cancellations may occur at any time, a true return does not guarantee that this thread will ever acquire a lock. This method is designed primarily for use in monitoring of the system state.

Parameters
threadThe thread that will be queried for.
Returns
true if the given thread is queued waiting for this lock
Exceptions
NullPointerExceptionif the thread is NULL.
bool decaf::util::concurrent::locks::ReentrantReadWriteLock::hasQueuedThreads ( ) const

Queries whether any threads are waiting to acquire the read or write lock.

Note that because cancellations may occur at any time, a true return does not guarantee that any other thread will ever acquire a lock. This method is designed primarily for use in monitoring of the system state.

Returns
if there may be other threads waiting to acquire the lock
bool decaf::util::concurrent::locks::ReentrantReadWriteLock::hasWaiters ( Condition condition) const

Queries whether any threads are waiting on the given condition associated with the write lock.

Note that because timeouts and interrupts may occur at any time, a true return does not guarantee that a future signal will awaken any threads. This method is designed primarily for use in monitoring of the system state.

Parameters
conditionThe condition to be queried for waiters.
Returns
true if there are any waiting threads
Exceptions
NullPointerExceptionif the ConditionObject pointer is NULL.
IllegalArgumentExceptionif the ConditionObject is not associated with this Lock.
IllegalMonitorStateExceptionif the caller does not hold exclusive synchronization.
bool decaf::util::concurrent::locks::ReentrantReadWriteLock::isFair ( ) const

Returns true if this lock has fairness set true.

Returns
true if the Lock uses a fair policy otherwise false.
bool decaf::util::concurrent::locks::ReentrantReadWriteLock::isWriteLocked ( ) const

Queries if the write lock is held by any thread.

This method is designed for use in monitoring system state, not for synchronization control.

Returns
true if any thread holds the write lock and false otherwise
bool decaf::util::concurrent::locks::ReentrantReadWriteLock::isWriteLockedByCurrentThread ( ) const

Queries if the write lock is held by the current thread.

Returns
true if the current thread holds the write lock and false otherwise
std::string decaf::util::concurrent::locks::ReentrantReadWriteLock::toString ( ) const

Returns a string identifying this lock, as well as its lock state.

The state, in brackets, includes the String "Write locks =" followed by the number of reentrantly held write locks, and the String "Read locks =" followed by the number of held read locks.

Returns
a string identifying this lock, as well as its lock state

The documentation for this class was generated from the following file: