/** * Queries the number of reentrant read holds on this lock by the current thread. A reader thread * has a hold on a lock for each lock action that is not matched by an unlock action. * * @return the number of holds on the read lock by the current thread, or zero if the read lock is * not held by the current thread */ public int getReadHoldCount() { return mDelegate.getReadHoldCount(); }
/** * The snapshot operation processing as following: <br> * 1. Create a Snapshot Handler, and do some initialization; <br> * 2. Put the handler into snapshotHandlers <br> * So when we consider if any snapshot is taking, we should consider both the takingSnapshotLock * and snapshotHandlers; * @return true to indicate that there're some running snapshots. */ public synchronized boolean isTakingAnySnapshot() { return this.takingSnapshotLock.getReadHoldCount() > 0 || this.snapshotHandlers.size() > 0; }
public synchronized List<Proposal> getCommittedLog() { ReadLock rl = logLock.readLock(); // only make a copy if this thread isn't already holding a lock if(logLock.getReadHoldCount() <=0) { try { rl.lock(); return new LinkedList<Proposal>(this.committedLog); } finally { rl.unlock(); } } return this.committedLog; }
@VisibleForTesting boolean inodeReadLockedByCurrentThread(long inodeId) { return mInodeLocks.getRawReadWriteLock(inodeId).getReadHoldCount() > 0; }
@VisibleForTesting boolean edgeReadLockedByCurrentThread(Edge edge) { return mEdgeLocks.getRawReadWriteLock(edge).getReadHoldCount() > 0; }
public synchronized LinkedList<Proposal> getCommittedLog() { ReadLock rl = logLock.readLock(); // only make a copy if this thread isn't already holding a lock if(logLock.getReadHoldCount() <=0) { try { rl.lock(); return new LinkedList<Proposal>(this.committedLog); } finally { rl.unlock(); } } return this.committedLog; }
/** * Queries the number of reentrant read holds on this lock by the * current thread. A reader thread has a hold on a lock for * each lock action that is not matched by an unlock action. * * @return the number of holds on the read lock by the current thread, * or zero if the read lock is not held by the current thread */ public int getReadHoldCount() { return locks[curIdx()].getReadHoldCount(); }
/** {@inheritDoc} */ @Override public boolean holdsLock() { return lock.isWriteLockedByCurrentThread() || lock.getReadHoldCount() > 0; }
/** * Acquires an exclusive lock on the database. This is semantically similar to acquiring a write lock in a {@link * java.util.concurrent.locks.ReadWriteLock ReadWriteLock} but it is not generally necessary for protecting actual * database writes--it's only necessary when exclusive use of the database connection is required (e.g. while the * database is attached to another database). * <p> * Only one thread can hold an exclusive lock at a time. Calling this while on a thread that already holds a non- * exclusive lock is an error! We will throw an exception if this method is called while the * calling thread is in a transaction or otherwise holds the non-exclusive lock. Otherwise, this method will block * until all non-exclusive locks acquired with {@link #acquireNonExclusiveLock()} have been released, but will * prevent any new non-exclusive locks from being acquired while it blocks. */ protected void acquireExclusiveLock() { if (readWriteLock.getReadHoldCount() > 0 && readWriteLock.getWriteHoldCount() == 0) { throw new IllegalStateException("Can't acquire an exclusive lock when the calling thread is in a " + "transaction or otherwise holds a non-exclusive lock and not the exclusive lock"); } readWriteLock.writeLock().lock(); }
/** * Starts timing for the instrumented read lock. * It records the time to ThreadLocal. */ @Override protected void startLockTiming() { if (readWriteLock.getReadHoldCount() == 1) { readLockHeldTimeStamp.set(getTimer().monotonicNow()); } } }
@Override public void unlock() { boolean needReport = readWriteLock.getReadHoldCount() == 1; long localLockReleaseTime = getTimer().monotonicNow(); long localLockAcquireTime = readLockHeldTimeStamp.get(); getLock().unlock(); if (needReport) { readLockHeldTimeStamp.remove(); check(localLockAcquireTime, localLockReleaseTime); } }
Channel channelToClose = null; Map<Integer, Callback<List<ByteBuffer>>> requestsToCancel = null; boolean stateReadLockHeld = stateLock.getReadHoldCount() != 0;
int holdCount = inputRowSetsLock.getReadHoldCount(); for ( int i = 0; i < holdCount; i++ ) { inputRowSetsLock.readLock().unlock();
if (checkpointLock.getReadHoldCount() > 1 || safeToUpdatePageMemories()) break; else {
/** * Tests {@link LockResource} with {@link ReentrantReadWriteLock}. */ @Test public void reentrantReadWriteLock() { ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); try (LockResource r1 = new LockResource(lock.readLock())) { try (LockResource r2 = new LockResource(lock.readLock())) { assertEquals(lock.getReadHoldCount(), 2); assertTrue(lock.readLock().tryLock()); lock.readLock().unlock(); } } assertEquals(lock.getReadHoldCount(), 0); try (LockResource r1 = new LockResource(lock.writeLock())) { try (LockResource r2 = new LockResource(lock.readLock())) { assertTrue(lock.isWriteLockedByCurrentThread()); assertEquals(lock.getReadHoldCount(), 1); } } assertFalse(lock.isWriteLockedByCurrentThread()); assertEquals(lock.getReadHoldCount(), 0); try (LockResource r = new LockResource(lock.readLock())) { assertFalse(lock.writeLock().tryLock()); } } }
public int getReadHoldCount() { return this.dirLock.getReadHoldCount(); }
@Test public void testBasics() { AutoReadWriteLock lock = new AutoReadWriteLock(new ReentrantReadWriteLock()); try (AutoLock al = lock.lockForRead()) { Assert.assertTrue(lock.innerLock().getReadHoldCount() == 1); } Assert.assertTrue(lock.innerLock().getReadHoldCount() == 0); try (AutoLock al = lock.lockForWrite()) { Assert.assertTrue(lock.innerLock().getWriteHoldCount() == 1); } Assert.assertTrue(lock.innerLock().getWriteHoldCount() == 0); } }
public void readLock() { coarseLock.readLock().lock(); if (coarseLock.getReadHoldCount() == 1) { readLockHeldTimeStampNanos.set(timer.monotonicNowNanos()); } }
boolean hasReadLock() { return this.dirLock.getReadHoldCount() > 0 || hasWriteLock(); }
public void readLockInterruptibly() throws InterruptedException { coarseLock.readLock().lockInterruptibly(); if (coarseLock.getReadHoldCount() == 1) { readLockHeldTimeStampNanos.set(timer.monotonicNowNanos()); } }