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.4 by jsr166, Fri Oct 12 16:48:15 2012 UTC vs.
Revision 1.7 by dl, Fri Oct 12 23:11:14 2012 UTC

# Line 26 | Line 26 | import java.util.concurrent.TimeUnit;
26   *   in method {@link #unlockWrite} to release the lock. Untimed and
27   *   timed versions of {@code tryWriteLock} are also provided. When
28   *   the lock is held in write mode, no read locks may be obtained,
29 < *   and all observer validations will fail.  </li>
29 > *   and all optimistic read validations will fail.  </li>
30   *
31   *  <li><b>Reading.</b> Method {@link #readLock} possibly blocks
32   *   waiting for non-exclusive access, returning a stamp that can be
# Line 76 | Line 76 | import java.util.concurrent.TimeUnit;
76   * into initial unlocked state, so they are not useful for remote
77   * locking.
78   *
79 < * <p>The scheduling policy of StampedLock does not consistently prefer
80 < * readers over writers or vice versa.
79 > * <p>The scheduling policy of StampedLock does not consistently
80 > * prefer readers over writers or vice versa.  A zero return from any
81 > * "try" method for acquiring or converting locks does carry any
82 > * information about the state of the lock; a subsequent invocation
83 > * may succeed.
84   *
85   * <p><b>Sample Usage.</b> The following illustrates some usage idioms
86   * in a class that maintains simple two-dimensional points. The sample
# Line 87 | Line 90 | import java.util.concurrent.TimeUnit;
90   *
91   *  <pre>{@code
92   * class Point {
93 < *   private volatile double x, y;
93 > *   private double x, y;
94   *   private final StampedLock sl = new StampedLock();
95   *
96   *   void move(double deltaX, double deltaY) { // an exclusively locked method
# Line 119 | Line 122 | import java.util.concurrent.TimeUnit;
122   *   }
123   *
124   *   double distanceFromOriginV2() { // combines code paths
125 < *     for (long stamp = sl.optimisticRead(); ; stamp = sl.readLock()) {
125 > *     for (long stamp = sl.tryOptimisticRead(); ; stamp = sl.readLock()) {
126   *       double currentX, currentY;
127   *       try {
128   *         currentX = x;
# Line 237 | Line 240 | public class StampedLock implements java
240      /** Maximum number of retries before blocking on acquisition */
241      private static final int SPINS = (NCPU > 1) ? 1 << 6 : 1;
242  
243 <    /** Maximum number of retries before re-blocking on write lock */
243 >    /** Maximum number of retries before re-blocking */
244      private static final int MAX_HEAD_SPINS = (NCPU > 1) ? 1 << 12 : 1;
245  
246      /** The period for yielding when waiting for overflow spinlock */
# Line 329 | Line 332 | public class StampedLock implements java
332  
333      /**
334       * Exclusively acquires the lock if it is available within the
335 <     * given time and the current thread has not been interrupted
335 >     * given time and the current thread has not been interrupted.
336       *
337       * @return a stamp that can be used to unlock or convert mode,
338       * or zero if the lock is not available
# Line 419 | Line 422 | public class StampedLock implements java
422  
423      /**
424       * Non-exclusively acquires the lock if it is available within the
425 <     * given time and the current thread has not been interrupted
425 >     * given time and the current thread has not been interrupted.
426       *
427       * @return a stamp that can be used to unlock or convert mode,
428       * or zero if the lock is not available
# Line 1103 | Line 1106 | public class StampedLock implements java
1106      /**
1107       * If node non-null, forces cancel status and unsplices from queue
1108       * if possible, by traversing entire queue looking for cancelled
1109 <     * nodes, cleaning out all at head, but stopping upon first
1107 <     * encounter otherwise.
1109 >     * nodes.
1110       */
1111      private long cancelReader(RNode node, boolean interrupted) {
1112          Thread w;
# Line 1119 | Line 1121 | public class StampedLock implements java
1121                      }
1122                      else {
1123                          U.compareAndSwapObject(pred, RNEXT, p, q);
1124 <                        break;
1124 >                        p = pred.next;
1125                      }
1126                  }
1127                  else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines