/*!
Lock. Blocks untill the mutex becomes available

\return true if lock is successfull.
false if it fails to require a lock.
519832
function lock()
    {
        if ( $fp = $this->fp() )
        {
            if ( flock( $fp, LOCK_EX ) )
            {
                $this->clearMeta();
                $this->setMeta( 'timestamp', time() );
                return true;
            }
        }
        return false;
    }
87761
public void lock() {
		if (cancel != null)
			return;
		if (error != null)
			return;
		Thread t;
		BlockedThreadHandler blockedHandler;
		do {
			synchronized (this) {
				if (!locked) {
					locked = true;
					return;
				}
				t = Thread.currentThread();
				blockedHandler = Threading.getBlockedThreadHandler(t);
				if (blockedHandler != null) break;
				try { this.wait(0); }
				catch (InterruptedException e) { continue; }
			}
		} while (true);
		blockedHandler.blocked(this, 0);
	}
1199810
public function lock($key, $timeout = self::EXPIRE): bool
    {
        $wait = 20000;
        $totalWait = 0;
        $time = $timeout * 1000000;
        $key = self::PREFIX . $key;

        while ($totalWait < $time && false === $this->mem->add($key, 1, $timeout)) {
            usleep($wait);
            $totalWait += $wait;
        }

        if ($totalWait >= $time) {
            throw new \RuntimeException('cannot get lock for waiting ' . $timeout . 's.', __LINE__);
        }

        return true;
    }
160826
public function isLocked($plugin)
    {
        $requiredBy = $this->getRequiredBy($plugin);

        foreach ($requiredBy as $required) {
            if ($this->isLoaded($required)) {
                return true;
            }
        }

        return false;
    }
929730
function try_lock( $expiration = 0 ) {
            if ( $this->is_locked() ) {
                // Already locked.
                return false;
            }

            set_site_transient( "locked_{$this->_wp_user_id}", $this->_thread_id, $expiration );

            if ( $this->has_lock() ) {
                set_site_transient( "locked_{$this->_wp_user_id}", true, $expiration );

                return true;
            }

            return false;
        }
214578
public final boolean tryLockForRead(L locker, long timeout, TimeUnit unit)
        throws InterruptedException
    {
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        if (!tryLockForRead(locker)) {
            return lockForReadQueuedInterruptibly(locker, addReadWaiter(), unit.toNanos(timeout));
        }
        return true;
    }
1335611
private final void contendedLock() {
            boolean waiting = false;
            for (int s;;) {
                if (((s = lockState) & ~WAITER) == 0) {
                    if (U.compareAndSwapInt(this, LOCKSTATE, s, WRITER)) {
                        if (waiting)
                            waiter = null;
                        return;
                    }
                }
                else if ((s & WAITER) == 0) {
                    if (U.compareAndSwapInt(this, LOCKSTATE, s, s | WAITER)) {
                        waiting = true;
                        waiter = Thread.currentThread();
                    }
                }
                else if (waiting)
                    LockSupport.park(this);
            }
        }
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);
    });
}
47725
function isTaskLocked(task) {
  if(task.semaphore) {
    if(!task.semaphore.ttl) {
      throw new TypeError('TimeToLiveNotPresent');
    }
    return ( (timestamp() - task.semaphore.time) < task.semaphore.ttl );
  }
  return false;
}
203318
function mutex($id,$func,$args=NULL) {
		if (!is_dir($tmp=$this->hive['TEMP']))
			mkdir($tmp,self::MODE,TRUE);
		// Use filesystem lock
		if (is_file($lock=$tmp.
			$this->get('SEED').'.'.$this->hash($id).'.lock') &&
			filemtime($lock)+ini_get('max_execution_time')<microtime(TRUE))
			// Stale lock
			@unlink($lock);
		while (!($handle=@fopen($lock,'x')) && !connection_aborted())
			usleep(mt_rand(0,100));
		$this->locks[$id]=$lock;
		$out=$this->call($func,$args);
		fclose($handle);
		@unlink($lock);
		unset($this->locks[$id]);
		return $out;
	}
370869
public function lock($mode = LOCK_SH)
    {

        if (!is_resource($this->fp)) return false;

        if (flock($this->fp, $mode) === false) return false;

        if ($mode != LOCK_UN) $this->file_lock = true;
        else $this->file_lock = false;

        return true;
    }
1029372
def try_lock(lock):
    """"""
    # NOTE(harlowja): the keyword argument for 'blocking' does not work
    # in py2.x and only is fixed in py3.x (this adjustment is documented
    # and/or debated in http://bugs.python.org/issue10789); so we'll just
    # stick to the format that works in both (oddly the keyword argument
    # works in py2.x but only with reentrant locks).
    was_locked = lock.acquire(False)
    try:
        yield was_locked
    finally:
        if was_locked:
            lock.release()
986261
public function isLocked(): bool
	{
		return $this->locked_until !== null && $this->locked_until->getTimestamp() >= Time::now()->getTimestamp();
	}
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;

	}
1356316
public function lock($lockName)
    {
        $lockHandle = $this->lockProvider->lock($lockName);

        if ($lockHandle === false) {
            return false;
        }

        $this->lockList[$lockName] = $lockHandle;
        return true;
    }
417987
public function isLocked($name)
    {
        if ($this->acquireLock($name, false)) {
            return !$this->releaseLock($name);
        }

        return true;
    }
126620
def lock(self, block=True):
		
		self._locked = True
		return self._lock.acquire(block)