235 |
|
void innerSet(V v) { |
236 |
|
for (;;) { |
237 |
|
int s = getState(); |
238 |
< |
if (ranOrCancelled(s)) |
238 |
> |
if (s == RAN) |
239 |
|
return; |
240 |
< |
if (compareAndSetState(s, RAN)) |
241 |
< |
break; |
242 |
< |
} |
243 |
< |
result = v; |
244 |
< |
releaseShared(0); |
245 |
< |
done(); |
240 |
> |
if (s == CANCELLED) { |
241 |
> |
releaseShared(0); |
242 |
> |
return; |
243 |
> |
} |
244 |
> |
if (compareAndSetState(s, RAN)) { |
245 |
> |
result = v; |
246 |
> |
releaseShared(0); |
247 |
> |
done(); |
248 |
> |
return; |
249 |
> |
} |
250 |
> |
} |
251 |
|
} |
252 |
|
|
253 |
|
void innerSetException(Throwable t) { |
254 |
|
for (;;) { |
255 |
|
int s = getState(); |
256 |
< |
if (ranOrCancelled(s)) |
256 |
> |
if (s == RAN) |
257 |
|
return; |
258 |
< |
if (compareAndSetState(s, RAN)) |
259 |
< |
break; |
258 |
> |
if (s == CANCELLED) { |
259 |
> |
releaseShared(0); |
260 |
> |
return; |
261 |
> |
} |
262 |
> |
if (compareAndSetState(s, RAN)) { |
263 |
> |
exception = t; |
264 |
> |
result = null; |
265 |
> |
releaseShared(0); |
266 |
> |
done(); |
267 |
> |
return; |
268 |
> |
} |
269 |
|
} |
256 |
– |
exception = t; |
257 |
– |
result = null; |
258 |
– |
releaseShared(0); |
259 |
– |
done(); |
270 |
|
} |
271 |
|
|
272 |
|
boolean innerCancel(boolean mayInterruptIfRunning) { |
279 |
|
} |
280 |
|
if (mayInterruptIfRunning) { |
281 |
|
Thread r = runner; |
282 |
< |
if (r != null) { |
283 |
< |
Thread.yield(); // Heuristic to avoid stall on next lines |
274 |
< |
if (r == runner) |
275 |
< |
r.interrupt(); |
276 |
< |
} |
282 |
> |
if (r != null) |
283 |
> |
r.interrupt(); |
284 |
|
} |
285 |
|
releaseShared(0); |
286 |
|
done(); |