66 |
|
public boolean isCancelled() { |
67 |
|
return sync.innerIsCancelled(); |
68 |
|
} |
69 |
< |
|
69 |
> |
|
70 |
|
public boolean isDone() { |
71 |
|
return sync.innerIsDone(); |
72 |
|
} |
74 |
|
public boolean cancel(boolean mayInterruptIfRunning) { |
75 |
|
return sync.innerCancel(mayInterruptIfRunning); |
76 |
|
} |
77 |
< |
|
77 |
> |
|
78 |
|
public V get() throws InterruptedException, ExecutionException { |
79 |
|
return sync.innerGet(); |
80 |
|
} |
99 |
|
* Sets the result of this Future to the given value unless |
100 |
|
* this future has already been set or has been cancelled. |
101 |
|
* @param v the value |
102 |
< |
*/ |
102 |
> |
*/ |
103 |
|
protected void set(V v) { |
104 |
|
sync.innerSet(v); |
105 |
|
} |
109 |
|
* with the given throwable as its cause, unless this Future has |
110 |
|
* already been set or has been cancelled. |
111 |
|
* @param t the cause of failure. |
112 |
< |
*/ |
112 |
> |
*/ |
113 |
|
protected void setException(Throwable t) { |
114 |
|
sync.innerSetException(t); |
115 |
|
} |
116 |
< |
|
116 |
> |
|
117 |
|
/** |
118 |
|
* Sets this Future to the result of computation unless |
119 |
|
* it has been cancelled. |
157 |
|
/** The exception to throw from get() */ |
158 |
|
private Throwable exception; |
159 |
|
|
160 |
< |
/** |
160 |
> |
/** |
161 |
|
* The thread running task. When nulled after set/cancel, this |
162 |
|
* indicates that the results are accessible. Must be |
163 |
|
* volatile, to ensure visibility upon completion. |
185 |
|
*/ |
186 |
|
protected boolean tryReleaseShared(int ignore) { |
187 |
|
runner = null; |
188 |
< |
return true; |
188 |
> |
return true; |
189 |
|
} |
190 |
|
|
191 |
|
boolean innerIsCancelled() { |
192 |
|
return getState() == CANCELLED; |
193 |
|
} |
194 |
< |
|
194 |
> |
|
195 |
|
boolean innerIsDone() { |
196 |
|
return ranOrCancelled(getState()) && runner == null; |
197 |
|
} |
207 |
|
|
208 |
|
V innerGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException { |
209 |
|
if (!tryAcquireSharedNanos(0, nanosTimeout)) |
210 |
< |
throw new TimeoutException(); |
210 |
> |
throw new TimeoutException(); |
211 |
|
if (getState() == CANCELLED) |
212 |
|
throw new CancellationException(); |
213 |
|
if (exception != null) |
247 |
|
int s = getState(); |
248 |
|
if (ranOrCancelled(s)) |
249 |
|
return false; |
250 |
< |
if (compareAndSetState(s, CANCELLED)) |
250 |
> |
if (compareAndSetState(s, CANCELLED)) |
251 |
|
break; |
252 |
|
} |
253 |
|
if (mayInterruptIfRunning) { |
261 |
|
} |
262 |
|
|
263 |
|
void innerRun() { |
264 |
< |
if (!compareAndSetState(0, RUNNING)) |
264 |
> |
if (!compareAndSetState(0, RUNNING)) |
265 |
|
return; |
266 |
|
try { |
267 |
|
runner = Thread.currentThread(); |
268 |
|
innerSet(callable.call()); |
269 |
|
} catch (Throwable ex) { |
270 |
|
innerSetException(ex); |
271 |
< |
} |
271 |
> |
} |
272 |
|
} |
273 |
|
|
274 |
|
boolean innerRunAndReset() { |
275 |
< |
if (!compareAndSetState(0, RUNNING)) |
275 |
> |
if (!compareAndSetState(0, RUNNING)) |
276 |
|
return false; |
277 |
|
try { |
278 |
|
runner = Thread.currentThread(); |
282 |
|
} catch (Throwable ex) { |
283 |
|
innerSetException(ex); |
284 |
|
return false; |
285 |
< |
} |
285 |
> |
} |
286 |
|
} |
287 |
|
} |
288 |
|
} |