public synchronized void unlock() { checkState(lock.isHeldByCurrentThread(), "Current thread does not hold lock"); currentOwner = null; lock.unlock(); }
private synchronized void setOwner() { checkState(lock.isHeldByCurrentThread(), "Current thread does not hold lock"); currentOwner = Thread.currentThread(); // NOTE: We do not use interrupted stack information to know that another // thread has attempted to interrupt the driver, and interrupt this new lock // owner. The interrupted stack information is for debugging purposes only. // In the case of interruption, the caller should (and does) have a separate // state to prevent further processing in the Driver. }
/** * Releases the lock on the transceiver's channel if held by the calling thread. */ public void unlockChannel() { if (channelLock.isHeldByCurrentThread()) { channelLock.unlock(); } }
private static void attemptThreadControl(long threadId, Runnable r){ //(get lock) boolean tookLock = false; if(!control.isHeldByCurrentThread()){ control.lock(); tookLock = true; } //(perform action) attemptThreadControlThreadsafe(threadId); if(threadId == currentThread){ r.run(); } else { queueTask(threadId, r); } //(release lock) assert control.isHeldByCurrentThread(); if(tookLock){ control.unlock(); } }
/** Enters this monitor when the guard is satisfied. Blocks indefinitely. */ public void enterWhenUninterruptibly(Guard guard) { if (guard.monitor != this) { throw new IllegalMonitorStateException(); } final ReentrantLock lock = this.lock; boolean signalBeforeWaiting = lock.isHeldByCurrentThread(); lock.lock(); boolean satisfied = false; try { if (!guard.isSatisfied()) { awaitUninterruptibly(guard, signalBeforeWaiting); } satisfied = true; } finally { if (!satisfied) { leave(); } } }
@Subscribe public void handleConfigurationEvent(MaterializedConfiguration conf) { try { lifecycleLock.lockInterruptibly(); stopAllComponents(); startAllComponents(conf); } catch (InterruptedException e) { logger.info("Interrupted while trying to handle configuration event"); return; } finally { // If interrupted while trying to lock, we don't own the lock, so must not attempt to unlock if (lifecycleLock.isHeldByCurrentThread()) { lifecycleLock.unlock(); } } }
producer_lock.lock(); try { if(count == 0 || count-1 == 0) { count=0; consumer_lock.unlock(); return; producer_lock.unlock(); if(consumer_lock.isHeldByCurrentThread()) consumer_lock.unlock();
public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException { checkState(!lock.isHeldByCurrentThread(), "Lock is not reentrant"); boolean acquired = lock.tryLock(timeout, unit); if (acquired) { setOwner(); } return acquired; }
/** * Release the lock that is preventing operations on this disk store during the backup process. */ public void releaseBackupLock() { ReentrantLock backupLock = getBackupLock(); if (backupLock.isHeldByCurrentThread()) { backupLock.unlock(); } }
/** Enters this monitor when the guard is satisfied. Blocks indefinitely. */ public void enterWhenUninterruptibly(Guard guard) { if (guard.monitor != this) { throw new IllegalMonitorStateException(); } final ReentrantLock lock = this.lock; boolean signalBeforeWaiting = lock.isHeldByCurrentThread(); lock.lock(); boolean satisfied = false; try { if (!guard.isSatisfied()) { awaitUninterruptibly(guard, signalBeforeWaiting); } satisfied = true; } finally { if (!satisfied) { leave(); } } }
public synchronized void unlock() { checkState(lock.isHeldByCurrentThread(), "Current thread does not hold lock"); currentOwner = null; lock.unlock(); }
public static void locked(ReentrantLock lock, Runnable task) { try { lock.lockInterruptibly(); task.run(); } catch (InterruptedException e) { throw new IllegalStateException(e); } finally { if (lock.isHeldByCurrentThread()) lock.unlock(); } }
assert !control.isHeldByCurrentThread(); assert !control.isHeldByCurrentThread(); backlog.poll().run(); assert control.tryLock(); assert ! threadsWaiting.isEmpty(); control.lock(); attemptThreadControlThreadsafe(-1); control.unlock();
public boolean tryLock() { checkState(!lock.isHeldByCurrentThread(), "Lock is not reentrant"); boolean acquired = lock.tryLock(); if (acquired) { setOwner(); } return acquired; }
protected void releaseAndCleanLock(Long id, RuntimeEngine runtime) { if (id != null) { ReentrantLock lock = engineLocks.get(id); if (lock != null) { if (!lock.hasQueuedThreads()) { logger.debug("Removing lock {} from list as non is waiting for it by {}", lock, runtime); engineLocks.remove(id); } if (lock.isHeldByCurrentThread()) { lock.unlock(); logger.debug("{} unlocked by {}", lock, runtime); } } } }
/** * Associate the transactional state with this thread. * * @param txState the transactional state. */ public void masqueradeAs(TXStateProxy txState) { assert txState != null; if (!txState.getLock().isHeldByCurrentThread()) { txState.getLock().lock(); } setTXState(txState); if (logger.isDebugEnabled()) { logger.debug("masqueradeAs tx {}", txState); } }
public synchronized void unlock() { checkState(lock.isHeldByCurrentThread(), "Current thread does not hold lock"); currentOwner = null; lock.unlock(); }
public static <E> E locked(ReentrantLock lock, Supplier<E> task) { try { lock.lockInterruptibly(); return task.get(); } catch (InterruptedException e) { throw new IllegalStateException(e); } finally { if (lock.isHeldByCurrentThread()) lock.unlock(); } }
/** * Blocks until all partitioned steps have completed. As each step completes * the PartitionAnalyzer analyzes the collector data received from each * partition (if there is any). * * @param tasks The {@link Future} that contains the reference to the executing step * @param result Set of completed {@link StepExecution}s * @throws Exception */ private void processPartitionResults( final List<Future<StepExecution>> tasks, final Set<StepExecution> result) throws Exception { while(true) { Thread.sleep(pollingInterval); try { lock.lock(); while(!partitionDataQueue.isEmpty()) { analyzer.analyzeCollectorData(partitionDataQueue.remove()); } processFinishedPartitions(tasks, result); if(tasks.size() == 0) { break; } } finally { if(lock.isHeldByCurrentThread()) { lock.unlock(); } } } }
@SuppressWarnings("unchecked") public T get(final int index) { // Must be held by same thread Preconditions.checkState(locks.get(index).isHeldByCurrentThread()); if (softReferenceList[index] != null) { return ((SoftReference<T>)(softReferenceList[index])).get(); } return null; }