/** * Called upon termination of a write. * Returns the object to signal to wake up a waiter, or null if no such */ protected synchronized Signaller endWrite() { activeWriter_ = null; if (waitingReaders_ > 0 && allowReader()) return readerLock_; else if (waitingWriters_ > 0) return writerLock_; else return null; }
protected synchronized boolean startReadFromWaitingReader() { boolean pass = startRead(); if (pass) --waitingReaders_; return pass; }
protected synchronized boolean startWriteFromNewWriter() { boolean pass = startWrite(); if (!pass) ++waitingWriters_; return pass; }
synchronized(this) { if (msecs <= 0) return startRead(); else if (startReadFromNewReader()) return true; else { try { ReaderLock.this.wait(waitTime); } catch(InterruptedException ex){ cancelledWaitingReader(); ie = ex; break; if (startReadFromWaitingReader()) return true; else { waitTime = msecs - (System.currentTimeMillis() - start); if (waitTime <= 0) { cancelledWaitingReader(); break;
synchronized(this) { if (msecs <= 0) return startWrite(); else if (startWriteFromNewWriter()) return true; else { try { WriterLock.this.wait(waitTime); } catch(InterruptedException ex){ cancelledWaitingWriter(); WriterLock.this.notify(); ie = ex; break; if (startWriteFromWaitingWriter()) return true; else { waitTime = msecs - (System.currentTimeMillis() - start); if (waitTime <= 0) { cancelledWaitingWriter(); WriterLock.this.notify(); break;
public void lock() { //if (Thread.interrupted()) throw new RuntimeException("Lock interrupted", new InterruptedException()); InterruptedException ie = null; synchronized(this) { if (!startReadFromNewReader()) { for (;;) { try { ReaderLock.this.wait(); if (startReadFromWaitingReader()) return; } catch(InterruptedException ex){ cancelledWaitingReader(); ie = ex; break; } } } } if (ie != null) { // fall through outside synch on interrupt. // This notification is not really needed here, // but may be in plausible subclasses writerLock_.signalWaiters(); throw new RuntimeException("Lock interrupted, " + ie); } }
public void lock() { //if (Thread.interrupted()) throw new RuntimeException("Lock interrupted", new InterruptedException()); InterruptedException ie = null; synchronized(this) { if (!startWriteFromNewWriter()) { for (;;) { try { WriterLock.this.wait(); if (startWriteFromWaitingWriter()) return; } catch(InterruptedException ex){ cancelledWaitingWriter(); WriterLock.this.notify(); ie = ex; break; } } } } if (ie != null) { // Fall through outside synch on interrupt. // On exception, we may need to signal readers. // It is not worth checking here whether it is strictly necessary. readerLock_.signalWaiters(); throw new RuntimeException("Lock interrupted, " + ie); } }
public void unlock() { Signaller s = endRead(); if (s != null) s.signalWaiters(); }
public void unlock(){ Signaller s = endWrite(); if (s != null) s.signalWaiters(); }
synchronized(this) { if (msecs <= 0) return startRead(); else if (startReadFromNewReader()) return true; else { try { ReaderLock.this.wait(waitTime); } catch(InterruptedException ex){ cancelledWaitingReader(); ie = ex; break; if (startReadFromWaitingReader()) return true; else { waitTime = msecs - (System.currentTimeMillis() - start); if (waitTime <= 0) { cancelledWaitingReader(); break;
synchronized(this) { if (msecs <= 0) return startWrite(); else if (startWriteFromNewWriter()) return true; else { try { WriterLock.this.wait(waitTime); } catch(InterruptedException ex){ cancelledWaitingWriter(); WriterLock.this.notify(); ie = ex; break; if (startWriteFromWaitingWriter()) return true; else { waitTime = msecs - (System.currentTimeMillis() - start); if (waitTime <= 0) { cancelledWaitingWriter(); WriterLock.this.notify(); break;
public void lock() { //if (Thread.interrupted()) throw new RuntimeException("Lock interrupted", new InterruptedException()); InterruptedException ie = null; synchronized(this) { if (!startReadFromNewReader()) { for (;;) { try { ReaderLock.this.wait(); if (startReadFromWaitingReader()) return; } catch(InterruptedException ex){ cancelledWaitingReader(); ie = ex; break; } } } } if (ie != null) { // fall through outside synch on interrupt. // This notification is not really needed here, // but may be in plausible subclasses writerLock_.signalWaiters(); throw new RuntimeException("Lock interrupted, " + ie); } }
public void lock() { //if (Thread.interrupted()) throw new RuntimeException("Lock interrupted", new InterruptedException()); InterruptedException ie = null; synchronized(this) { if (!startWriteFromNewWriter()) { for (;;) { try { WriterLock.this.wait(); if (startWriteFromWaitingWriter()) return; } catch(InterruptedException ex){ cancelledWaitingWriter(); WriterLock.this.notify(); ie = ex; break; } } } } if (ie != null) { // Fall through outside synch on interrupt. // On exception, we may need to signal readers. // It is not worth checking here whether it is strictly necessary. readerLock_.signalWaiters(); throw new RuntimeException("Lock interrupted, " + ie); } }
public void unlock() { Signaller s = endRead(); if (s != null) s.signalWaiters(); }
public void unlock(){ Signaller s = endWrite(); if (s != null) s.signalWaiters(); }
protected synchronized boolean startWriteFromWaitingWriter() { boolean pass = startWrite(); if (pass) --waitingWriters_; return pass; }
protected synchronized boolean startReadFromNewReader() { boolean pass = startRead(); if (!pass) ++waitingReaders_; return pass; }
protected synchronized boolean startRead() { boolean allowRead = allowReader(); if (allowRead) ++activeReaders_; return allowRead; }
protected synchronized boolean startWriteFromNewWriter() { boolean pass = startWrite(); if (!pass) ++waitingWriters_; return pass; }
protected synchronized boolean startReadFromWaitingReader() { boolean pass = startRead(); if (pass) --waitingReaders_; return pass; }