Executes a block wrapped in a ZK exclusive lock.
167395
def with_lock
      @zk_lock ||= @zk.locker(current_lock_path)

      begin
        @zk_lock.lock!(true)
      rescue Exception
        # handle shutdown case
        running? ? raise : return
      end

      if running?
        @zk_lock.assert!
        yield
      end
    ensure
      if @zk_lock
        begin
          @zk_lock.unlock!
        rescue => ex
          logger.warn("Failed to release lock: #{ex.inspect}")
        end
      end
    end
493585
function Block(options) {
  if (!(this instanceof Block))
    return new Block(options);

  AbstractBlock.call(this);

  this.txs = [];

  this._raw = null;
  this._size = -1;
  this._witness = -1;

  if (options)
    this.fromOptions(options);
}
1274605
public void acquireAllLocks(List<Object> keys, boolean exclusive) {
      for (Object k : keys) {
        acquireLock(k, exclusive);
    }
   }
742931
def simple_locking(lock_id, expiration=None):
    
    def inner_decorator(function):
        def wrapper(*args, **kwargs):
            try:
                # Trying to acquire lock
                lock = Lock.acquire_lock(lock_id, expiration)
            except LockError:
                # Unable to acquire lock - non fatal
                pass
            else:
                # Lock acquired, proceed normally, release lock afterwards
                logger.debug('acquired lock: %s' % lock_id)
                try:
                    return function(*args, **kwargs)
                except:
                    # Re raise any exception that occured when calling wrapped
                    # function
                    raise
                finally:
                    lock.release()
        return wraps(function)(wrapper)
    return inner_decorator
758205
public static void runByBoolean(boolean bool, Runnable trueBlock,
            Runnable falseBlock) {
        if (bool)
            trueBlock.run();
        else
            falseBlock.run();
    }
468569
@ConditionBlock
  public void evaluate(Runnable block) {
    try {
      block.run();
    } catch (Throwable t) {
      exceptions.add(t);
      wakeUp();
    }
    latch.countDown();
  }
1084626
def _exclusive_lock(path):
    """"""
    _create_file_dirs(path)
    fd = os.open(path, os.O_WRONLY | os.O_CREAT, 0o600)

    try:
        retries_left = _LOCK_RETRIES
        success = False

        while retries_left > 0:
            # try to acquire the lock in a loop
            # because gevent doesn't treat flock as IO,
            # so waiting here without yielding would get the worker killed
            try:
                fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
                success = True
                break
            except IOError as e:
                if e.errno in [errno.EAGAIN, errno.EWOULDBLOCK]:
                    # This yields execution to other green threads.
                    gevent.sleep(_LOCK_SLEEP_TIME_S)
                    retries_left -= 1
                else:
                    raise

        if success:
            yield
        else:
            raise ConcurrentModificationError(path)
    finally:
        if success:
            fcntl.flock(fd, fcntl.LOCK_UN)
        os.close(fd)
464369
private void runSubmissions(boolean block) throws InterruptedException {
        if (block) {
            Runnable r = m_submissionQueue.take();
            do {
                r.run();
            } while ((r = m_submissionQueue.poll()) != null);
        } else {
            Runnable r = null;
            while ((r = m_submissionQueue.poll()) != null) {
                r.run();
            }
        }
    }
232996
def state_run_block(channel)
      debug :run_block
      channel[:state] = nil
      blk = channel[:block]
      channel[:block] = nil
      begin
        instance_eval &blk
      rescue => ex
        channel[:exception] = ex
      end
      channel[:state] = :exit
    end
365116
def if_state(*expected_states)
      mutex.lock
      raise ArgumentError, 'no block given' unless block_given?

      if expected_states.include? @state
        yield
      else
        false
      end
    ensure
      mutex.unlock
    end
