An identity-keyed inter-process lock for safeguarding lifecycle and other operations.
5876
def lifecycle_lock(self):
    """"""
    safe_mkdir(self._metadata_base_dir)
    return OwnerPrintingInterProcessFileLock(
      # N.B. This lock can't key into the actual named metadata dir (e.g. `.pids/pantsd/lock`
      # via `ProcessMetadataManager._get_metadata_dir_by_name()`) because of a need to purge
      # the named metadata dir on startup to avoid stale metadata reads.
      os.path.join(self._metadata_base_dir, '.lock.{}'.format(self._name))
    )
898695
private static GlobalInterlock _findAndRefreshLock(EntityManager em, long type) {
        GlobalInterlock lock = em.find(GlobalInterlock.class, type);

        if (lock != null) {
            try {
                em.refresh(lock);
                lock = em.find(GlobalInterlock.class, type);
            } catch (EntityNotFoundException ex) {
                LOGGER.warn("Lock of type {} was expired by another process.", type);
                lock = null;
            }
        }
        return lock;
    }
1207132
def lock_exists_in_either_channel_side(
        channel_state: NettingChannelState,
        secrethash: SecretHash,
) -> bool:
    """"""
    lock = get_lock(channel_state.our_state, secrethash)
    if not lock:
        lock = get_lock(channel_state.partner_state, secrethash)
    return lock is not None
1063560
void unlockBucketsWrite(long i1, long i2) {
		int bucket1LockIdx = getBucketLock(i1);
		int bucket2LockIdx = getBucketLock(i2);
		// always unlock segments in same order to avoid deadlocks
		if (bucket1LockIdx == bucket2LockIdx) {
			lockAry[bucket1LockIdx].tryUnlockWrite();
			return;
		}
		lockAry[bucket1LockIdx].tryUnlockWrite();
		lockAry[bucket2LockIdx].tryUnlockWrite();
	}
47451
def _lock(self):
        """"""
        if not self.locked:
            self.device.cu.lock()
            self.locked = True
878800
def lock(instance_id, profile=None, **kwargs):
    '''
    

    '''
    conn = _auth(profile, **kwargs)
    return conn.lock(instance_id)
679164
function _runIfLocked() {
    var self = this;

    self._clusterUtils._setLock(self.lockKey, function(err, lock) {
        if (err) {
            throw err;
        } else if (!lock) {
            return;
        }

        process.nextTick(self._func);
    });
}
1334594
function (seq, release, done) {
      lockRelease = release
      latestSeq = seq

      hashNodesAndFindLinks(nodes, done)
    }
1220188
protected void handleLockExpiry(SharedSessionContractImplementor session, Object key, Lockable lock) {
        long ts = region.nextTimestamp() + region.getTimeout();
        // create new lock that times out immediately
        Lock newLock = new Lock(ts, uuid, nextLockId.getAndIncrement(), null);
        newLock.unlock(ts);
        region.put(session, key, newLock);
    }
1360256
private void lockInodeInternal(Inode inode, LockMode mode) {
    Preconditions.checkState(!endsInInode());
    String lastEdgeName = ((EdgeEntry) lastEntry()).getEdge().getName();
    Preconditions.checkState(inode.getName().equals(lastEdgeName),
        "Expected to lock inode %s but locked inode %s", lastEdgeName, inode.getName());

    mLockedInodes.add(inode);
    mEntries.add(new InodeEntry(mInodeLockManager.lockInode(inode, mode), inode));
  }
851410
function polylock (params) {

		if (params === undefined)
			params = {};

		this.queue       = new polylock_ll();
		this.ex_locks    = {};
		this.ex_reserved = {};
		this.sh_locks    = {};
		this.op_num      = 1;

		this.drain_for_writes = params.write_priority ? true : false;

	}
1320213
def datalock(self, acquire=True):
        # type: (_BaseResumeManager) -> None
        
        if acquire:
            self._lock.acquire()
        try:
            yield
        finally:
            if acquire:
                self._lock.release()
971428
function isLockHolder(task, requestorId) {
  if(!task.semaphore) {
    throw new LockError('TaskNotLocked');
  }
  var requestKey  = hashKey(requestorId, task.id);

  return requestKey === task.semaphore.key;
}
31870
def lock_machine(uuid)
      lock_path = @data_dir.join("#{uuid}.lock")
      lock_file = lock_path.open("w+")
      if lock_file.flock(File::LOCK_EX | File::LOCK_NB) === false
        lock_file.close
        lock_file = nil
      end

      lock_file
    end
1126018
protected void ensureDeviceCacheHolder(Integer deviceId, AllocationShape shape) {
        if (!deviceCache.containsKey(deviceId)) {
            try {
                synchronized (this) {
                   if (!deviceCache.containsKey(deviceId)) {
                        deviceCache.put(deviceId, new ConcurrentHashMap<AllocationShape, CacheHolder>());
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        if (!deviceCache.get(deviceId).containsKey(shape)) {
            try {
                singleLock.acquire();

                if (!deviceCache.get(deviceId).containsKey(shape)) {
                    deviceCache.get(deviceId).put(shape, new CacheHolder(shape, deviceCachedAmount.get(deviceId)));
                }
            } catch (Exception e) {

            } finally {
                singleLock.release();
            }
        }
    }
1061252
private void syncToOSThread(WebSecurityContext webSecurityContext) throws SecurityViolationException {
        try {
            Object token = ThreadIdentityManager.setAppThreadIdentity(subjectManager.getInvocationSubject());
            webSecurityContext.setSyncToOSThreadToken(token);
        } catch (ThreadIdentityException tie) {
            SecurityViolationException secVE = convertWebSecurityException(new WebSecurityCollaboratorException(tie.getMessage(), DENY_AUTHZ_FAILED, webSecurityContext));
            throw secVE;
        }
    }
827769
private void internalLockResource(CmsLock lock, Map<String, CmsLock> locks) throws CmsLockException {

        CmsLock currentLock = null;
        if (locks == null) {
            currentLock = OpenCms.getMemoryMonitor().getCachedLock(lock.getResourceName());
        } else {
            currentLock = locks.get(lock.getResourceName());
        }
        if (currentLock != null) {
            if (currentLock.getSystemLock().equals(lock) || currentLock.getEditionLock().equals(lock)) {
                return;
            }
            if (!currentLock.getSystemLock().isUnlocked() && lock.getSystemLock().isUnlocked()) {
                lock.setRelatedLock(currentLock);
                if (locks == null) {
                    OpenCms.getMemoryMonitor().cacheLock(lock);
                } else {
                    locks.put(lock.getResourceName(), lock);
                }
            } else if (currentLock.getSystemLock().isUnlocked() && !lock.getSystemLock().isUnlocked()) {
                currentLock.setRelatedLock(lock);
            } else {
                throw new CmsLockException(
                    Messages.get().container(Messages.ERR_LOCK_ILLEGAL_STATE_2, currentLock, lock));
            }
        } else {
            if (locks == null) {
                OpenCms.getMemoryMonitor().cacheLock(lock);
            } else {
                locks.put(lock.getResourceName(), lock);
            }
        }
    }