activemq-cpp-3.6.0
|
#include <src/main/decaf/util/concurrent/locks/AbstractQueuedSynchronizer.h>
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::Thread * | 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. | |
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 ConditionObject * | createDefaultConditionObject () |
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::Thread * | getExclusiveOwnerThread () 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 |
|
protected |
|
virtual |
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.
arg | Argument 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.
arg | Argument passed to tryAcquire, value is not interpreted by this class. |
InterruptedException | if 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.
arg | Argument 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.
arg | Argument passed to tryAcquireShared, value is not interpreted by this class. |
InterruptedException | if the calling Thread is interrupted. |
|
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.
expect | The value that state must have if the update is made. |
update | The new value to assign the state if the current value matches the expected. |
|
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.
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.
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.
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.
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.
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.
|
protectedvirtual |
Gets and returns the currently set value of this object 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.
NullPointerException | if the ConditionObject pointer is NULL. |
IllegalArgumentException | if the ConditionObject is not associated with this Synchronizer. |
IllegalMonitorStateException | if 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.
NullPointerException | if the ConditionObject pointer is NULL. |
IllegalArgumentException | if the ConditionObject is not associated with this Synchronizer. |
IllegalMonitorStateException | if the caller does not hold exclusive synchronization. |
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::hasContended | ( | ) | 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:
if (isHeldExclusively()) {// A reentrant acquire; increment hold countreturn true;return false;} else {// try to acquire normally}}
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::hasQueuedThreads | ( | ) | const |
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.
NullPointerException | if the ConditionObject pointer is NULL. |
IllegalArgumentException | if the ConditionObject is not associated with this Synchronizer. |
IllegalMonitorStateException | if the caller does not hold exclusive synchronization. |
|
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.
UnsupportedOperationException | if Condition objects are not supported. |
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::isQueued | ( | decaf::lang::Thread * | thread | ) | const |
bool decaf::util::concurrent::locks::AbstractQueuedSynchronizer::owns | ( | const AbstractQueuedSynchronizer::ConditionObject * | condition | ) | const |
Checks whether the given ConditionObject uses this Synchronizer as its lock object.
NullPointerException | if 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.
arg | A value used to release, it is passed to tryRelease and not interpreted by this class. |
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.
arg | A value used to release, it is passed to tryReleaseShared and not interpreted by this class. |
|
protectedvirtual |
Sets the synchronization state to the given value.
value | The 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.
|
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.
arg | The value passed to the acquire method. |
IllegalMonitorStateException | if the acquire places the object in an invalid state. |
UnsupportedOperationException | if 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.
arg | Value to be passed to tryAcquire(int) its meaning is uninterpreted here. |
nanos | Time in nanoseconds to wait before reporting the acquisition as failed. |
InterruptedException | if the calling thread is interrupted. |
|
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.
arg | The value passed to the acquire method. |
IllegalMonitorStateException | if the acquire places the object in an invalid state. |
UnsupportedOperationException | if 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.
arg | Value to be passed to tryAcquireShared(int) its meaning is uninterpreted here. |
nanos | Time in nanoseconds to wait before reporting the acquisition as failed. |
InterruptedException | if the calling thread is interrupted. |
|
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.
arg | The value that was passed to the release method. |
IllegalMonitorStateException | if the release places the object in an invalid state. |
UnsupportedOperationException | if exclusive mode is not supported. |
|
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.
arg | The value that was passed to the release method. |
IllegalMonitorStateException | if the release places the object in an invalid state. |
UnsupportedOperationException | if shared mode is not supported. |
|
friend |