Blocks the calling thread until enough turns have elapsed

@param cyclesToBlock number of ticks to block
974073
private void blockMe(int cyclesToBlock) {
	long unblock = cycles + cyclesToBlock;

	BlockedEntry newEntry = new BlockedEntry(unblock);
	blockedCollection.add(newEntry);

	while (unblock > cycles) {
	    try {
		newEntry.getSync().acquire(); // blocks
	    } catch (InterruptedException exc) {
		log.error("[temporaryBlock] Spurious wakeup", exc);
	    }
	}

    }
845225
public void tick() throws InterruptedException {
    try (LockResource r = new LockResource(mLock)) {
      HeartbeatScheduler.addTimer(this);
      // Wait in a loop to handle spurious wakeups
      while (!mScheduled) {
        mTickCondition.await();
      }

      mScheduled = false;
    }
  }
1093095
public void setWorkerBlocks(java.util.Collection<WorkerBlock> workerBlocks) {
        if (workerBlocks == null) {
            this.workerBlocks = null;
            return;
        }

        this.workerBlocks = new java.util.ArrayList<WorkerBlock>(workerBlocks);
    }
255896
private void performStepAnimation(final Node nextSlide) {

        // setSlideLocked(true);
        this.slideStepAnimation = ParallelTransitionBuilder.create()

                                                           .onFinished(new EventHandler<ActionEvent>() {

                                                               @Override
                                                               public void handle(final ActionEvent event) {
                                                                   AbstractTemplateView.this.currentSubSlide = nextSlide;
                                                                   // AbstractTemplateView.this.setSlideLocked(false);
                                                               }
                                                           })

                                                           .children(
                                                                     SequentialTransitionBuilder.create()
                                                                                                .node(this.currentSubSlide)
                                                                                                .children(
                                                                                                          TranslateTransitionBuilder.create()
                                                                                                                                    .duration(Duration.millis(400))
                                                                                                                                    .fromY(0)
                                                                                                                                    .toY(-700)
                                                                                                                                    // .fromZ(-10)
                                                                                                                                    .build(),
                                                                                                          TimelineBuilder.create()
                                                                                                                         .keyFrames(
                                                                                                                                    new KeyFrame(
                                                                                                                                                 Duration.millis(0),
                                                                                                                                                 new KeyValue(
                                                                                                                                                              this.currentSubSlide.visibleProperty(),
                                                                                                                                                              true)),
                                                                                                                                    new KeyFrame(
                                                                                                                                                 Duration.millis(1),
                                                                                                                                                 new KeyValue(
                                                                                                                                                              this.currentSubSlide.visibleProperty(),
                                                                                                                                                              false)))
                                                                                                                         .build())

                                                                                                .build(),
                                                                     SequentialTransitionBuilder.create()
                                                                                                .node(nextSlide)
                                                                                                .children(
                                                                                                          TimelineBuilder.create()
                                                                                                                         .keyFrames(
                                                                                                                                    new KeyFrame(
                                                                                                                                                 Duration.millis(0),
                                                                                                                                                 new KeyValue(
                                                                                                                                                              nextSlide.visibleProperty(),
                                                                                                                                                              false)),
                                                                                                                                    new KeyFrame(
                                                                                                                                                 Duration.millis(1),
                                                                                                                                                 new KeyValue(
                                                                                                                                                              nextSlide.visibleProperty(),
                                                                                                                                                              true)))
                                                                                                                         .build(),
                                                                                                          TranslateTransitionBuilder.create()
                                                                                                                                    .duration(Duration.millis(400))
                                                                                                                                    .fromY(700)
                                                                                                                                    .toY(0)
                                                                                                                                    // .fromZ(-10)
                                                                                                                                    .build())
                                                                                                .build())
                                                           .build();
        this.slideStepAnimation.play();

    }
890112
@Override
    public void changeBank(int newBank) {
	int penalty = Timing.getInstance().BANK_CHANGE;
	log.trace("[changeBank] Waiting {} cycles to change to bank {}", penalty, newBank);
	turnsControl.waitTurns(penalty, "Change bank");
	robot.changeBank(newBank);

    }
