83 |
|
|
84 |
|
List<Function<StampedLock, Long>> readLockers() { |
85 |
|
List<Function<StampedLock, Long>> readLockers = new ArrayList<>(); |
86 |
< |
readLockers.add((sl) -> sl.readLock()); |
87 |
< |
readLockers.add((sl) -> sl.tryReadLock()); |
88 |
< |
readLockers.add((sl) -> readLockInterruptiblyUninterrupted(sl)); |
89 |
< |
readLockers.add((sl) -> tryReadLockUninterrupted(sl, Long.MIN_VALUE, DAYS)); |
90 |
< |
readLockers.add((sl) -> tryReadLockUninterrupted(sl, 0L, DAYS)); |
91 |
< |
readLockers.add((sl) -> sl.tryConvertToReadLock(sl.tryOptimisticRead())); |
86 |
> |
readLockers.add(sl -> sl.readLock()); |
87 |
> |
readLockers.add(sl -> sl.tryReadLock()); |
88 |
> |
readLockers.add(sl -> readLockInterruptiblyUninterrupted(sl)); |
89 |
> |
readLockers.add(sl -> tryReadLockUninterrupted(sl, Long.MIN_VALUE, DAYS)); |
90 |
> |
readLockers.add(sl -> tryReadLockUninterrupted(sl, 0L, DAYS)); |
91 |
> |
readLockers.add(sl -> sl.tryConvertToReadLock(sl.tryOptimisticRead())); |
92 |
|
return readLockers; |
93 |
|
} |
94 |
|
|
104 |
|
|
105 |
|
List<Function<StampedLock, Long>> writeLockers() { |
106 |
|
List<Function<StampedLock, Long>> writeLockers = new ArrayList<>(); |
107 |
< |
writeLockers.add((sl) -> sl.writeLock()); |
108 |
< |
writeLockers.add((sl) -> sl.tryWriteLock()); |
109 |
< |
writeLockers.add((sl) -> writeLockInterruptiblyUninterrupted(sl)); |
110 |
< |
writeLockers.add((sl) -> tryWriteLockUninterrupted(sl, Long.MIN_VALUE, DAYS)); |
111 |
< |
writeLockers.add((sl) -> tryWriteLockUninterrupted(sl, 0L, DAYS)); |
112 |
< |
writeLockers.add((sl) -> sl.tryConvertToWriteLock(sl.tryOptimisticRead())); |
107 |
> |
writeLockers.add(sl -> sl.writeLock()); |
108 |
> |
writeLockers.add(sl -> sl.tryWriteLock()); |
109 |
> |
writeLockers.add(sl -> writeLockInterruptiblyUninterrupted(sl)); |
110 |
> |
writeLockers.add(sl -> tryWriteLockUninterrupted(sl, Long.MIN_VALUE, DAYS)); |
111 |
> |
writeLockers.add(sl -> tryWriteLockUninterrupted(sl, 0L, DAYS)); |
112 |
> |
writeLockers.add(sl -> sl.tryConvertToWriteLock(sl.tryOptimisticRead())); |
113 |
|
return writeLockers; |
114 |
|
} |
115 |
|
|
272 |
|
* interruptible operations throw InterruptedException when pre-interrupted |
273 |
|
*/ |
274 |
|
public void testInterruptibleOperationsThrowInterruptedExceptionWhenPreInterrupted() { |
275 |
– |
final CountDownLatch running = new CountDownLatch(1); |
275 |
|
final StampedLock lock = new StampedLock(); |
276 |
|
|
277 |
|
Action[] interruptibleLockActions = { |
336 |
|
* interruptible operations throw InterruptedException when write locked and interrupted |
337 |
|
*/ |
338 |
|
public void testInterruptibleOperationsThrowInterruptedExceptionWriteLockedInterrupted() { |
340 |
– |
final CountDownLatch running = new CountDownLatch(1); |
339 |
|
final StampedLock lock = new StampedLock(); |
340 |
|
long s = lock.writeLock(); |
341 |
|
|
358 |
|
* interruptible operations throw InterruptedException when read locked and interrupted |
359 |
|
*/ |
360 |
|
public void testInterruptibleOperationsThrowInterruptedExceptionReadLockedInterrupted() { |
363 |
– |
final CountDownLatch running = new CountDownLatch(1); |
361 |
|
final StampedLock lock = new StampedLock(); |
362 |
|
long s = lock.readLock(); |
363 |
|
|
479 |
|
* A writelock succeeds only after a reading thread unlocks |
480 |
|
*/ |
481 |
|
public void testWriteAfterReadLock() throws InterruptedException { |
482 |
< |
final CountDownLatch running = new CountDownLatch(1); |
482 |
> |
final CountDownLatch threadStarted = new CountDownLatch(1); |
483 |
|
final StampedLock lock = new StampedLock(); |
484 |
|
long rs = lock.readLock(); |
485 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
486 |
|
public void realRun() { |
487 |
< |
running.countDown(); |
487 |
> |
threadStarted.countDown(); |
488 |
|
long s = lock.writeLock(); |
489 |
|
lock.unlockWrite(s); |
490 |
|
}}); |
491 |
|
|
492 |
< |
running.await(); |
492 |
> |
threadStarted.await(); |
493 |
|
waitForThreadToEnterWaitState(t, MEDIUM_DELAY_MS); |
494 |
|
assertFalse(lock.isWriteLocked()); |
495 |
|
lock.unlockRead(rs); |
735 |
|
*/ |
736 |
|
public void testValidateOptimisticWriteLocked2() |
737 |
|
throws InterruptedException { |
738 |
< |
final CountDownLatch running = new CountDownLatch(1); |
738 |
> |
final CountDownLatch locked = new CountDownLatch(1); |
739 |
|
final StampedLock lock = new StampedLock(); |
740 |
|
final long p = assertValid(lock, lock.tryOptimisticRead()); |
741 |
|
|
742 |
|
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
743 |
|
public void realRun() throws InterruptedException { |
744 |
|
lock.writeLockInterruptibly(); |
745 |
< |
running.countDown(); |
745 |
> |
locked.countDown(); |
746 |
|
lock.writeLockInterruptibly(); |
747 |
|
}}); |
748 |
|
|
749 |
< |
running.await(); |
749 |
> |
locked.await(); |
750 |
|
assertFalse(lock.validate(p)); |
751 |
|
assertEquals(0L, lock.tryOptimisticRead()); |
752 |
|
t.interrupt(); |