217 |
|
|
218 |
|
V innerGet() throws InterruptedException, ExecutionException { |
219 |
|
acquireSharedInterruptibly(0); |
220 |
< |
if (getState() == CANCELLED) |
221 |
< |
throw new CancellationException(); |
222 |
< |
if (exception != null) |
223 |
< |
throw new ExecutionException(exception); |
224 |
< |
return result; |
220 |
> |
if (getState() == CANCELLED) |
221 |
> |
throw new CancellationException(); |
222 |
> |
if (exception != null) |
223 |
> |
throw new ExecutionException(exception); |
224 |
> |
return result; |
225 |
|
} |
226 |
|
|
227 |
|
V innerGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException { |
235 |
|
} |
236 |
|
|
237 |
|
void innerSet(V v) { |
238 |
< |
for (;;) { |
239 |
< |
int s = getState(); |
240 |
< |
if (s == RAN) |
241 |
< |
return; |
238 |
> |
for (;;) { |
239 |
> |
int s = getState(); |
240 |
> |
if (s == RAN) |
241 |
> |
return; |
242 |
|
if (s == CANCELLED) { |
243 |
< |
// aggressively release to set runner to null, |
244 |
< |
// in case we are racing with a cancel request |
245 |
< |
// that will try to interrupt runner |
243 |
> |
// aggressively release to set runner to null, |
244 |
> |
// in case we are racing with a cancel request |
245 |
> |
// that will try to interrupt runner |
246 |
|
releaseShared(0); |
247 |
|
return; |
248 |
|
} |
249 |
< |
if (compareAndSetState(s, RAN)) { |
249 |
> |
if (compareAndSetState(s, RAN)) { |
250 |
|
result = v; |
251 |
|
releaseShared(0); |
252 |
|
done(); |
253 |
< |
return; |
253 |
> |
return; |
254 |
|
} |
255 |
|
} |
256 |
|
} |
257 |
|
|
258 |
|
void innerSetException(Throwable t) { |
259 |
< |
for (;;) { |
260 |
< |
int s = getState(); |
261 |
< |
if (s == RAN) |
262 |
< |
return; |
259 |
> |
for (;;) { |
260 |
> |
int s = getState(); |
261 |
> |
if (s == RAN) |
262 |
> |
return; |
263 |
|
if (s == CANCELLED) { |
264 |
< |
// aggressively release to set runner to null, |
265 |
< |
// in case we are racing with a cancel request |
266 |
< |
// that will try to interrupt runner |
264 |
> |
// aggressively release to set runner to null, |
265 |
> |
// in case we are racing with a cancel request |
266 |
> |
// that will try to interrupt runner |
267 |
|
releaseShared(0); |
268 |
|
return; |
269 |
|
} |
270 |
< |
if (compareAndSetState(s, RAN)) { |
270 |
> |
if (compareAndSetState(s, RAN)) { |
271 |
|
exception = t; |
272 |
|
releaseShared(0); |
273 |
|
done(); |
274 |
< |
return; |
274 |
> |
return; |
275 |
|
} |
276 |
< |
} |
276 |
> |
} |
277 |
|
} |
278 |
|
|
279 |
|
boolean innerCancel(boolean mayInterruptIfRunning) { |
280 |
< |
for (;;) { |
281 |
< |
int s = getState(); |
282 |
< |
if (ranOrCancelled(s)) |
283 |
< |
return false; |
284 |
< |
if (compareAndSetState(s, CANCELLED)) |
285 |
< |
break; |
286 |
< |
} |
280 |
> |
for (;;) { |
281 |
> |
int s = getState(); |
282 |
> |
if (ranOrCancelled(s)) |
283 |
> |
return false; |
284 |
> |
if (compareAndSetState(s, CANCELLED)) |
285 |
> |
break; |
286 |
> |
} |
287 |
|
if (mayInterruptIfRunning) { |
288 |
|
Thread r = runner; |
289 |
|
if (r != null) |
310 |
|
set(result); |
311 |
|
} else { |
312 |
|
releaseShared(0); // cancel |
313 |
< |
} |
313 |
> |
} |
314 |
|
} |
315 |
|
|
316 |
|
boolean innerRunAndReset() { |