LockTable
final class ConcurrentLockSet extends java.lang.Object implements LockTable
Lockable
s to LockControl
objects.
A LockControl contains information about the locks held on a Lockable.
MT - Mutable : All public methods of this class, except addWaiters, are
thread safe. addWaiters can only be called from the thread which performs
deadlock detection. Only one thread can perform deadlock detection at a
time.
The class creates ActiveLock and LockControl objects.
LockControl objects are never passed out of this class, All the methods of
LockControl are called while holding a ReentrantLock associated with the
Lockable controlled by the LockControl, thus providing the
single threading that LockControl required.
Methods of Lockables are only called by this class or LockControl, and
always while holding the corresponding ReentrantLock, thus providing the
single threading that Lockable requires.
LockControl
Modifier and Type | Class | Description |
---|---|---|
private static class |
ConcurrentLockSet.Entry |
Class representing an entry in the lock table.
|
Modifier and Type | Field | Description |
---|---|---|
private java.util.concurrent.atomic.AtomicInteger |
blockCount |
|
private int |
deadlockTimeout |
Timeout for deadlocks, in ms.
|
private boolean |
deadlockTrace |
|
private AbstractPool |
factory |
|
private java.util.concurrent.ConcurrentHashMap<Lockable,ConcurrentLockSet.Entry> |
locks |
Hash table which maps
Lockable objects to
Lock s. |
private java.util.ArrayList<ConcurrentLockSet.Entry> |
seenByDeadlockDetection |
List containing all entries seen by the last call to
addWaiters() . |
private int |
waitTimeout |
Constructor | Description |
---|---|
ConcurrentLockSet(AbstractPool factory) |
Modifier and Type | Method | Description |
---|---|---|
void |
addWaiters(java.util.Map<java.lang.Object,java.lang.Object> waiters) |
Add all waiters in this lock table to a
Map object. |
boolean |
anyoneBlocked() |
Check whether anyone is blocked.
|
private java.lang.Object[] |
checkDeadlock(ConcurrentLockSet.Entry entry,
ActiveLock waitingLock,
byte wakeupReason) |
Check whether there is a deadlock.
|
private ConcurrentLockSet.Entry |
getEntry(Lockable ref) |
Get an entry from the lock table.
|
int |
getWaitTimeout() |
Get the wait timeout in milliseconds.
|
Lock |
lockObject(CompatibilitySpace compatibilitySpace,
Lockable ref,
java.lang.Object qualifier,
int timeout) |
Lock an object within a specific compatibility space.
|
void |
oneLessWaiter() |
Decrease blockCount by one.
|
void |
oneMoreWaiter() |
Increase blockCount by one.
|
void |
setDeadlockTimeout(int timeout) |
Set the deadlock timeout.
|
void |
setDeadlockTrace(boolean val) |
Enable or disable tracing of deadlocks.
|
void |
setWaitTimeout(int timeout) |
Set the wait timeout.
|
java.util.Map<Lockable,Control> |
shallowClone() |
make a shallow clone of myself and my lock controls
|
private java.lang.String |
toDebugString() |
|
void |
unlock(Latch item,
int unlockCount) |
Unlock an object, previously locked by lockObject().
|
private void |
unlock(ConcurrentLockSet.Entry entry,
Latch item,
int unlockCount) |
Unlock an object, previously locked by lockObject().
|
Lock |
unlockReference(CompatibilitySpace space,
Lockable ref,
java.lang.Object qualifier,
java.util.Map group) |
Unlock an object once if it is present in the specified group.
|
boolean |
zeroDurationLockObject(CompatibilitySpace space,
Lockable ref,
java.lang.Object qualifier,
int timeout) |
Lock an object and release the lock immediately.
|
private final AbstractPool factory
private final java.util.concurrent.ConcurrentHashMap<Lockable,ConcurrentLockSet.Entry> locks
Lockable
objects to
Lock
s.private java.util.ArrayList<ConcurrentLockSet.Entry> seenByDeadlockDetection
addWaiters()
. Makes it possible for the deadlock detection
thread to lock all the entries it has visited until it has
finished. This prevents false deadlocks from being reported (because all
observed waiters must still be waiting when the deadlock detection has
completed).private int deadlockTimeout
private int waitTimeout
private boolean deadlockTrace
private final java.util.concurrent.atomic.AtomicInteger blockCount
ConcurrentLockSet(AbstractPool factory)
private ConcurrentLockSet.Entry getEntry(Lockable ref)
Lockable
, insert an entry. The returned entry will be
locked and is guaranteed to still be present in the table.ref
- the Lockable
whose entry to returnLockable
, locked for exclusive
accessprivate java.lang.Object[] checkDeadlock(ConcurrentLockSet.Entry entry, ActiveLock waitingLock, byte wakeupReason)
entry
- the entry in the lock table for the lock request that
triggered deadlock detectionwaitingLock
- the waiting lockwakeupReason
- the reason for waking up the waiterpublic Lock lockObject(CompatibilitySpace compatibilitySpace, Lockable ref, java.lang.Object qualifier, int timeout) throws StandardException
lockObject
in interface LockTable
compatibilitySpace
- Compatibility space.ref
- Lockable reference.qualifier
- Qualifier.timeout
- Timeout in milli-secondsStandardException
- Standard Derby policy.public void unlock(Latch item, int unlockCount)
private void unlock(ConcurrentLockSet.Entry entry, Latch item, int unlockCount)
entry
- the entry in which the lock is contained (the current
thread must have locked the entry)item
- the item to unlockunlockCount
- the number of times to unlock the item (if zero, take
the unlock count from item)public Lock unlockReference(CompatibilitySpace space, Lockable ref, java.lang.Object qualifier, java.util.Map group)
unlockReference
in interface LockTable
space
- the compatibility spaceref
- a reference to the locked objectqualifier
- qualifier of the lockgroup
- a map representing the locks in a groupnull
if
the object was not unlockedpublic boolean zeroDurationLockObject(CompatibilitySpace space, Lockable ref, java.lang.Object qualifier, int timeout) throws StandardException
Lock lock = lockTable.lockObject(space, ref, qualifier, timeout); lockTable.unlock(lock, 1);except that the implementation might be more efficient.
zeroDurationLockObject
in interface LockTable
space
- the compatibility spaceref
- a reference to the locked objectqualifier
- qualifier of the locktimeout
- maximum time to wait in milliseconds
(C_LockFactory.NO_WAIT
means don't wait)true
if the object was locked, or
false
if the object couldn't be locked immediately and timeout
was NO_WAIT
or LockOwner
had the noWait
flag setStandardException
- if the lock could not be obtainedpublic void setDeadlockTimeout(int timeout)
setDeadlockTimeout
in interface LockTable
timeout
- deadlock timeout in millisecondspublic void setWaitTimeout(int timeout)
setWaitTimeout
in interface LockTable
timeout
- wait timeout in millisecondspublic int getWaitTimeout()
getWaitTimeout
in interface LockTable
public void setDeadlockTrace(boolean val)
LockTable
setDeadlockTrace
in interface LockTable
val
- true
enables tracing, false
disables tracingprivate java.lang.String toDebugString()
public void addWaiters(java.util.Map<java.lang.Object,java.lang.Object> waiters)
Map
object.
This method can only be called by the thread that is currently
performing deadlock detection. All entries that are visited in the lock
table will be locked when this method returns. The entries that have
been seen and locked will be unlocked after the deadlock detection has
finished.addWaiters
in interface LockTable
waiters
- the map to add the waiters toLockControl.addWaiters(java.util.Map<java.lang.Object, java.lang.Object>)
public java.util.Map<Lockable,Control> shallowClone()
shallowClone
in interface LockTable
public void oneMoreWaiter()
oneMoreWaiter
in interface LockTable
public void oneLessWaiter()
oneLessWaiter
in interface LockTable
public boolean anyoneBlocked()
anyoneBlocked
in interface LockTable
true
if someone is blocked, false
otherwiseApache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.