Attempt to immediately acquire a shared read lock.

@param locker object which might be write or upgrade lock owner
@return true if acquired
936
public final boolean tryLockForRead(L locker) {
        int state = mState;
        if (state >= 0) { // no write lock is held
            if (isReadWriteFirst() || isReadLockHeld(locker)) {
                do {
                    if (incrementReadLocks(state)) {
                        adjustReadLockCount(locker, 1);
                        return true;
                    }
                    // keep looping on CAS failure if a reader or upgrader mucked with the state
                } while ((state = mState) >= 0);
            }
        } else if (mOwner == locker) {
            // keep looping on CAS failure if a reader or upgrader mucked with the state
            while (!incrementReadLocks(state)) {
                state = mState;
            }
            adjustReadLockCount(locker, 1);
            return true;
        }
        return false;
    }
854316
private ClientRWLock getBlockLock(long blockId) {
    // Loop until we either find the block lock in the mLocks map, or successfully acquire a new
    // block lock from the lock pool.
    while (true) {
      ClientRWLock blockLock;
      // Check whether a lock has already been allocated for the block id.
      synchronized (mSharedMapsLock) {
        blockLock = mLocks.get(blockId);
        if (blockLock != null) {
          blockLock.addReference();
          return blockLock;
        }
      }
      // Since a block lock hasn't already been allocated, try to acquire a new one from the pool.
      // Acquire the lock outside the synchronized section because #acquire might need to block.
      // We shouldn't wait indefinitely in acquire because the another lock for this block could be
      // allocated to another thread, in which case we could just use that lock.
      blockLock = mLockPool.acquire(1, TimeUnit.SECONDS);
      if (blockLock != null) {
        synchronized (mSharedMapsLock) {
          // Check if someone else acquired a block lock for blockId while we were acquiring one.
          if (mLocks.containsKey(blockId)) {
            mLockPool.release(blockLock);
            blockLock = mLocks.get(blockId);
          } else {
            mLocks.put(blockId, blockLock);
          }
          blockLock.addReference();
          return blockLock;
        }
      }
    }
  }
424517
protected void peerAcquiringLock (PeerNode peer, NodeObject.Lock lock)
    {
        // refuse to ratify if we believe someone else owns the lock
        String owner = queryLock(lock);
        if (owner != null) {
            log.warning("Refusing to ratify lock acquisition.", "lock", lock,
                "node", peer.getNodeName(), "owner", owner);
            return;
        }

        // check for an existing handler
        LockHandler handler = _locks.get(lock);
        if (handler == null) {
            createLockHandler(peer, lock, true);
            return;
        }

        // if the existing node has priority, we're done
        if (hasPriority(handler.getNodeName(), peer.getNodeName())) {
            return;
        }

        // the new node has priority, so cancel the existing handler and take over
        // its listeners
        ResultListenerList<String> olisteners = handler.listeners;
        handler.cancel();
        handler = createLockHandler(peer, lock, true);
        handler.listeners = olisteners;
    }
1360970
public boolean unlock() throws IOException {
		if (lock != null) {
			lock.release();
			lock = null;
			return true;
		}
		return false;
	}
736907
public boolean hasReadLock(TransactionImpl tx, Object obj)
    {
        checkTimedOutLocks();

        Identity oid = new Identity(obj,getBroker());
        String oidString = oid.toString();
		String txGuid = tx.getGUID();
        return hasReadLockInternal(oidString, txGuid);
    }
818958
public final void unlockFromWrite(L locker) {
        int writeCount = mWriteCount - 1;
        if (writeCount < 0) {
            throw new IllegalMonitorStateException("Too many write locks released");
        }
        mWriteCount = writeCount;
        if (writeCount > 0) {
            return;
        }

        // copy original state to check if upgrade lock was automatic
        final int state = mState;

        // make sure upgrade lock is still held after releasing write lock
        mState = LOCK_STATE_UPGRADE;

        Node h = mRWHead;
        if (h != null && h.mWaitStatus != 0) {
            unparkReadWriteSuccessor(h);
        }

        if (state == LOCK_STATE_WRITE) {
            // upgrade owner was automatically set, so automatically clear it
            unlockFromUpgrade(locker);
        }
    }
