114 |
|
*/ |
115 |
|
private static class Generation { |
116 |
|
boolean broken = false; |
117 |
– |
boolean tripped = false; |
117 |
|
} |
118 |
|
|
119 |
|
/** The lock for guarding barrier entry */ |
140 |
|
*/ |
141 |
|
private void nextGeneration() { |
142 |
|
// signal completion of last generation |
144 |
– |
generation.tripped = true; |
143 |
|
trip.signalAll(); |
144 |
|
// set up next generation |
145 |
|
count = parties; |
199 |
|
else if (nanos > 0L) |
200 |
|
nanos = trip.awaitNanos(nanos); |
201 |
|
} catch (InterruptedException ie) { |
202 |
< |
breakBarrier(); |
203 |
< |
throw ie; |
202 |
> |
if (g == generation && ! g.broken) { |
203 |
> |
breakBarrier(); |
204 |
> |
throw ie; |
205 |
> |
} else { |
206 |
> |
// We're about to finish waiting even if we had not |
207 |
> |
// been interrupted, so this interrupt is deemed to |
208 |
> |
// "belong" to subsequent execution. |
209 |
> |
Thread.currentThread().interrupt(); |
210 |
> |
} |
211 |
|
} |
212 |
|
|
213 |
|
if (g.broken) |
214 |
|
throw new BrokenBarrierException(); |
215 |
|
|
216 |
< |
if (g.tripped) |
216 |
> |
if (g != generation) |
217 |
|
return index; |
218 |
|
|
219 |
|
if (timed && nanos <= 0L) { |
274 |
|
* |
275 |
|
* <p>If the current thread is not the last to arrive then it is |
276 |
|
* disabled for thread scheduling purposes and lies dormant until |
277 |
< |
* one of following things happens: |
277 |
> |
* one of the following things happens: |
278 |
|
* <ul> |
279 |
|
* <li>The last thread arrives; or |
280 |
|
* <li>Some other thread {@link Thread#interrupt interrupts} the current |