You are currently viewing a snapshot of taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to, please file a bug.

All Packages  This Package  Class Hierarchy  Class Search  Index

Class calypso.util.RWLock


A "read-write" lock. This lock allows for an arbitrary number of simultaneous readers. The lock can be upgraded to a write lock in two ways. First, the lock can be upgraded without guaranteeing invariance across the transition (in other words, the read lock may need to be released before the write lock can be acquired). The other form of upgrade guarantees invariance; however, the upgrade can only be performed by initially locking the lock using the invariant read lock enter method. Upgrading the lock in either case involves waiting until there are no more readers. This implementation gives priority to upgrades and invariant locks which may lead to reader starvation.

Each thread using the lock may re-enter the lock as many times as needed. However, attempting to re-enter the lock with the invariant read lock will fail unless the lock was originally entered that way by the invoking thread.

Only one thread may enter the invariant read lock at a time; other threads attempting this will block until the owning thread exits the lock completely.

Note that the implementation assumes that the user of instances of this class properly pairs the enters/exits.

public final class  RWLock
     extends java.lang.Object
          // Fields 13
     private LockState fFreeList;
     private int fFreeListLength;
     private int fInvariantLockCount;
     private Thread fInvariantLockOwner;
     private int fNumReaders;
     private LockState fStateList;
     private int fWriteLockCount;
     private Thread fWriteLockOwner;
     static final int kInvariantRead;
     private static final int kMaxFreeListLength;
     static final int kRead;
     static String[] kStateToString;
     static final int kWrite;

          // Constructors 1
     public RWLock();

          // Methods 11
     private void appendLockState(Thread, int);
     public synchronized void enterInvariantReadLock() throws InterruptedException;
     public synchronized void enterReadLock() throws InterruptedException;
     public synchronized void enterWriteLock() throws InterruptedException;
     public synchronized void exitInvariantReadLock();
     public synchronized void exitReadLock();
     public synchronized void exitWriteLock();
     private void freeLockState(LockState);
     private boolean isLocked(Thread, int);
     private LockState newLockState();
     private void removeLockState(Thread, int);

          // Inner Classes 1
     static class LockState



   private int fNumReaders


   private Thread fWriteLockOwner


   private int fWriteLockCount


   private Thread fInvariantLockOwner


   private int fInvariantLockCount


   static final int kRead


   static final int kWrite


   static final int kInvariantRead


   static String[] kStateToString


   private LockState fStateList

Circular list of LockState objects. When the lock changes state (via one of the three enter methods) we append a LockState object to the end of the stack. When a thread exits the lock we find it's last LockState object and remove it from the list.


   private LockState fFreeList

A list of free LockState objects used to reduce the execution time for allocation.


   private int fFreeListLength


   private static final int kMaxFreeListLength



   public RWLock() 



   public synchronized void enterReadLock()  throws InterruptedException


   public synchronized void exitReadLock() 


   public synchronized void enterInvariantReadLock()  throws InterruptedException

Enter the invariant read lock. Only one thread at a time can hold the invariant read lock. This lock guarantees to upgrade to a write lock without needing to release the read lock.


   public synchronized void exitInvariantReadLock() 


   public synchronized void enterWriteLock()  throws InterruptedException


   public synchronized void exitWriteLock() 


   private boolean isLocked(Thread aThread, 
                            int aHow) 

See if aThread has the given type of lock


   private void appendLockState(Thread aThread, 
                                int aState) 


   private void removeLockState(Thread aThread, 
                                int aState) 

Walk up the thread state list and look for aThread. Verify that the LockState is in the right state and if it is then we remove that LockState from the list.


   private LockState newLockState() 


   private void freeLockState(LockState aState) 

All Packages  This Package  Class Hierarchy  Class Search  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.4