/** * Attempts to release this lock. * * <p> If the number of readers is now zero then the lock * is made available for write lock attempts. */ public void unlock() { switch (lock.sync.endRead()) { case Sync.NONE: return; case Sync.READER: lock.readerLock_.signalWaiters(); return; case Sync.WRITER: lock.writerLock_.signalWaiters(); return; } }
/** * Creates an instance of {@code ReentrantLock} with the * given fairness policy. * * @param fair {@code true} if this lock should use a fair ordering policy */ public ReentrantLock(boolean fair) { sync = (fair)? (Sync)new FairSync() : new NonfairSync(); }
/** * Queries if the write lock is held by any thread. This method is * designed for use in monitoring system state, not for * synchronization control. * * @return {@code true} if any thread holds the write lock and * {@code false} otherwise */ public boolean isWriteLocked() { return sync.isWriteLocked(); }
synchronized boolean startWriteFromWaitingWriter() { boolean pass = startWrite(); if (pass) --waitingWriters_; return pass; }
/** * Queries if this write lock is held by the current thread. * Identical in effect to {@link * ReentrantReadWriteLock#isWriteLockedByCurrentThread}. * * @return {@code true} if the current thread holds this lock and * {@code false} otherwise * @since 1.6 */ public boolean isHeldByCurrentThread() { return lock.sync.isWriteLockedByCurrentThread(); }
/** * 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 sync.getWriteHoldCount(); }
/** * Queries if this lock is held by any thread. This method is * designed for use in monitoring of the system state, * not for synchronization control. * * @return {@code true} if any thread holds this lock and * {@code false} otherwise */ public boolean isLocked() { return sync.isLocked(); }
/** * Returns {@code true} if this lock has fairness set true. * * @return {@code true} if this lock has fairness set true */ public final boolean isFair() { return sync.isFair(); }
synchronized boolean startReadFromWaitingReader() { boolean pass = startRead(); if (pass) --waitingReaders_; return pass; }
/** * Queries the number of read locks held for this lock. This * method is designed for use in monitoring system state, not for * synchronization control. * @return the number of read locks held. */ public int getReadLockCount() { return sync.getReadLockCount(); }
/** * Attempts to release this lock. * * <p> If the number of readers is now zero then the lock * is made available for write lock attempts. */ public void unlock() { switch (lock.sync.endRead()) { case Sync.NONE: return; case Sync.READER: lock.readerLock_.signalWaiters(); return; case Sync.WRITER: lock.writerLock_.signalWaiters(); return; } }
/** * Creates an instance of {@code ReentrantLock} with the * given fairness policy. * * @param fair {@code true} if this lock should use a fair ordering policy */ public ReentrantLock(boolean fair) { sync = (fair)? (Sync)new FairSync() : new NonfairSync(); }
/** * Attempts to release this lock. * * <p> If the number of readers is now zero then the lock * is made available for write lock attempts. */ public void unlock() { switch (lock.sync.endRead()) { case Sync.NONE: return; case Sync.READER: lock.readerLock_.signalWaiters(); return; case Sync.WRITER: lock.writerLock_.signalWaiters(); return; } }
/** * Creates an instance of {@code ReentrantLock} with the * given fairness policy. * * @param fair {@code true} if this lock should use a fair ordering policy */ public ReentrantLock(boolean fair) { sync = (fair)? (Sync)new FairSync() : new NonfairSync(); }