767171
public static void loopBlocks(int start , int endExclusive , IntRangeConsumer consumer ) {
		final ForkJoinPool pool = BoofConcurrency.pool;
		int numThreads = pool.getParallelism();

		int range = endExclusive-start;
		if( range == 0 ) // nothing to do here!
			return;
		if( range < 0 )
			throw new IllegalArgumentException("end must be more than start. "+start+" -> "+endExclusive);

		// Did some experimentation here. Gave it more threads than were needed or exactly what was needed
		// exactly seemed to do better in the test cases
		int blockSize = Math.max(1,range/numThreads);

		try {
			pool.submit(new IntRangeTask(start,endExclusive,blockSize,consumer)).get();
		} catch (InterruptedException | ExecutionException e) {
			throw new RuntimeException(e);
		}
	}
262128
public synchronized void pause() {
        // use compareAndSet to make sure it stops only once and when running
        if (running.compareAndSet(true, false)) {
            logger.debug("Stopping the HystrixMetricsPoller");
            scheduledTask.cancel(true);
        } else {
            logger.debug("Attempted to pause a stopped poller");
        }
    }
1231632
private void rollBlocksScheduled(long now) {
    if ((now - lastBlocksScheduledRollTime) > 
        BLOCKS_SCHEDULED_ROLL_INTERVAL) {
      prevApproxBlocksScheduled = currApproxBlocksScheduled;
      currApproxBlocksScheduled = 0;
      lastBlocksScheduledRollTime = now;
    }
  }
964719
public static void schedule(String threadName) {
    try (LockResource r = new LockResource(sLock)) {
      ScheduledTimer timer = sTimers.get(threadName);
      if (timer == null) {
        throw new RuntimeException("Timer for thread " + threadName + " not found.");
      }
      timer.schedule();
    }
  }
701484
protected void setRelatedLock(CmsLock relatedLock) {

        if (this == NULL_LOCK) {
            throw new RuntimeException("null lock");
        }
        if ((relatedLock == null) || relatedLock.isUnlocked()) {
            m_relatedLock = null;
        } else {
            m_relatedLock = relatedLock;
            m_relatedLock.m_relatedLock = this;
        }
    }
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");
    }
373712
protected final void synchronizedRedraw() {
    Runnable pr = new Runnable() {
      @Override
      public void run() {
        if(VisualizationPlot.this.pendingRedraw == this) {
          VisualizationPlot.this.pendingRedraw = null;
          VisualizationPlot.this.redraw();
        }
      }
    };
    pendingRedraw = pr;
    scheduleUpdate(pr);
  }
1238387
protected void scheduleRunAsync(Runnable runnable, long delay, TimeUnit unit) {
		componentMainThreadExecutor.schedule(runnable, delay, unit);
	}
446430
private void blockingRefresh() {
        try {
            if (blockingRefreshLock
                    .tryLock(BLOCKING_REFRESH_MAX_WAIT_IN_SECONDS, TimeUnit.SECONDS)) {
                try {
                    // Return if successful refresh occurred while waiting for the lock
                    if (!shouldDoBlockingRefresh()) {
                        return;
                    } else {
                        // Otherwise do a synchronous refresh if the last lock holder was unable to
                        // refresh the value
                        refreshValue();
                        return;
                    }
                } finally {
                    blockingRefreshLock.unlock();
                }
            }
        } catch (InterruptedException ex) {
            handleInterruptedException("Interrupted waiting to refresh the value.", ex);
        }
        // Couldn't acquire the lock. Just try a synchronous refresh
        refreshValue();
    }
797676
private boolean beginBlocking() {
    begin();
    synchronized (blockingThreads) {
      if (isOpen()) {
        blockingThreads.add(Thread.currentThread());
        return true;
      }

      return false;
    }
  }
1075519
private void waitForMoveCompletion() {
    boolean shouldWait;
    int waitedIterations = 0;
    do {
      shouldWait = false;
      for (BalancerDatanode target : plan.targets) {
        if (!target.isPendingQEmpty()) {
          shouldWait = true;
        }
      }
      if (shouldWait) {
        try {
          if (waitedIterations > MAX_WAIT_ITERATIONS) {
            for (BalancerDatanode target : plan.targets) {
              target.killPending();
            }
            continue;
          }
          waitedIterations++;
          Thread.sleep(blockMoveWaitTime);
        } catch (InterruptedException ignored) {
        }
      }
    } while (shouldWait);
  }
342363
public int waitForMessages(int num_spins, final BiConsumer<Integer,Integer> wait_strategy) throws InterruptedException {
        // try spinning first (experimental)
        for(int i=0; i < num_spins && count == 0; i++) {
            if(wait_strategy != null)
                wait_strategy.accept(i, num_spins);
            else
                Thread.yield();
        }
        if(count == 0)
            _waitForMessages();
        return count; // whatever is the last count; could have been updated since lock release
    }