Class LockControl

  • All Implemented Interfaces:
    Control

    final class LockControl
    extends java.lang.Object
    implements Control
    A LockControl contains a reference to the item being locked and doubly linked lists for the granted locks and the waiting locks.

    MT - Mutable - Container object : single thread required

    • Field Detail

      • firstGrant

        private Lock firstGrant
        This lock control uses an optimistic locking scheme. When the first lock on an object is granted it simply sets firstGrant to be that object, removing the need to allocate a list if no other locks are granted before the first lock is release. If a second lock is granted then a list is allocated and the firstGrant lock is moved into the list. Once a list has been created it is always used.
      • granted

        private java.util.List<Lock> granted
      • waiting

        private java.util.List<Lock> waiting
      • lastPossibleSkip

        private Lock lastPossibleSkip
    • Constructor Detail

      • LockControl

        protected LockControl​(Lock firstLock,
                              Lockable ref)
      • LockControl

        private LockControl​(LockControl copyFrom)
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface Control
      • grant

        void grant​(Lock lockItem)
        Grant this lock.
      • unlock

        public boolean unlock​(Latch lockInGroup,
                              int unlockCount)
        Specified by:
        unlock in interface Control
      • isGrantable

        public boolean isGrantable​(boolean noWaitersBeforeMe,
                                   CompatibilitySpace compatibilitySpace,
                                   java.lang.Object qualifier)
        This routine can be called to see if a lock currently on the wait list could be granted. If this lock has waiters ahead of it then we do not jump over the waiter(s) even if we can be granted. This avoids the first waiter being starved out.
        Specified by:
        isGrantable in interface Control
      • addLock

        public Lock addLock​(LockTable ls,
                            CompatibilitySpace compatibilitySpace,
                            java.lang.Object qualifier)
        Add a lock into this control, granted it if possible. This can be entered in several states.
      • The Lockable is locked (granted queue not empty), and there are no waiters (waiting queue is empty)
      • The Lockable is locked and there are waiters
      • The Lockable is locked and there are waiters and the first is potentially granted
      • The Lockable is unlocked and there are waiters and the first is potentially granted. Logically the item is still locked, it's just that the lock has just been released and the first waker has not woken up yet. This call is never entered when the object is unlocked and there are no waiters. 1) The Lockable has just been unlocked,