653524
private boolean sLockable(Lockers lks, long txNum) {
		return (!xLocked(lks) || hasXLock(lks, txNum))
				&& (!sixLocked(lks) || hasSixLock(lks, txNum))
				&& (!ixLocked(lks) || isTheOnlyIxLocker(lks, txNum));
	}
192409
public boolean addReader(TransactionImpl tx, Object obj)
	{
		try
		{
			LockEntry lock = new LockEntry(new Identity(obj,getBroker()).toString(),
					tx.getGUID(),
					System.currentTimeMillis(),
					LockStrategyFactory.getIsolationLevel(obj),
					LockEntry.LOCK_READ);
            addReaderRemote(lock);
			return true;
		}
		catch (Throwable t)
		{
			log.error("Cannot store LockEntry for object " + obj + " in transaction " + tx, t);
			return false;
		}
	}
1090210
def acquire(self, blocking=True, timeout=None):
        
        logger.debug("Getting %r ...", self._name)

        if self._held:
            raise AlreadyAcquired("Already acquired from this Lock instance.")

        if not blocking and timeout is not None:
            raise TimeoutNotUsable("Timeout cannot be used if blocking=False")

        timeout = timeout if timeout is None else int(timeout)
        if timeout is not None and timeout <= 0:
            raise InvalidTimeout("Timeout (%d) cannot be less than or equal to 0" % timeout)

        if timeout and self._expire and timeout > self._expire:
            raise TimeoutTooLarge("Timeout (%d) cannot be greater than expire (%d)" % (timeout, self._expire))

        busy = True
        blpop_timeout = timeout or self._expire or 0
        timed_out = False
        while busy:
            busy = not self._client.set(self._name, self._id, nx=True, ex=self._expire)
            if busy:
                if timed_out:
                    return False
                elif blocking:
                    timed_out = not self._client.blpop(self._signal, blpop_timeout) and timeout
                else:
                    logger.debug("Failed to get %r.", self._name)
                    return False

        logger.debug("Got lock for %r.", self._name)
        if self._lock_renewal_interval is not None:
            self._start_lock_renewer()
        return True
315529
public boolean upgradeLock(LockEntry reader)
    {
        checkTimedOutLocks();

        String oidString = reader.getOidString();
        ObjectLocks objectLocks = null;
        synchronized (locktable)
        {
	        objectLocks = (ObjectLocks) locktable.get(oidString);
        }

        if (objectLocks == null)
        {
            return false;
        }
        else
        {
            // add writer entry
            LockEntry writer = new LockEntry(reader.getOidString(),
                    reader.getTransactionId(),
                    System.currentTimeMillis(),
                    reader.getIsolationLevel(),
                    LockEntry.LOCK_WRITE);
            objectLocks.setWriter(writer);
            // remove reader entry
            objectLocks.getReaders().remove(reader.getTransactionId());
            return true;
        }
    }
1083130
def release_read_lock
      while(true)
        c = @counter.value
        if @counter.compare_and_swap(c,c-1)
          if waiting_writer?(c) && running_readers(c) == 1
            @writer_mutex.synchronize { @writer_q.signal }
          end
          break
        end
      end
      true
    end
831742
public boolean acquire(final Lock lock) {
        lock.setUniqueId(this.uniqueId);
        if (this.lockTimeout > 0) {
            lock.setExpirationDate(ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(this.lockTimeout));
        } else {
            lock.setExpirationDate(null);
        }
        var success = false;
        try {
            if (lock.getApplicationId() != null) {
                this.entityManager.merge(lock);
            } else {
                lock.setApplicationId(this.applicationId);
                this.entityManager.persist(lock);
            }
            success = true;
        } catch (final Exception e) {
            success = false;
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[{}] could not obtain [{}] lock.", this.uniqueId, this.applicationId, e);
            } else {
                LOGGER.info("[{}] could not obtain [{}] lock.", this.uniqueId, this.applicationId);
            }
        }
        return success;
    }
1091120
private final Result lockForUpgradeInterruptibly_(L locker) throws InterruptedException {
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Result result;
        if ((result = tryLockForUpgrade_(locker)) == Result.FAILED) {
            result = lockForUpgradeQueuedInterruptibly(locker, addUpgradeWaiter());
        }
        return result;
    }
915538
public static synchronized org.apache.ojb.odmg.locking.LockManager getLockManager()
    {
        if(lockManagerFactory == null)
        {
            lockManagerFactory = new LockManagerFactory();
        }
        return lockManagerFactory.getManager();
    }
119490
synchronized int release(Locker locker) {

        //-----------------------------------------------------------------
        // A transaction can be both a holder and a waiter if
        // it is attempting to convert a shared lock to an exclusive one.
        //-----------------------------------------------------------------

        if (holders.remove(locker) != null) {
            numUsers--;
        }

        Waiter waiter = (Waiter) waiters.remove(locker);
        if (waiter != null) {
            numUsers--;
            synchronized (waiter) {
                waitQ.removeElement(waiter);
                waiter.released = true;
                lockMgr.unwaitEvent(waiter);
                waiter.notify();
            }
        }

        //----------------------------------------------------------------
        // Q: Do we care about attempts to release locks for given locker
        //    that are not held by that locker? If so fail here if locker
        //    was neither holder nor waiter.
        //----------------------------------------------------------------

        //----------------------------------------------------------
        // If there are no more holders then wake up all compatible
        // waiters from the head of the wait queue. This imposes a
        // strict FIFO scheduling.
        //----------------------------------------------------------

        if (holders.size() == 0) {

            //-------------------------------------------------
            // Grant first waiter the lock and then see if the
            // remaining waiters are compatible.
            //-------------------------------------------------

            if (waiters.size() > 0) {
                Waiter newHolder = (Waiter) waitQ.firstElement();
                synchronized (newHolder) {
                    waiters.remove(newHolder.locker);
                    waitQ.removeElementAt(0);
                    holders.put(newHolder.locker, newHolder.locker);
                    this.mode = newHolder.mode;
                    lockMgr.unwaitEvent(newHolder);
                    newHolder.notify();
                }
            }

            //--------------------------------------------------
            // If lock now held in exclusive mode we are done,
            // else grant lock to all waiters at head of queue
            // that are requesting the lock in the SHARED mode.
            //--------------------------------------------------

            if (mode == LockManager.EXCLUSIVE) {
                return numUsers;
            }

            while (waiters.size() > 0) {
                Waiter newHolder = (Waiter) waitQ.firstElement();
                if (newHolder.mode == LockManager.EXCLUSIVE) {
                    return numUsers;
                }

                synchronized (newHolder) {
                    waiters.remove(newHolder.locker);
                    waitQ.removeElementAt(0);
                    holders.put(newHolder.locker, newHolder.locker);
                    lockMgr.unwaitEvent(newHolder);
                    newHolder.notify();
                }
            }
        }
        return numUsers;

    }
232941
@Override
    public synchronized void releaseReadLock(final Lock lock) {
        if (lock == null || lock.name == null || lock.name.isEmpty()) {
            throw new InvalidArgument("lock is invalid");
        }

        if (locks.containsKey(lock.name)) {
            locks.remove(lock.name);

            final Set<File> readLocks = getReadLocks();
            for (final File readLock : readLocks) {
                if (readLock.getName().endsWith(lock.name)) {
                    if (!readLock.delete()) {
                        throw new IllegalStateException(
                                "read lock could not be deleted");
                    }

                    readLocks.remove(readLock);
                    return;
                }
            }
        }

        throw new InvalidArgument("read lock '" + lock.name
                + "' is unknown");
    }
335319
@SuppressWarnings("unchecked")
    @Override
    synchronized public V get(Object key) {
        if(!this.containsKey(key)) {
            super.put((K) key, readBack((K) key));
        }

        return super.get(key);
    }