/** * Queries the number of reentrant write holds on this lock by the current thread. A writer 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 write lock by the current thread, or zero if the write lock * is not held by the current thread */ public int getWriteHoldCount() { return mDelegate.getWriteHoldCount(); }
@VisibleForTesting boolean inodeWriteLockedByCurrentThread(long inodeId) { return mInodeLocks.getRawReadWriteLock(inodeId).getWriteHoldCount() > 0; }
@VisibleForTesting boolean edgeWriteLockedByCurrentThread(Edge edge) { return mEdgeLocks.getRawReadWriteLock(edge).getWriteHoldCount() > 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(); }
public int getWriteHoldCount() { return coarseLock.getWriteHoldCount(); }
public int getWriteHoldCount() { return this.dirLock.getWriteHoldCount(); }
@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 writeLock() { coarseLock.writeLock().lock(); if (coarseLock.getWriteHoldCount() == 1) { writeLockHeldTimeStampNanos = timer.monotonicNowNanos(); } }
public void writeLockInterruptibly() throws InterruptedException { coarseLock.writeLock().lockInterruptibly(); if (coarseLock.getWriteHoldCount() == 1) { writeLockHeldTimeStampNanos = timer.monotonicNowNanos(); } }
.getWriteHoldCount() == 1 && coarseLock.isWriteLockedByCurrentThread(); final long currentTimeNanos = timer.monotonicNowNanos(); final long writeLockIntervalNanos =
/** * Queries the number of reentrant write holds on this lock by the current thread. Delegates to * {@link ReentrantReadWriteLock#getWriteHoldCount()}. * * @return the number of holds on the write lock by the current thread, or zero if the write lock is not held by the * current thread * @since 2.4 * @noreference */ protected int getWriteHoldCount() { return rwLock.getWriteHoldCount(); }
/** * Queries the number of reentrant write holds on this lock by the current thread. Delegates to * {@link ReentrantReadWriteLock#getWriteHoldCount()}. * * @return the number of holds on the write lock by the current thread, or zero if the write lock is not held by the * current thread * @since 2.4 * @noreference */ protected int getWriteHoldCount() { return rwLock.getWriteHoldCount(); }
final void releaseActivationWriteeLock() { if (m_activationLock.getWriteHoldCount() > 0) { m_activationLock.writeLock().unlock(); } }
final void releaseActivationWriteeLock() { if (m_activationLock.getWriteHoldCount() > 0) { m_activationLock.writeLock().unlock(); } }
/** * Releases the write lock only and only if the write lock is held by the current thread. * @return {@literal true} if the lock has no more holders, {@literal false} otherwise. */ public boolean releaseWriteLockIfHeld() { if (m_lock.isWriteLockedByCurrentThread()) { m_lock.writeLock().unlock(); } return m_lock.getWriteHoldCount() == 0; }
/** * Releases the write lock only and only if the write lock is held by the current thread. * @return {@literal true} if the lock has no more holders, {@literal false} otherwise. */ public boolean releaseWriteLockIfHeld() { if (m_lock.isWriteLockedByCurrentThread()) { m_lock.writeLock().unlock(); } return m_lock.getWriteHoldCount() == 0; }
public void writeLock() { coarseLock.writeLock().lock(); if (coarseLock.getWriteHoldCount() == 1) { writeLockHeldTimeStampNanos = timer.monotonicNowNanos(); } }
public void dumpState(Logger logger, Level level) { if (logger.isLoggable(level)) { logger.log(level, "Current locking conditions are " + rwlock.getReadLockCount() + "/"+ rwlock.getReadHoldCount() + " shared locks" + "and " + rwlock.getWriteHoldCount() + " write lock"); } }
public void writeLockInterruptibly() throws InterruptedException { coarseLock.writeLock().lockInterruptibly(); if (coarseLock.getWriteHoldCount() == 1) { writeLockHeldTimeStampNanos = timer.monotonicNowNanos(); } }
private static void checkLock(ReentrantReadWriteLock rwx, int expectedR, int expectedW) { int r = rwx.getReadHoldCount() ; int w = rwx.getWriteHoldCount() ; Assert.assertEquals("R", expectedR, r); Assert.assertEquals("W", expectedW, w); }