84 |
|
rl.writeLock().lock(); |
85 |
|
assertTrue(rl.isWriteLocked()); |
86 |
|
assertTrue(rl.isWriteLockedByCurrentThread()); |
87 |
+ |
assertTrue(rl.writeLock().isHeldByCurrentThread()); |
88 |
|
assertEquals(0, rl.getReadLockCount()); |
89 |
|
rl.writeLock().unlock(); |
90 |
|
assertFalse(rl.isWriteLocked()); |
91 |
|
assertFalse(rl.isWriteLockedByCurrentThread()); |
92 |
+ |
assertFalse(rl.writeLock().isHeldByCurrentThread()); |
93 |
|
assertEquals(0, rl.getReadLockCount()); |
94 |
|
rl.readLock().lock(); |
95 |
|
assertFalse(rl.isWriteLocked()); |
110 |
|
rl.writeLock().lock(); |
111 |
|
assertTrue(rl.isWriteLocked()); |
112 |
|
assertTrue(rl.isWriteLockedByCurrentThread()); |
113 |
+ |
assertTrue(rl.writeLock().isHeldByCurrentThread()); |
114 |
|
assertEquals(0, rl.getReadLockCount()); |
115 |
|
rl.writeLock().unlock(); |
116 |
|
assertFalse(rl.isWriteLocked()); |
117 |
|
assertFalse(rl.isWriteLockedByCurrentThread()); |
118 |
+ |
assertFalse(rl.writeLock().isHeldByCurrentThread()); |
119 |
|
assertEquals(0, rl.getReadLockCount()); |
120 |
|
rl.readLock().lock(); |
121 |
|
assertFalse(rl.isWriteLocked()); |
142 |
|
} |
143 |
|
} |
144 |
|
|
145 |
+ |
/** |
146 |
+ |
* WriteLock.getHoldCount returns number of recursive holds |
147 |
+ |
*/ |
148 |
+ |
public void testGetHoldCount() { |
149 |
+ |
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
150 |
+ |
for(int i = 1; i <= SIZE; i++) { |
151 |
+ |
lock.writeLock().lock(); |
152 |
+ |
assertEquals(i,lock.writeLock().getHoldCount()); |
153 |
+ |
} |
154 |
+ |
for(int i = SIZE; i > 0; i--) { |
155 |
+ |
lock.writeLock().unlock(); |
156 |
+ |
assertEquals(i-1,lock.writeLock().getHoldCount()); |
157 |
+ |
} |
158 |
+ |
} |
159 |
+ |
|
160 |
|
/** |
161 |
|
* getReadHoldCount returns number of recursive holds |
162 |
|
*/ |