214 |
|
} |
215 |
|
|
216 |
|
/** |
217 |
< |
* Blocks a worker thread until completion. Called only by pool. |
217 |
> |
* Blocks a worker thread until completion. Called only by |
218 |
> |
* pool. Currently unused -- pool-based waits use timeout |
219 |
> |
* version below. |
220 |
|
*/ |
221 |
|
final void internalAwaitDone() { |
222 |
|
int s; // the odd construction reduces lock bias effects |
233 |
|
} |
234 |
|
|
235 |
|
/** |
236 |
+ |
* Blocks a worker thread until completed or timed out. Called |
237 |
+ |
* only by pool. |
238 |
+ |
* |
239 |
+ |
* @return status on exit |
240 |
+ |
*/ |
241 |
+ |
final int internalAwaitDone(long millis) { |
242 |
+ |
int s; |
243 |
+ |
if ((s = status) >= 0) { |
244 |
+ |
try { |
245 |
+ |
synchronized(this) { |
246 |
+ |
if (UNSAFE.compareAndSwapInt(this, statusOffset, s,SIGNAL)) |
247 |
+ |
wait(millis, 0); |
248 |
+ |
} |
249 |
+ |
} catch (InterruptedException ie) { |
250 |
+ |
cancelIfTerminating(); |
251 |
+ |
} |
252 |
+ |
s = status; |
253 |
+ |
} |
254 |
+ |
return s; |
255 |
+ |
} |
256 |
+ |
|
257 |
+ |
/** |
258 |
|
* Blocks a non-worker-thread until completion. |
259 |
|
*/ |
260 |
|
private void externalAwaitDone() { |
667 |
|
*/ |
668 |
|
boolean interrupted = false; |
669 |
|
boolean dec = false; // true if pool count decremented |
670 |
+ |
long nanos = unit.toNanos(timeout); |
671 |
|
for (;;) { |
672 |
|
if (Thread.interrupted() && pool == null) { |
673 |
|
interrupted = true; |
678 |
|
break; |
679 |
|
if (UNSAFE.compareAndSwapInt(this, statusOffset, s, SIGNAL)) { |
680 |
|
long startTime = System.nanoTime(); |
656 |
– |
long nanos = unit.toNanos(timeout); |
681 |
|
long nt; // wait time |
682 |
|
while (status >= 0 && |
683 |
|
(nt = nanos - (System.nanoTime() - startTime)) > 0) { |