644531
private Map<String, Object> bindBlocks(PrepareSignatureContext sig, PrepareInvocationContext inv) {

    if(inv == null) {
      return Collections.emptyMap();
    }
    
    BlockDeclContext allDecl = null;
    BlockDeclContext unnamedDecl = null;
    
    List<NamedOutputBlockContext> namedBlocks = new ArrayList<>(inv.namedBlocks);
    Map<String, Object> blocks = new HashMap<>();
    
    for (BlockDeclContext blockDecl : sig.blockDecls) {
      
      if (blockDecl.flag != null) {
        if (blockDecl.flag.getText().equals("*")) {
          if (allDecl != null) {
            throw new ExecutionException("only a single parameter can be marked with '*'", getLocation(blockDecl));
          }
          allDecl = blockDecl;
        }
        else if (blockDecl.flag.getText().equals("+")) {
          if (unnamedDecl != null) {
            throw new ExecutionException("only a single parameter can be marked with '+'", getLocation(blockDecl));
          }
          unnamedDecl = blockDecl;
        }
        else {
          throw new ExecutionException("unknown block declaration flag", getLocation(blockDecl));
        }
        continue;
      }
      
      //Find the block
      
      ParserRuleContext paramBlock = findAndRemoveBlock(namedBlocks, name(blockDecl));
      
      //Bind the block
      
      BoundParamOutputBlock boundBlock = bindBlock(paramBlock);

      blocks.put(name(blockDecl), boundBlock);
      
    }
    
    //
    // Bind unnamed block (if requested)
    //
    
    if (unnamedDecl != null) {
      
      UnnamedOutputBlockContext unnamedBlock = inv.unnamedBlock;
      
      BoundParamOutputBlock boundUnnamedBlock = bindBlock(unnamedBlock);
      
      blocks.put(unnamedDecl.id.getText(), boundUnnamedBlock);
      
    }
    
    //
    // Bind rest of blocks (if requested)
    //
    
    if (allDecl != null) {
      
      Map<String, Block> otherBlocks = new HashMap<>();
      
      // Add unnamed block if it wasn't bound explicitly
      if (inv.unnamedBlock != null && unnamedDecl == null) {
        
        UnnamedOutputBlockContext unnamedBlock = inv.unnamedBlock;
        
        BoundParamOutputBlock boundUnnamedBlock = new BoundParamOutputBlock(unnamedBlock, mode(unnamedBlock), currentScope);
        
        otherBlocks.put("", boundUnnamedBlock);
      }
      
      // Add all other unbound blocks
      for (NamedOutputBlockContext namedBlock : namedBlocks) {
        
        String blockName = nullToEmpty(name(namedBlock));
        
        BoundParamOutputBlock boundNamedBlock = new BoundParamOutputBlock(namedBlock, mode(namedBlock), currentScope);
        
        otherBlocks.put(blockName, boundNamedBlock);
        
      }

      blocks.put(allDecl.id.getText(), otherBlocks);
      
    }

    return blocks;
  }
1006522
public synchronized void lockExclusive()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "lockExclusive", this);

        boolean interrupted = false;

        // If another thread is attempting to lock exclusive,
        // wait for it to finish first.
        while (!tryLockExclusive())
        {
            try
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Waiting to get exclusive lock");
                wait(1000);
            }
            catch (InterruptedException e)
            {
                // No FFDC code needed
                interrupted = true;
            }
        }

            // Wait for existing locks to be released
        while (iLockCount > 0)
        {
            try
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Waiting for lock count to reach 0 " + iLockCount);
                wait(1000);
            }
            catch (InterruptedException e)
            {
                // No FFDC code needed
                interrupted = true;
            }
        }

        if (interrupted)
        {
            Thread.currentThread().interrupt();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "lockExclusive");
    }
1052896
function (blockname) {
            this._stack.push(this._curblock);
            this._curblock = this._blocks[blockname];
            if (this.indentUnit && this._curblock) {
                this._updateIndent();
            }
        }
678015
def execute(receiver, method, args, block)
      @mutex.synchronize do
        raise "already calling" if @call
        @call = Call::Sync.new(self, method, args, block)
      end

      receiver << @call
    end
705631
private static Block convertBlock(TBlock tblk) {
    return new Block(tblk.getBlockId(), 
                     tblk.getNumBytes(),
                     tblk.getGenerationStamp());
  }
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);
	}
778887
def locked_execute(self, sql, parameters = None, cursorClass = DictCursor, quiet = False):
		'''''' 
		return self.execute(sql, parameters, cursorClass, quiet = quiet, locked = True)