ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/StampedLock.java
(Generate patch)

Comparing jsr166/src/jsr166e/StampedLock.java (file contents):
Revision 1.8 by dl, Sat Oct 13 11:51:12 2012 UTC vs.
Revision 1.16 by jsr166, Sun Oct 14 20:00:48 2012 UTC

# Line 11 | Line 11 | import java.util.concurrent.TimeUnit;
11  
12   /**
13   * A capability-based lock with three modes for controlling read/write
14 < * access.  The state of a StampedLock consists of a version and
15 < * mode. Lock acquisition methods return a stamp that represents and
14 > * access.  The state of a StampedLock consists of a version and mode.
15 > * Lock acquisition methods return a stamp that represents and
16   * controls access with respect to a lock state; "try" versions of
17   * these methods may instead return the special value zero to
18   * represent failure to acquire access. Lock release and conversion
# Line 55 | Line 55 | import java.util.concurrent.TimeUnit;
55   * <p>This class also supports methods that conditionally provide
56   * conversions across the three modes. For example, method {@link
57   * #tryConvertToWriteLock} attempts to "upgrade" a mode, returning
58 < * valid write stamp if (1) already in writing mode (2) in reading
58 > * a valid write stamp if (1) already in writing mode (2) in reading
59   * mode and there are no other readers or (3) in optimistic mode and
60   * the lock is available. The forms of these methods are designed to
61   * help reduce some of the code bloat that otherwise occurs in
# Line 180 | Line 180 | public class StampedLock implements java
180       * read-locked.  The read count is ignored when validating
181       * "optimistic" seqlock-reader-style stamps.  Because we must use
182       * a small finite number of bits (currently 7) for readers, a
183 <     * supplementary reader overflow word is used when then number of
183 >     * supplementary reader overflow word is used when the number of
184       * readers exceeds the count field. We do this by treating the max
185       * reader count value (RBITS) as a spinlock protecting overflow
186       * updates.
# Line 261 | Line 261 | public class StampedLock implements java
261      private static final int OVERFLOW_YIELD_RATE = 7; // must be power 2 - 1
262  
263      /** The number of bits to use for reader count before overflowing */
264 <    private static final int  LG_READERS = 7;
264 >    private static final int LG_READERS = 7;
265  
266      // Values for lock state and stamp operations
267      private static final long RUNIT = 1L;
# Line 334 | Line 334 | public class StampedLock implements java
334       * Exclusively acquires the lock if it is immediately available.
335       *
336       * @return a stamp that can be used to unlock or convert mode,
337 <     * or zero if the lock is not available.
337 >     * or zero if the lock is not available
338       */
339      public long tryWriteLock() {
340          long s, next;
# Line 539 | Line 539 | public class StampedLock implements java
539      }
540  
541      /**
542 <     * If the lock state matches the given stamp, releases
542 >     * If the lock state matches the given stamp, releases the
543       * non-exclusive lock.
544       *
545       * @param stamp a stamp returned by a read-lock operation
# Line 606 | Line 606 | public class StampedLock implements java
606      /**
607       * If the lock state matches the given stamp then performs one of
608       * the following actions. If the stamp represents holding a write
609 <     * lock, returns it. Or, if a read lock, if the write lock is
610 <     * available, releases the read and returns a write stamp. Or, if
611 <     * an optimistic read, returns a write stamp only if immediately
612 <     * available. This method returns zero in all other cases.
609 >     * lock, returns it.  Or, if a read lock, if the write lock is
610 >     * available, releases the read lock and returns a write stamp.
611 >     * Or, if an optimistic read, returns a write stamp only if
612 >     * immediately available. This method returns zero in all other
613 >     * cases.
614       *
615       * @param stamp a stamp
616       * @return a valid write stamp, or zero on failure
# Line 700 | Line 701 | public class StampedLock implements java
701              else if (m == WBIT) {
702                  if (a != m)
703                      break;
704 <                next = state = (s += WBIT) == 0L ? ORIGIN : s;
704 >                state = next = (s += WBIT) == 0L ? ORIGIN : s;
705                  readerPrefSignal();
706                  return next;
707              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines