Lock all objects reachable via 1:N and N:1 relations,
@param lock The lock type to use
513170
private void lockReachableObjects(Identity oid, Object userObject,
            Object cacheObject, int lock, Stack stack, boolean buildingObject)
            throws LockingException
    {
        ContextEntry entry;
        boolean onlyDependants = !_tx.getKit().isImplicitLockingUsed();
        ClassDescriptor mif = _pb.getClassDescriptor(userObject.getClass());

        // N:1 relations
        Iterator iter = mif.getObjectReferenceDescriptors().iterator();
        ObjectReferenceDescriptor rds = null;
        PersistentField f;
        Object relUserObj;
        Identity relOid;
        boolean isDependent;

        while (iter.hasNext())
        {
            rds = (ObjectReferenceDescriptor) iter.next();
            isDependent = rds.getOtmDependent();
            if (onlyDependants && !isDependent)
            {
                continue;
            }
            f = rds.getPersistentField();
            relUserObj = f.get(userObject);
            if (relUserObj != null)
            {
                relOid = new Identity(relUserObj, _pb);
                entry = (ContextEntry) _objects.get(relOid);
                if ((entry == null) || (entry.userObject != relUserObj))
                {
                    entry = insertInternal(relOid, relUserObj, lock, isDependent,
                                           oid, stack);
                    if (buildingObject && (entry != null))
                    {
                        f.set(userObject, entry.userObject);
                        f.set(cacheObject, entry.cacheObject);
                    }
                }
            }
        }

        // 1:N relations
        Iterator collections = mif.getCollectionDescriptors().iterator();
        CollectionDescriptor cds;
        Object userCol;
        Iterator userColIterator;
        Class type;
        ArrayList newUserCol = null;
        ArrayList newCacheCol = null;

        while (collections.hasNext())
        {
            cds = (CollectionDescriptor) collections.next();
            f = cds.getPersistentField();
            type = f.getType();
            isDependent = cds.getOtmDependent();
            if (onlyDependants && !isDependent)
            {
                continue;
            }
            userCol = f.get(userObject);
            if (userCol != null)
            {
                if ((userCol instanceof CollectionProxyDefaultImpl)
                        && !((CollectionProxyDefaultImpl) userCol).isLoaded())
                {
                    continue;
                }

                if (buildingObject)
                {
                    newUserCol = new ArrayList();
                    newCacheCol = new ArrayList();
                }

                if (Collection.class.isAssignableFrom(type))
                {
                    userColIterator = ((Collection) userCol).iterator();
                }
                else if (type.isArray())
                {
                    userColIterator = new ArrayIterator(userCol);
                }
                else
                {
                    throw new OJBRuntimeException(
                        userCol.getClass()
                            + " can not be managed by OJB OTM, use Array or Collection instead !");
                }

                while (userColIterator.hasNext())
                {
                    relUserObj = userColIterator.next();
                    relOid = new Identity(relUserObj, _pb);
                    entry = (ContextEntry) _objects.get(relOid);
                    if ((entry == null) || (entry.userObject != relUserObj))
                    {
                        entry = insertInternal(relOid, relUserObj, lock,
                                               isDependent, null, stack);
                    }
                    if (buildingObject && (entry != null))
                    {
                        newUserCol.add(entry.userObject);
                        newCacheCol.add(entry.cacheObject);
                    }
                }
                if (buildingObject)
                {
                    setCollectionField(userObject, f, newUserCol);
                    setCollectionField(cacheObject, f, newCacheCol);
                }
            }
        }
    }
717381
function lock(obj, freeze, options) {
    if (options && options.noLocking) {
        return;
    }
    if (freeze) {
        Object.freeze(obj); // freeze the entire object, permanently;
    } else {
        const desc = {
            writable: false,
            configurable: false,
            enumerable: true
        };
        for (const p in obj) {
            Object.defineProperty(obj, p, desc);
        }
    }
}
808135
private void lockWritersExclusive() {

        if (exclusiveLockOwner == Thread.currentThread()) {
            writers.decrementAndGet();
            return;
        }

        synchronized (this) {
            for (;;) {

                if (writers.compareAndSet(0, -1)) {
                    exclusiveLockOwner = Thread.currentThread();
                    return;
                }
            }
        }
    }
