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

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

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

Data Structures

class  ConditionObject
 Condition object for this Synchronizer, which serves as the basis for other Lock objects. More...

Public Member Functions

virtual ~AbstractQueuedSynchronizer ()
void acquire (int arg)
 Acquire the lock exclusively, ignoring interrupts.
void acquireShared (int arg)
 Acquire the lock in shared mode, ignoring interrupts.
void acquireInterruptibly (int arg)
 Acquire the lock exclusively, allowing for interrupts.
void acquireSharedInterruptibly (int arg)
 Acquire the lock in shared mode, allowing interruption.
Collection
< decaf::lang::Thread * > * 
getExclusiveQueuedThreads () const
 Creates and returns a new Collection object that contains only those threads that may be waiting to acquire this Synchronization in exclusive mode.
Collection
< decaf::lang::Thread * > * 
getSharedQueuedThreads () const
 Creates and returns a new Collection object that contains only those threads that may be waiting to acquire this Synchronization in shared mode.
decaf::lang::ThreadgetFirstQueuedThread () const
 Returns the first thread queue (the thread that's been waiting the longest) if there are currently no queued threads this method returns NULL.
Collection
< decaf::lang::Thread * > * 
getQueuedThreads () const
 Creates and returns a new Collection object that contains a best effort snapshot of the threads that are currently waiting to acquire.
int getQueueLength () const
 Gets an estimated count of the number of threads that are currently waiting to acquire, this value changes dynamically so the result of this method can be invalid immediately after it is called.
Collection
< decaf::lang::Thread * > * 
getWaitingThreads (const AbstractQueuedSynchronizer::ConditionObject *condition) const
 Creates and returns a new Collection object that contains all the threads that may be waiting on the given ConditionOject instance at the time this method is called.
int getWaitQueueLength (const AbstractQueuedSynchronizer::ConditionObject *condition) const
 Gets an estimated count of the number of threads that are currently waiting on the given ConditionObject, this value changes dynamically so the result of this method can be invalid immediately after it is called.
bool hasContended () const
bool hasQueuedThreads () const
bool hasWaiters (const AbstractQueuedSynchronizer::ConditionObject *condition) const
 Returns true if there are any threads that are currently waiting on the given ConditionObject, the condition must be associated with this synchronizer instance.
bool isQueued (decaf::lang::Thread *thread) const
 Traverse the Queue if waiting threads to see if the given thread is present.
bool owns (const AbstractQueuedSynchronizer::ConditionObject *condition) const
 Checks whether the given ConditionObject uses this Synchronizer as its lock object.
bool release (int arg)
 When held in exclusive mode this method releases the Synchronizer.
bool releaseShared (int arg)
 When held in shared mode this method releases the Synchronizer.
std::string toString () const
 Gets a string that identifies this Synchronizer along with its present state.
bool tryAcquireNanos (int arg, long long nanos)
 Acquires in exclusive mode if possible, first checking if the calling thread has already been interrupted or not, then calling tryAcquire(int) at least one time and possibly more up to the given timeout, or until the calling thread is interrupted.
bool tryAcquireSharedNanos (int arg, long long nanos)
 Acquires in shared mode if possible, first checking if the calling thread has already been interrupted or not, then calling tryAcquireShared(int) at least one time and possibly more up to the given timeout, or until the calling thread is interrupted.
- Public Member Functions inherited from decaf::util::concurrent::locks::AbstractOwnableSynchronizer
virtual ~AbstractOwnableSynchronizer ()

Protected Member Functions

 AbstractQueuedSynchronizer ()
virtual int getState () const
 Gets and returns the currently set value of this object Synchronization sate.
virtual void setState (int value)
 Sets the synchronization state to the given value.
virtual bool compareAndSetState (int expect, int update)
 Sets the synchronization state to the specified value if the current value is equal to the expected value given, otherwise no change is made.
virtual bool isHeldExclusively () const
 If the calling thread hold an exclusive lock on this synchronization then this method returns true, false otherwise.
virtual bool tryAcquire (int arg)
 Performs the actual work of attempting to acquire the lock in exclusive mode.
virtual int tryAcquireShared (int arg)
 Performs the actual work of attempting to acquire the lock in shared mode.
virtual bool tryRelease (int arg)
 Performs a release for the calling thread in exclusive mode.
virtual bool tryReleaseShared (int arg)
 Performs a release for the calling thread in shared mode.
virtual ConditionObjectcreateDefaultConditionObject ()
 Provides a means for derived classes to create a ConditionObject implemented by the basic logic implemented inside this class.
bool hasQueuedPredecessors () const
 Queries whether any threads have been waiting to acquire longer than the current thread.
- Protected Member Functions inherited from decaf::util::concurrent::locks::AbstractOwnableSynchronizer
 AbstractOwnableSynchronizer ()
decaf::lang::ThreadgetExclusiveOwnerThread () const
 Gets the Thread that was last set using the setExclusiveOwnerThread method, or NULL if no Thread has been made the exclusive owner.
void setExclusiveOwnerThread (decaf::lang::Thread *thread)
 Sets the Thread that has exclusive ownership of this Synchronizer, can be NULL to indicate that no Thread now owns this Synchronizer.

Friends

class SynchronizerState

Constructor & Destructor Documentation

decaf::util::concurrent::locks::AbstractQueuedSynchronizer::AbstractQueuedSynchronizer ( )
protected
virtual decaf::util::concurrent::locks::AbstractQueuedSynchronizer::~AbstractQueuedSynchronizer ( )
virtual

Member Function Documentation

void decaf::util::concurrent::locks::AbstractQueuedSynchronizer::acquire ( int  arg)

Acquire the lock exclusively, ignoring interrupts.

This method will call tryAcquire at least once and return if that succeeds, otherwise it can block and possibly spin until the lock is acquired. This method can serve as the basis for a Lock.lock() implementation.

Parameters
argArgument passed to tryAcquire, value is not interpreted by this class.
void decaf::util::concurrent::locks::AbstractQueuedSynchronizer::acquireInterruptibly ( int  arg)

Acquire the lock exclusively, allowing for interrupts.

If the interrupt state is not already set this method will call tryAcquire at least once and return if that succeeds, otherwise it can block and possibly spin until the lock is acquired or the Thread is interrupted. This method can serve as the basis for a Lock.lockInterruptibly() implementation.

Parameters
argArgument passed to tryAcquire, value is not interpreted by this class.
Exceptions
InterruptedExceptionif the calling Thread is interrupted.
void decaf::util::concurrent::locks::AbstractQueuedSynchronizer::acquireShared ( int  arg)

Acquire the lock in shared mode, ignoring interrupts.

This method will call tryAcquireShared at least once and return if that succeeds, otherwise it can block and possibly spin until the lock is acquired.

Parameters
argArgument passed to tryAcquireShared, value is not interpreted by this class.
void decaf::util::concurrent::locks::AbstractQueuedSynchronizer::acquireSharedInterruptibly ( int  arg)

Acquire the lock in shared mode, allowing interruption.

If the interrupt state is not already set this method will call tryAcquireShared at least once and return if that succeeds, otherwise it can block and possibly spin until the lock is acquired or the Thread is interrupted.

Parameters
argArgument passed to tryAcquireShared, value is not interpreted by this class.
Exceptions
InterruptedExceptionif the calling Thread is interrupted.
virtual bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::compareAndSetState ( int  expect,
int  update 
)
protectedvirtual

Sets the synchronization state to the specified value if the current value is equal to the expected value given, otherwise no change is made.

This method is Atomic.

Parameters
expectThe value that state must have if the update is made.
updateThe new value to assign the state if the current value matches the expected.
Returns
true if a change is made, false otherwise.
virtual ConditionObject* decaf::util::concurrent::locks::AbstractQueuedSynchronizer::createDefaultConditionObject ( )
protectedvirtual

Provides a means for derived classes to create a ConditionObject implemented by the basic logic implemented inside this class.

Can be overridden by derived classes that wish to provide their own implementation of a ConditionObject.

Returns
a new ConditionObject that is owned by the caller.
Collection<decaf::lang::Thread*>* decaf::util::concurrent::locks::AbstractQueuedSynchronizer::getExclusiveQueuedThreads ( ) const

Creates and returns a new Collection object that contains only those threads that may be waiting to acquire this Synchronization in exclusive mode.

Returns
a Collection pointer that contains waiting threads for exclusive acquisition. The caller owns the returned pointer.
decaf::lang::Thread* decaf::util::concurrent::locks::AbstractQueuedSynchronizer::getFirstQueuedThread ( ) const

Returns the first thread queue (the thread that's been waiting the longest) if there are currently no queued threads this method returns NULL.

Returns
the first thread in the queue or NULL if none are currently waiting.
Collection<decaf::lang::Thread*>* decaf::util::concurrent::locks::AbstractQueuedSynchronizer::getQueuedThreads ( ) const

Creates and returns a new Collection object that contains a best effort snapshot of the threads that are currently waiting to acquire.

Returns
a Collection pointer that contains waiting threads for lock acquisition. The caller owns the returned pointer.
int decaf::util::concurrent::locks::AbstractQueuedSynchronizer::getQueueLength ( ) const

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

Returns
an estimate of the number of waiting threads.
Collection<decaf::lang::Thread*>* decaf::util::concurrent::locks::AbstractQueuedSynchronizer::getSharedQueuedThreads ( ) const

Creates and returns a new Collection object that contains only those threads that may be waiting to acquire this Synchronization in shared mode.

Returns
a Collection pointer that contains waiting threads for shared acquisition. The caller owns the returned pointer.
virtual int decaf::util::concurrent::locks::AbstractQueuedSynchronizer::getState ( ) const
protectedvirtual

Gets and returns the currently set value of this object Synchronization sate.

Returns
the value of the synchronization sate.
Collection<decaf::lang::Thread*>* decaf::util::concurrent::locks::AbstractQueuedSynchronizer::getWaitingThreads ( const AbstractQueuedSynchronizer::ConditionObject condition) const

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

Returns
a Collection pointer that contains waiting threads on given ConditionObject. 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::AbstractQueuedSynchronizer::getWaitQueueLength ( const AbstractQueuedSynchronizer::ConditionObject condition) const

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

The ConditionObject must be associated with this AbstractQueuedSynchronizer 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.
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::hasContended ( ) const
Returns
true if there has ever been the need for the acquire method to block.
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::hasQueuedPredecessors ( ) const
protected

Queries whether any threads have been waiting to acquire longer than the current thread.

Note that because cancellations due to interrupts and timeouts may occur at any time, a true return does not guarantee that some other thread will acquire before the current thread. Likewise, it is possible for another thread to win a race to enqueue after this method has returned false, due to the queue being empty.

This method is designed to be used by a fair synchronizer to avoid barging. Such a synchronizer's tryAcquire method should return false, and its tryAcquireShared method should return a negative value, if this method returns true (unless this is a reentrant acquire). For example, the tryAcquire method for a fair, reentrant, exclusive mode synchronizer might look like this:

 
virtual bool tryAcquire(int arg) {
// A reentrant acquire; increment hold count
return true;
} else if (hasQueuedPredecessors()) {
return false;
} else {
// try to acquire normally
}
}
Returns
true if there is a queued thread preceding the current thread, and false if the current thread is at the head of the queue or the queue is empty
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::hasQueuedThreads ( ) const
Returns
true if there are threads that are currently waiting to acquire.
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::hasWaiters ( const AbstractQueuedSynchronizer::ConditionObject condition) const

Returns true if there are any threads that are currently waiting on the given ConditionObject, the condition must be associated with this synchronizer instance.

Returns
true if the condition object has 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.
virtual bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::isHeldExclusively ( ) const
protectedvirtual

If the calling thread hold an exclusive lock on this synchronization then this method returns true, false otherwise.

The default behavior is to throw an UnsupportedOperation exception as this method is only needed when ConditionObject is supported.

Returns
true if this synchronization is held exclusively by the current thread.
Exceptions
UnsupportedOperationExceptionif Condition objects are not supported.
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::isQueued ( decaf::lang::Thread thread) const

Traverse the Queue if waiting threads to see if the given thread is present.

Returns
true if the given thread is in the wait Queue.
Exceptions
NullPointerExceptionif the thread pointer is NULL.
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::owns ( const AbstractQueuedSynchronizer::ConditionObject condition) const

Checks whether the given ConditionObject uses this Synchronizer as its lock object.

Returns
true if the ConditionObject uses this Synchronizer as its lock.
Exceptions
NullPointerExceptionif the condition pointer is NULL.
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::release ( int  arg)

When held in exclusive mode this method releases the Synchronizer.

This method calls tryRelease(int) and if one or more threads is unblocked it returns true. This method forms the basis of Lock.unlock.

Parameters
argA value used to release, it is passed to tryRelease and not interpreted by this class.
Returns
the result that is returned from a call to tryRelease(int).
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::releaseShared ( int  arg)

When held in shared mode this method releases the Synchronizer.

This method calls tryReleaseShared(int) and if one or more threads is unblocked it returns true.

Parameters
argA value used to release, it is passed to tryReleaseShared and not interpreted by this class.
Returns
the result that is returned from a call to tryReleaseShared(int).
virtual void decaf::util::concurrent::locks::AbstractQueuedSynchronizer::setState ( int  value)
protectedvirtual

Sets the synchronization state to the given value.

Parameters
valueThe new value to assign to the synchronization state.
std::string decaf::util::concurrent::locks::AbstractQueuedSynchronizer::toString ( ) const

Gets a string that identifies this Synchronizer along with its present state.

The string contains the state in a bracketed form that contains "State =" and the result of getState() and also contains the indicators "nonempty" or "empty" based on whether the thread queue is empty or not.

Returns
a string value that identifies this AbstractQueuedSynchronizer.
virtual bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::tryAcquire ( int  arg)
protectedvirtual

Performs the actual work of attempting to acquire the lock in exclusive mode.

The implementation should acquire the lock in exclusive mode based on its current state or the capabilities of the lock being implemented.

Whenever a thread calls acquire this method is invoked. If the method fails then the acquire method can decide to block the calling thread until signaled that another attempt to acquire should be made.

The default implementation always throws UnsupportedOperationException.

Parameters
argThe value passed to the acquire method.
Returns
true if the acquire succeeded, false otherwise.
Exceptions
IllegalMonitorStateExceptionif the acquire places the object in an invalid state.
UnsupportedOperationExceptionif exclusive mode is not supported.
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::tryAcquireNanos ( int  arg,
long long  nanos 
)

Acquires in exclusive mode if possible, first checking if the calling thread has already been interrupted or not, then calling tryAcquire(int) at least one time and possibly more up to the given timeout, or until the calling thread is interrupted.

Parameters
argValue to be passed to tryAcquire(int) its meaning is uninterpreted here.
nanosTime in nanoseconds to wait before reporting the acquisition as failed.
Returns
true if the acquire succeeded, false otherwise.
Exceptions
InterruptedExceptionif the calling thread is interrupted.
virtual int decaf::util::concurrent::locks::AbstractQueuedSynchronizer::tryAcquireShared ( int  arg)
protectedvirtual

Performs the actual work of attempting to acquire the lock in shared mode.

The implementation should acquire the lock in exclusive mode based on its current state or the capabilities of the lock being implemented.

Whenever a thread calls acquire this method is invoked. If the method fails then the acquire method can decide to block the calling thread until signaled that another attempt to acquire should be made.

The default implementation always throws UnsupportedOperationException.

Parameters
argThe value passed to the acquire method.
Returns
a negative value if the acquire failed, zero if it did succeed but no additional shared mode acquires can, or a positive number if success and future calls amy also succeed.
Exceptions
IllegalMonitorStateExceptionif the acquire places the object in an invalid state.
UnsupportedOperationExceptionif shared mode is not supported.
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::tryAcquireSharedNanos ( int  arg,
long long  nanos 
)

Acquires in shared mode if possible, first checking if the calling thread has already been interrupted or not, then calling tryAcquireShared(int) at least one time and possibly more up to the given timeout, or until the calling thread is interrupted.

Parameters
argValue to be passed to tryAcquireShared(int) its meaning is uninterpreted here.
nanosTime in nanoseconds to wait before reporting the acquisition as failed.
Returns
true if the acquire succeeded, false otherwise.
Exceptions
InterruptedExceptionif the calling thread is interrupted.
virtual bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::tryRelease ( int  arg)
protectedvirtual

Performs a release for the calling thread in exclusive mode.

For any thread that performs a release this method will always be invoked.

The default implementation always throws UnsupportedOperationException.

Parameters
argThe value that was passed to the release method.
Returns
true if the synchronization is now fully released such that waiting threads can now attempt to acquire it, false if not fully released.
Exceptions
IllegalMonitorStateExceptionif the release places the object in an invalid state.
UnsupportedOperationExceptionif exclusive mode is not supported.
virtual bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::tryReleaseShared ( int  arg)
protectedvirtual

Performs a release for the calling thread in shared mode.

For any thread that performs a release this method will always be invoked.

The default implementation always throws UnsupportedOperationException.

Parameters
argThe value that was passed to the release method.
Returns
true if the synchronization is now fully released such that waiting threads can now attempt to acquire it, false if not fully released.
Exceptions
IllegalMonitorStateExceptionif the release places the object in an invalid state.
UnsupportedOperationExceptionif shared mode is not supported.

Friends And Related Function Documentation

friend class SynchronizerState
friend

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