Top Inners Fields Constructors Methods
org.python.modules._threading

pack-priv final Class Mutex

Located in compilation unit of org.python.modules._threading.Lock.

extends Object
implements Lock
Class Inheritance
All Implemented Interfaces
java.util.concurrent.locks.Lock

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final Mutex.Sync

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv String
public int
public boolean
public boolean
public void
lock()

Implements java.util.concurrent.locks.Lock.lock.

Acquires the lock.

public void
lockInterruptibly()

Implements java.util.concurrent.locks.Lock.lockInterruptibly.

Acquires the lock unless the current thread is interrupted.

public Condition
newCondition()

Implements java.util.concurrent.locks.Lock.newCondition.

Returns a new Condition instance that is bound to this Lock instance.

public boolean
tryLock()

Implements java.util.concurrent.locks.Lock.tryLock.

Acquires the lock only if it is free at the time of invocation.

public boolean
tryLock(long
the maximum time to wait for the lock
timeout
,
TimeUnit
the time unit of the time argument
unit
)

Implements java.util.concurrent.locks.Lock.tryLock.

Acquires the lock if it is free within the given waiting time and the current thread has not been interrupted.

public void
unlock()

Implements java.util.concurrent.locks.Lock.unlock.

Releases the lock.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

syncback to summary
private final Mutex.Sync sync

Constructor Detail

Mutexback to summary
pack-priv Mutex()

Method Detail

getOwnerNameback to summary
pack-priv String getOwnerName()
getWaitQueueLengthback to summary
public int getWaitQueueLength(Condition condition)
hasQueuedThreadsback to summary
public boolean hasQueuedThreads()
isLockedback to summary
public boolean isLocked()
lockback to summary
public void lock()

Implements java.util.concurrent.locks.Lock.lock.

Doc from java.util.concurrent.locks.Lock.lock.

Acquires the lock.

If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.

Implementation Considerations

A Lock implementation may be able to detect erroneous use of the lock, such as an invocation that would cause deadlock, and may throw an (unchecked) exception in such circumstances. The circumstances and the exception type must be documented by that Lock implementation.

lockInterruptiblyback to summary
public void lockInterruptibly() throws InterruptedException

Implements java.util.concurrent.locks.Lock.lockInterruptibly.

Doc from java.util.concurrent.locks.Lock.lockInterruptibly.

Acquires the lock unless the current thread is interrupted.

Acquires the lock if it is available and returns immediately.

If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

  • The lock is acquired by the current thread; or
  • Some other thread interrupts the current thread, and interruption of lock acquisition is supported.

If the current thread:

  • has its interrupted status set on entry to this method; or
  • is interrupted while acquiring the lock, and interruption of lock acquisition is supported,
then InterruptedException is thrown and the current thread's interrupted status is cleared.

Implementation Considerations

The ability to interrupt a lock acquisition in some implementations may not be possible, and if possible may be an expensive operation. The programmer should be aware that this may be the case. An implementation should document when this is the case.

An implementation can favor responding to an interrupt over normal method return.

A Lock implementation may be able to detect erroneous use of the lock, such as an invocation that would cause deadlock, and may throw an (unchecked) exception in such circumstances. The circumstances and the exception type must be documented by that Lock implementation.

Exceptions
InterruptedException:
if the current thread is interrupted while acquiring the lock (and interruption of lock acquisition is supported)
newConditionback to summary
public Condition newCondition()

Implements java.util.concurrent.locks.Lock.newCondition.

Doc from java.util.concurrent.locks.Lock.newCondition.

Returns a new Condition instance that is bound to this Lock instance.

Before waiting on the condition the lock must be held by the current thread. A call to Condition#await() will atomically release the lock before waiting and re-acquire the lock before the wait returns.

Implementation Considerations

The exact operation of the Condition instance depends on the Lock implementation and must be documented by that implementation.

Returns:Condition

A new Condition instance for this Lock instance

tryLockback to summary
public boolean tryLock()

Implements java.util.concurrent.locks.Lock.tryLock.

Doc from java.util.concurrent.locks.Lock.tryLock.

Acquires the lock only if it is free at the time of invocation.

Acquires the lock if it is available and returns immediately with the value true. If the lock is not available then this method will return immediately with the value false.

A typical usage idiom for this method would be:

 Lock lock = ...;
if (lock.tryLock()) {
  try {
    // manipulate protected state
  } finally {
    lock.unlock();
  }
} else {
  // perform alternative actions
}
This usage ensures that the lock is unlocked if it was acquired, and doesn't try to unlock if the lock was not acquired.
Returns:boolean

true if the lock was acquired and false otherwise

tryLockback to summary
public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException

Implements java.util.concurrent.locks.Lock.tryLock.

Doc from java.util.concurrent.locks.Lock.tryLock.

Acquires the lock if it is free within the given waiting time and the current thread has not been interrupted.

If the lock is available this method returns immediately with the value true. If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:

  • The lock is acquired by the current thread; or
  • Some other thread interrupts the current thread, and interruption of lock acquisition is supported; or
  • The specified waiting time elapses

If the lock is acquired then the value true is returned.

If the current thread:

  • has its interrupted status set on entry to this method; or
  • is interrupted while acquiring the lock, and interruption of lock acquisition is supported,
then InterruptedException is thrown and the current thread's interrupted status is cleared.

If the specified waiting time elapses then the value false is returned. If the time is less than or equal to zero, the method will not wait at all.

Implementation Considerations

The ability to interrupt a lock acquisition in some implementations may not be possible, and if possible may be an expensive operation. The programmer should be aware that this may be the case. An implementation should document when this is the case.

An implementation can favor responding to an interrupt over normal method return, or reporting a timeout.

A Lock implementation may be able to detect erroneous use of the lock, such as an invocation that would cause deadlock, and may throw an (unchecked) exception in such circumstances. The circumstances and the exception type must be documented by that Lock implementation.

Parameters
timeout:long

the maximum time to wait for the lock

unit:TimeUnit

the time unit of the time argument

Returns:boolean

true if the lock was acquired and false if the waiting time elapsed before the lock was acquired

Exceptions
InterruptedException:
if the current thread is interrupted while acquiring the lock (and interruption of lock acquisition is supported)

unlockback to summary
public void unlock()

Implements java.util.concurrent.locks.Lock.unlock.

Doc from java.util.concurrent.locks.Lock.unlock.

Releases the lock.

Implementation Considerations

A Lock implementation will usually impose restrictions on which thread can release a lock (typically only the holder of the lock can release it) and may throw an (unchecked) exception if the restriction is violated. Any restrictions and the exception type must be documented by that Lock implementation.

org.python.modules._threading back to summary

private Class Mutex.Sync

extends AbstractQueuedSynchronizer
Class Inheritance

Constructor Summary

AccessConstructor and Description
private
Sync()

Method Summary

Modifier and TypeMethod and Description
pack-priv Thread
protected boolean
isHeldExclusively()

Overrides java.util.concurrent.locks.AbstractQueuedSynchronizer.isHeldExclusively.

Returns true if synchronization is held exclusively with respect to the current (calling) thread.

pack-priv AbstractQueuedSynchronizer.ConditionObject
public boolean
tryAcquire(int
the acquire argument. This value is always the one passed to an acquire method, or is the value saved on entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like.
acquires
)

Overrides java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquire.

Attempts to acquire in exclusive mode.

protected boolean
tryRelease(int
the release argument. This value is always the one passed to a release method, or the current state value upon entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like.
releases
)

Overrides java.util.concurrent.locks.AbstractQueuedSynchronizer.tryRelease.

Attempts to set the state to reflect a release in exclusive mode.

Inherited from java.util.concurrent.locks.AbstractQueuedSynchronizer:
acquireacquireInterruptiblyacquireSharedacquireSharedInterruptiblycompareAndSetStategetExclusiveQueuedThreadsgetFirstQueuedThreadgetQueuedThreadsgetQueueLengthgetSharedQueuedThreadsgetStategetWaitingThreadsgetWaitQueueLengthhasContendedhasQueuedPredecessorshasQueuedThreadshasWaitersisQueuedownsreleasereleaseSharedsetStatetoStringtryAcquireNanostryAcquireSharedtryAcquireSharedNanostryReleaseShared

Constructor Detail

Syncback to summary
private Sync()

Method Detail

getOwnerback to summary
pack-priv Thread getOwner()
isHeldExclusivelyback to summary
protected boolean isHeldExclusively()

Overrides java.util.concurrent.locks.AbstractQueuedSynchronizer.isHeldExclusively.

Doc from java.util.concurrent.locks.AbstractQueuedSynchronizer.isHeldExclusively.

Returns true if synchronization is held exclusively with respect to the current (calling) thread. This method is invoked upon each call to a ConditionObject method.

The default implementation throws UnsupportedOperationException. This method is invoked internally only within ConditionObject methods, so need not be defined if conditions are not used.

Returns:boolean

true if synchronization is held exclusively; false otherwise

newConditionback to summary
pack-priv AbstractQueuedSynchronizer.ConditionObject newCondition()
tryAcquireback to summary
public boolean tryAcquire(int acquires)

Overrides java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquire.

Doc from java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquire.

Attempts to acquire in exclusive mode. This method should query if the state of the object permits it to be acquired in the exclusive mode, and if so to acquire it.

This method is always invoked by the thread performing acquire. If this method reports failure, the acquire method may queue the thread, if it is not already queued, until it is signalled by a release from some other thread. This can be used to implement method Lock#tryLock().

The default implementation throws UnsupportedOperationException.

Parameters
acquires:int

the acquire argument. This value is always the one passed to an acquire method, or is the value saved on entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like.

Returns:boolean

true if successful. Upon success, this object has been acquired.

tryReleaseback to summary
protected boolean tryRelease(int releases)

Overrides java.util.concurrent.locks.AbstractQueuedSynchronizer.tryRelease.

Doc from java.util.concurrent.locks.AbstractQueuedSynchronizer.tryRelease.

Attempts to set the state to reflect a release in exclusive mode.

This method is always invoked by the thread performing release.

The default implementation throws UnsupportedOperationException.

Parameters
releases:int

the release argument. This value is always the one passed to a release method, or the current state value upon entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like.

Returns:boolean

true if this object is now in a fully released state, so that any waiting threads may attempt to acquire; and false otherwise.