870152
void writeLock(int count) {
      if (count > 0 && counter != null)
         counter.acquireShared(count);
      sync.acquireShared(1);
   }
1156633
@Override
	public final void lock(int handle) throws DataStoreException 
    {
        if (SAFE_MODE) checkHandle(handle);
        if (!locks.flip(handle))
        {
            locks.flip(handle); // Restore state
            throw new DataStoreException("Handle already locked : "+handle);
        }
    }
213355
private void unlock(Object holder) throws PSQLException {
    if (lockedFor != holder) {
      throw new PSQLException(GT.tr("Tried to break lock on database connection"),
          PSQLState.OBJECT_NOT_IN_STATE);
    }
    lockedFor = null;
    this.notify();
  }
70926
public void releaseLock (final NodeObject.Lock lock, final ResultListener<String> listener)
    {
        // wait until any pending resolution is complete
        queryLock(lock, new ChainedResultListener<String, String>(listener) {
            public void requestCompleted (String result) {
                if (Objects.equal(_nodeName, result)) {
                    if (_suboids.isEmpty()) {
                        lockReleased(lock, listener);
                    } else {
                        _locks.put(lock, new LockHandler(lock, false, listener));
                    }
                } else {
                    if (result != null) {
                        log.warning("Tried to release lock held by another peer", "lock", lock,
                                    "owner", result);
                    }
                    listener.requestCompleted(result);
                }
            }
        });
    }
517815
void lockBucketsWrite(long i1, long i2) {
		int bucket1LockIdx = getBucketLock(i1);
		int bucket2LockIdx = getBucketLock(i2);
		// always lock segments in same order to avoid deadlocks
		if (bucket1LockIdx < bucket2LockIdx) {
			lockAry[bucket1LockIdx].writeLock();
			lockAry[bucket2LockIdx].writeLock();
		} else if (bucket1LockIdx > bucket2LockIdx) {
			lockAry[bucket2LockIdx].writeLock();
			lockAry[bucket1LockIdx].writeLock();
		}
		// if we get here both indexes are on same segment so only lock once!!!
		else {
			lockAry[bucket1LockIdx].writeLock();
		}
	}
1147848
protected void removeAll()
   {
      List<LockData> locks = getLockList();
      for (LockData lockData : locks)
      {
         removeLock(lockData.getNodeIdentifier());
      }
   }
251623
public void setLocked(boolean locked) {
		if (ap == null) {
			return;
		}
		ap.setLocked(locked);
		btnPin.setVisible(! locked);
		if (!ap.isPinned()) {
			// Wont be visible if its pinned
			btnClose.setVisible(! locked);
		}
	}
993862
private void queueActionLocked(DeltaType actionType, Object obj) {
    String id = this.keyOf(obj);

    // If object is supposed to be deleted (last event is Deleted),
    // then we should ignore Sync events, because it would result in
    // recreation of this object.
    if (actionType == DeltaType.Sync && this.willObjectBeDeletedLocked(id)) {
      return;
    }

    Deque<MutablePair<DeltaType, Object>> deltas = items.get(id);
    if (deltas == null) {
      Deque<MutablePair<DeltaType, Object>> deltaList = new LinkedList<>();
      deltaList.add(new MutablePair(actionType, obj));
      deltas = new LinkedList<>(deltaList);
    } else {
      deltas.add(new MutablePair<DeltaType, Object>(actionType, obj));
    }

    // TODO(yue9944882): Eliminate the force class casting here
    Deque<MutablePair<DeltaType, Object>> combinedDeltaList =
        combineDeltas((LinkedList<MutablePair<DeltaType, Object>>) deltas);

    boolean exist = items.containsKey(id);
    if (combinedDeltaList != null && combinedDeltaList.size() > 0) {
      if (!exist) {
        this.queue.add(id);
      }
      this.items.put(id, new LinkedList<>(combinedDeltaList));
      notEmpty.signalAll();
    } else {
      this.items.remove(id);
    }
  }
