ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ReentrantReadWriteLock.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ReentrantReadWriteLock.java (file contents):
Revision 1.3 by dl, Sat Jun 7 18:20:21 2003 UTC vs.
Revision 1.4 by dl, Tue Jun 24 14:34:48 2003 UTC

# Line 103 | Line 103 | package java.util.concurrent;
103   * @spec JSR-166
104   * @revised $Date$
105   * @editor $Author$
106 + * @author Doug Lea
107   *
108   */
109   public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializable  {
# Line 113 | Line 114 | public class ReentrantReadWriteLock impl
114      */
115  
116      /** Inner class providing readlock */
117 <    private transient final Lock readerLock = new ReaderLock();
117 >    private final Lock readerLock = new ReaderLock();
118      /** Inner class providing writelock */
119 <    private transient final Lock writerLock = new WriterLock();
119 >    private final Lock writerLock = new WriterLock();
120  
121      public Lock writeLock() { return writerLock; }
122 +
123      public Lock readLock() { return readerLock; }
124  
125      /**
# Line 128 | Line 130 | public class ReentrantReadWriteLock impl
130       * subclass defined below that surrounds WriteLock condition waits
131       * with bookeeping to save and restore writer state.
132       **/
133 <    private transient final RRWLock entryLock = new RRWLock();
133 >    private final RRWLock entryLock = new RRWLock();
134  
135      /**
136       * Number of threads that have entered read lock.  This is never
# Line 160 | Line 162 | public class ReentrantReadWriteLock impl
162       * Lock used by exiting readers and entering writers
163       */
164  
165 <    private transient final ReentrantLock writeCheckLock = new ReentrantLock();
165 >    private final ReentrantLock writeCheckLock = new ReentrantLock();
166  
167      /**
168       * Condition waited on by blocked entering writers.
169       */
170 <    private transient final Condition writeEnabled = writeCheckLock.newCondition();
170 >    private final Condition writeEnabled = writeCheckLock.newCondition();
171  
172      /**
173       * Reader exit protocol, called from unlock. if this is the last
# Line 193 | Line 195 | public class ReentrantReadWriteLock impl
195      /**
196       * Writer enter protocol, called after acquiring entry lock.
197       * Wait until all readers have exited.
198 +     * @throws InterruptedException if interrupted while waiting
199      */
200      private void writerEnter() throws InterruptedException {
201          writeCheckLock.lock();
# Line 206 | Line 209 | public class ReentrantReadWriteLock impl
209  
210      }
211  
212 +    /**
213 +     * Trylock version of Writer enter protocol
214 +     * @return true if successful
215 +     */
216      private boolean tryWriterEnter() {
217          writeCheckLock.lock();
218          boolean ok = (exreaders == readers);
# Line 213 | Line 220 | public class ReentrantReadWriteLock impl
220          return ok;
221      }
222  
223 +    /**
224 +     * Timed version of writer enter protocol, called after acquiring
225 +     * entry lock.  Wait until all readers have exited.
226 +     * @param nanos the wait time
227 +     * @return true if successful
228 +     * @throws InterruptedException if interrupted while waiting
229 +     */
230      private boolean tryWriterEnter(long nanos) throws InterruptedException {
231          writeCheckLock.lock();
232          try {
# Line 229 | Line 243 | public class ReentrantReadWriteLock impl
243      }
244  
245  
246 +    /**
247 +     * The Reader lock
248 +     */
249      private class ReaderLock implements Lock {
250  
251          public void lock() {
# Line 275 | Line 292 | public class ReentrantReadWriteLock impl
292          }
293      }
294  
295 +    /**
296 +     * The writer lock
297 +     */
298      private class WriterLock implements Lock  {
299          public void lock() {
300              entryLock.lock();
# Line 355 | Line 375 | public class ReentrantReadWriteLock impl
375          
376          public void unlock() {
377              // must perform owner check before clearing "writing"
378 <            entryLock.checkOwner(Thread.currentThread());
378 >            if (!entryLock.isHeldByCurrentThread())
379 >                throw new IllegalMonitorStateException();
380              writing = false;
381              entryLock.unlock();
382          }
# Line 394 | Line 415 | public class ReentrantReadWriteLock impl
415              }
416          }
417      }
418 +
419   }
420  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines