100 |
|
} |
101 |
|
|
102 |
|
public boolean cancel(boolean mayInterruptIfRunning) { |
103 |
+ |
final ReentrantLock lock = this.lock; |
104 |
+ |
Thread interruptThread = null; |
105 |
|
lock.lock(); |
106 |
|
try { |
107 |
|
Object r = runState; |
108 |
|
if (r == DONE || r == CANCELLED) |
109 |
|
return false; |
108 |
– |
runState = CANCELLED; |
109 |
– |
accessible.signalAll(); |
110 |
|
if (mayInterruptIfRunning && r != null && r instanceof Thread) |
111 |
< |
((Thread)r).interrupt(); |
111 |
> |
interruptThread = (Thread)r; |
112 |
> |
accessible.signalAll(); |
113 |
> |
runState = CANCELLED; |
114 |
|
} |
115 |
|
finally{ |
116 |
|
lock.unlock(); |
117 |
|
} |
118 |
+ |
if (interruptThread != null) |
119 |
+ |
interruptThread.interrupt(); |
120 |
|
done(); |
121 |
|
return true; |
122 |
|
} |
134 |
|
* while waiting |
135 |
|
*/ |
136 |
|
public V get() throws InterruptedException, ExecutionException { |
137 |
+ |
final ReentrantLock lock = this.lock; |
138 |
|
lock.lock(); |
139 |
|
try { |
140 |
|
for (;;) { |
172 |
|
public V get(long timeout, TimeUnit unit) |
173 |
|
throws InterruptedException, ExecutionException, TimeoutException { |
174 |
|
long nanos = unit.toNanos(timeout); |
175 |
+ |
final ReentrantLock lock = this.lock; |
176 |
|
lock.lock(); |
177 |
|
try { |
178 |
|
for (;;) { |
211 |
|
* @param v the value |
212 |
|
*/ |
213 |
|
protected void set(V v) { |
214 |
+ |
final ReentrantLock lock = this.lock; |
215 |
|
lock.lock(); |
216 |
|
try { |
217 |
|
if (runState == CANCELLED) |
232 |
|
* @param t the cause of failure. |
233 |
|
*/ |
234 |
|
protected void setException(Throwable t) { |
235 |
+ |
final ReentrantLock lock = this.lock; |
236 |
|
lock.lock(); |
237 |
|
try { |
238 |
|
if (runState == CANCELLED) |
252 |
|
* @return true if successful |
253 |
|
*/ |
254 |
|
private boolean setRunning() { |
255 |
+ |
final ReentrantLock lock = this.lock; |
256 |
|
lock.lock(); |
257 |
|
try { |
258 |
|
if (runState != null) |
272 |
|
* @return true if successful |
273 |
|
*/ |
274 |
|
private boolean reset() { |
275 |
+ |
final ReentrantLock lock = this.lock; |
276 |
|
lock.lock(); |
277 |
|
try { |
278 |
|
if (runState == CANCELLED) |