371165
protected synchronized void lock(ManagedObject managedObject)
                    throws ObjectManagerException
    {
        throw new InvalidStateException(this, InternalTransaction.stateTerminated, InternalTransaction.stateNames[InternalTransaction.stateTerminated]);
    }
165866
public void lock() {
		if (cancel != null)
			return;
		if (error != null)
			return;
		Thread t = Thread.currentThread();
		if (t == lockingThread) {
			lockedTimes++;
			return;
		}
		BlockedThreadHandler blockedHandler = null;
		do {
			synchronized (this) {
				if (lockingThread == null) {
					lockingThread = t;
					lockedTimes = 1;
					return;
				}
				if (blockedHandler == null)
					blockedHandler = Threading.getBlockedThreadHandler(t);
				if (blockedHandler == null) {
					try { this.wait(0); }
					catch (InterruptedException e) { /* ignore */ }
					continue;
				}
			}
			blockedHandler.blocked(this, 0);
		} while (true);
	}
1267844
protected function _lock($object, $lock)
    {
        if ($lock) {
            self::$_locks[$object->getHandle()] = true;
        } else {
            unset(self::$_locks[$object->getHandle()]);
        }
    }
845637
public void intersectWith(LockSet other) {
        for (int i = 0; i + 1 < array.length; i += 2) {
            int valueNumber = array[i];
            if (valueNumber < 0) {
                break;
            }
            int myLockCount = array[i + 1];
            if (myLockCount <= 0) {
                continue;
            }
            int otherLockCount = other.getLockCount(valueNumber);
            if (otherLockCount <= 0) {
                /* This set holds the lock, but the other one doesn't. */
                array[i + 1] = 0;
            }
        }
    }
1053247
final void cleanLocks() throws RepositoryException {
        // clean the session-scoped locks: unlock all the nodes and remove the lock tokens from the system area
        Set<String> cleanedTokens = lockManager.cleanLocks(session);
        if (lockTokens.isEmpty()) {
            return;
        }
        // clean all open-scoped locks created via this session
        for (String lockToken : lockTokens) {
            if (!cleanedTokens.contains(lockToken)) {
                ModeShapeLock lock = lockManager.findLockByToken(lockToken);
                if (lock == null) {
                    // there is no existing lock for this token (it must've been removed from somewhere else)
                    continue;
                }
                // this is an open-scoped lock created via this session for which we'll have to update the 'held' flag
                if (!lockManager.setHeldBySession(session, lockToken, false)) {
                    // Generally not expected, because if the lock exists we can always change the lock-held value to false
                    // even when it is already false ...
                    throw new LockException(JcrI18n.invalidLockToken.text(lockToken));
                }
            }
        }
        // always clean our internal map of tokens
        lockTokens.clear();
    }
706291
private void lockAndRegisterReferences(ClassDescriptor cld, Object sourceObject, int lockMode, List registeredObjects) throws LockNotGrantedException
    {
        if (implicitLocking)
        {
            Iterator i = cld.getObjectReferenceDescriptors(true).iterator();
            while (i.hasNext())
            {
                ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
                Object refObj = rds.getPersistentField().get(sourceObject);
                if (refObj != null)
                {
                    boolean isProxy = ProxyHelper.isProxy(refObj);
                    RuntimeObject rt = isProxy ? new RuntimeObject(refObj, this, false) : new RuntimeObject(refObj, this);
                    if (!registrationList.contains(rt.getIdentity()))
                    {
                        lockAndRegister(rt, lockMode, registeredObjects);
                    }
                }
            }
        }
    }