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 |
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 |
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 |
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; |
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 */ |
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 |
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 |
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; |
1121 |
|
} |
1122 |
|
else { |
1123 |
|
U.compareAndSwapObject(pred, RNEXT, p, q); |
1124 |
< |
break; |
1124 |
> |
p = pred.next; |
1125 |
|
} |
1126 |
|
} |
1127 |
|
else { |