org.codehaus.wadi.impl
Class RWLock

java.lang.Object
  extended byorg.codehaus.wadi.impl.RWLock
All Implemented Interfaces:
ReadWriteLock
Direct Known Subclasses:
RankedRWLock

public class RWLock
extends Object
implements ReadWriteLock

A read-write lock. Writers are preferred. Writers are ordered according to 'priority'. A Reader may overlap release of its read lock with its application for a write lock. A Writer may downgrade, becoming a Reader.

Version:
$Revision: 1363 $
Author:
Jules Gosnell

Nested Class Summary
protected  class RWLock.Lock
           
protected  class RWLock.ReaderLock
           
protected  class RWLock.Signaller
          Reader and Writer requests are maintained in two different wait sets, by two different objects.
protected  class RWLock.WriterLock
           
 
Field Summary
protected  RWLockListener _listener
           
protected static Log _log
           
protected  int _maxPriority
           
protected static ThreadLocal _priority
           
protected  long activeReaders_
           
protected  Thread activeWriter_
           
protected  RWLock.ReaderLock readerLock_
           
protected  long waitingReaders_
           
protected  long waitingWriters_
           
protected  RWLock.WriterLock writerLock_
           
 
Constructor Summary
RWLock(int maxPriority)
           
 
Method Summary
protected  boolean allowReader()
           
protected  void cancelledWaitingReader()
           
protected  void cancelledWaitingWriter(RWLock.Lock l)
           
 void downgrade()
           
protected  RWLock.Signaller endRead()
          Called upon termination of a read.
protected  RWLock.Signaller endWrite()
          Called upon termination of a write.
static int getPriority()
           
protected  boolean notifyReadEnded()
           
 void overlap()
           
 Sync readLock()
           
 void setListener(RWLockListener listener)
           
static void setPriority(int priority)
           
protected  boolean startRead()
           
protected  boolean startReadFromNewReader()
           
protected  boolean startReadFromWaitingReader()
           
protected  boolean startWrite()
           
protected  boolean startWriteFromNewWriter(RWLock.Lock l)
           
protected  boolean startWriteFromWaitingWriter(RWLock.Lock l)
           
 String toString()
           
 Sync writeLock()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_log

protected static final Log _log

_maxPriority

protected int _maxPriority

_priority

protected static ThreadLocal _priority

activeReaders_

protected long activeReaders_

activeWriter_

protected Thread activeWriter_

waitingReaders_

protected long waitingReaders_

waitingWriters_

protected long waitingWriters_

_listener

protected RWLockListener _listener

readerLock_

protected final RWLock.ReaderLock readerLock_

writerLock_

protected final RWLock.WriterLock writerLock_
Constructor Detail

RWLock

public RWLock(int maxPriority)
Method Detail

setPriority

public static void setPriority(int priority)

getPriority

public static int getPriority()

setListener

public void setListener(RWLockListener listener)

writeLock

public Sync writeLock()
Specified by:
writeLock in interface ReadWriteLock

readLock

public Sync readLock()
Specified by:
readLock in interface ReadWriteLock

cancelledWaitingReader

protected void cancelledWaitingReader()

cancelledWaitingWriter

protected void cancelledWaitingWriter(RWLock.Lock l)

allowReader

protected boolean allowReader()

startRead

protected boolean startRead()

startWrite

protected boolean startWrite()

startReadFromNewReader

protected boolean startReadFromNewReader()

startWriteFromNewWriter

protected boolean startWriteFromNewWriter(RWLock.Lock l)

startReadFromWaitingReader

protected boolean startReadFromWaitingReader()

startWriteFromWaitingWriter

protected boolean startWriteFromWaitingWriter(RWLock.Lock l)

notifyReadEnded

protected boolean notifyReadEnded()

endRead

protected RWLock.Signaller endRead()
Called upon termination of a read. Returns the object to signal to wake up a waiter, or null if no such


endWrite

protected RWLock.Signaller endWrite()
Called upon termination of a write. Returns the object to signal to wake up a waiter, or null if no such


overlap

public void overlap()
             throws InterruptedException
Throws:
InterruptedException

downgrade

public void downgrade()
               throws IllegalStateException
Throws:
IllegalStateException

toString

public String toString()


Copyright © 2004-2006 Core Developers Network Ltd.. All Rights Reserved.