synchronized int endWrite() { if (activeWriter_ != Thread.currentThread()) { throw new IllegalMonitorStateException(); } --writeHolds_; if (writeHolds_ > 0) // still being held return NONE; else { activeWriter_ = null; if (waitingReaders_ > 0 && allowReader()) return READER; else if (waitingWriters_ > 0) return WRITER; else return NONE; } }
InterruptedException ie = null; synchronized (this) { if (!lock.sync.startReadFromNewReader()) { for (; ; ) { try { ReadLock.this.wait(); if (lock.sync.startReadFromWaitingReader()) return; lock.sync.cancelledWaitingReader(); ie = ex; break;
InterruptedException ie = null; synchronized (this) { if (!lock.sync.startWriteFromNewWriter()) { for (; ; ) { try { WriteLock.this.wait(); if (lock.sync.startWriteFromWaitingWriter()) return; lock.sync.cancelledWaitingWriter(); WriteLock.this.notify(); ie = ex;
synchronized (this) { if (nanos <= 0) return lock.sync.startWrite(); else if (lock.sync.startWriteFromNewWriter()) return true; else { lock.sync.cancelledWaitingWriter(); WriteLock.this.notify(); ie = ex; break; if (lock.sync.startWriteFromWaitingWriter()) return true; else { nanos = deadline - Utils.nanoTime(); if (nanos <= 0) { lock.sync.cancelledWaitingWriter(); WriteLock.this.notify(); break;
synchronized (this) { if (nanos <= 0) return lock.sync.startWrite(); else if (lock.sync.startWriteFromNewWriter()) return true; else { lock.sync.cancelledWaitingWriter(); WriteLock.this.notify(); ie = ex; break; if (lock.sync.startWriteFromWaitingWriter()) return true; else { nanos = deadline - Utils.nanoTime(); if (nanos <= 0) { lock.sync.cancelledWaitingWriter(); WriteLock.this.notify(); break;
synchronized (this) { if (nanos <= 0) return lock.sync.startRead(); else if (lock.sync.startReadFromNewReader()) return true; else { lock.sync.cancelledWaitingReader(); ie = ex; break; if (lock.sync.startReadFromWaitingReader()) return true; else { nanos = deadline - Utils.nanoTime(); if (nanos <= 0) { lock.sync.cancelledWaitingReader(); break;
synchronized (this) { if (nanos <= 0) return lock.sync.startRead(); else if (lock.sync.startReadFromNewReader()) return true; else { lock.sync.cancelledWaitingReader(); ie = ex; break; if (lock.sync.startReadFromWaitingReader()) return true; else { nanos = deadline - Utils.nanoTime(); if (nanos <= 0) { lock.sync.cancelledWaitingReader(); break;
synchronized (this) { if (nanos <= 0) return lock.sync.startWrite(); else if (lock.sync.startWriteFromNewWriter()) return true; else { lock.sync.cancelledWaitingWriter(); WriteLock.this.notify(); ie = ex; break; if (lock.sync.startWriteFromWaitingWriter()) return true; else { nanos = deadline - Utils.nanoTime(); if (nanos <= 0) { lock.sync.cancelledWaitingWriter(); WriteLock.this.notify(); break;
synchronized (this) { if (nanos <= 0) return lock.sync.startRead(); else if (lock.sync.startReadFromNewReader()) return true; else { lock.sync.cancelledWaitingReader(); ie = ex; break; if (lock.sync.startReadFromWaitingReader()) return true; else { nanos = deadline - Utils.nanoTime(); if (nanos <= 0) { lock.sync.cancelledWaitingReader(); break;
InterruptedException ie = null; synchronized (this) { if (!lock.sync.startWriteFromNewWriter()) { for (; ; ) { try { WriteLock.this.wait(); if (lock.sync.startWriteFromWaitingWriter()) return; lock.sync.cancelledWaitingWriter(); WriteLock.this.notify(); ie = ex;
InterruptedException ie = null; synchronized (this) { if (!lock.sync.startWriteFromNewWriter()) { for (; ; ) { try { WriteLock.this.wait(); if (lock.sync.startWriteFromWaitingWriter()) return; lock.sync.cancelledWaitingWriter(); WriteLock.this.notify(); ie = ex;
InterruptedException ie = null; synchronized (this) { if (!lock.sync.startReadFromNewReader()) { for (; ; ) { try { ReadLock.this.wait(); if (lock.sync.startReadFromWaitingReader()) return; lock.sync.cancelledWaitingReader(); ie = ex; break;
InterruptedException ie = null; synchronized (this) { if (!lock.sync.startReadFromNewReader()) { for (; ; ) { try { ReadLock.this.wait(); if (lock.sync.startReadFromWaitingReader()) return; lock.sync.cancelledWaitingReader(); ie = ex; break;
/** * Attempts to release this lock. * * <p>If the current thread is the holder of this lock then * the hold count is decremented. If the hold count is now * zero then the lock is released. If the current thread is * not the holder of this lock then {@link * IllegalMonitorStateException} is thrown. * * @throws IllegalMonitorStateException if the current thread does not * hold this lock. */ public void unlock() { switch (lock.sync.endWrite()) { case Sync.NONE: return; case Sync.READER: lock.readerLock_.signalWaiters(); return; case Sync.WRITER: lock.writerLock_.signalWaiters(); return; } }
/** * Attempts to release this lock. * * <p>If the current thread is the holder of this lock then * the hold count is decremented. If the hold count is now * zero then the lock is released. If the current thread is * not the holder of this lock then {@link * IllegalMonitorStateException} is thrown. * * @throws IllegalMonitorStateException if the current thread does not * hold this lock. */ public void unlock() { switch (lock.sync.endWrite()) { case Sync.NONE: return; case Sync.READER: lock.readerLock_.signalWaiters(); return; case Sync.WRITER: lock.writerLock_.signalWaiters(); return; } }
synchronized int endWrite() { if (activeWriter_ != Thread.currentThread()) { throw new IllegalMonitorStateException(); } --writeHolds_; if (writeHolds_ > 0) // still being held return NONE; else { activeWriter_ = null; if (waitingReaders_ > 0 && allowReader()) return READER; else if (waitingWriters_ > 0) return WRITER; else return NONE; } }
/** * Attempts to release this lock. * * <p>If the current thread is the holder of this lock then * the hold count is decremented. If the hold count is now * zero then the lock is released. If the current thread is * not the holder of this lock then {@link * IllegalMonitorStateException} is thrown. * * @throws IllegalMonitorStateException if the current thread does not * hold this lock. */ public void unlock() { switch (lock.sync.endWrite()) { case Sync.NONE: return; case Sync.READER: lock.readerLock_.signalWaiters(); return; case Sync.WRITER: lock.writerLock_.signalWaiters(); return; } }
/** * Returns the thread that currently owns the write lock, or * {@code null} if not owned. When this method is called by a * thread that is not the owner, the return value reflects a * best-effort approximation of current lock status. For example, * the owner may be momentarily {@code null} even if there are * threads trying to acquire the lock but have not yet done so. * This method is designed to facilitate construction of * subclasses that provide more extensive lock monitoring * facilities. * * @return the owner, or {@code null} if not owned */ protected Thread getOwner() { return sync.getOwner(); }
synchronized int endWrite() { if (activeWriter_ != Thread.currentThread()) { throw new IllegalMonitorStateException(); } --writeHolds_; if (writeHolds_ > 0) // still being held return NONE; else { activeWriter_ = null; if (waitingReaders_ > 0 && allowReader()) return READER; else if (waitingWriters_ > 0) return WRITER; else return NONE; } }
/** * Returns the thread that currently owns the write lock, or * {@code null} if not owned. When this method is called by a * thread that is not the owner, the return value reflects a * best-effort approximation of current lock status. For example, * the owner may be momentarily {@code null} even if there are * threads trying to acquire the lock but have not yet done so. * This method is designed to facilitate construction of * subclasses that provide more extensive lock monitoring * facilities. * * @return the owner, or {@code null} if not owned */ protected Thread getOwner() { return sync.getOwner(); }