241 |
|
*/ |
242 |
|
private volatile long state; |
243 |
|
|
244 |
< |
private static final int ushortMask = 0xffff; |
244 |
> |
private static final int ushortBits = 16; |
245 |
> |
private static final int ushortMask = (1 << ushortBits) - 1; |
246 |
|
private static final int phaseMask = 0x7fffffff; |
247 |
|
|
248 |
|
private static int unarrivedOf(long s) { |
249 |
< |
return (int) (s & ushortMask); |
249 |
> |
return ((int) s) & ushortMask; |
250 |
|
} |
251 |
|
|
252 |
|
private static int partiesOf(long s) { |
253 |
< |
return ((int) s) >>> 16; |
253 |
> |
return ((int) s) >>> ushortBits; |
254 |
|
} |
255 |
|
|
256 |
|
private static int phaseOf(long s) { |
257 |
< |
return (int) (s >>> 32); |
257 |
> |
return (int) (s >>> (2 * ushortBits)); |
258 |
|
} |
259 |
|
|
260 |
|
private static int arrivedOf(long s) { |
262 |
|
} |
263 |
|
|
264 |
|
private static long stateFor(int phase, int parties, int unarrived) { |
265 |
< |
return ((((long) phase) << 32) | (((long) parties) << 16) | |
265 |
> |
return ((((long) phase) << (2 * ushortBits)) | |
266 |
> |
(((long) parties) << ushortBits) | |
267 |
|
(long) unarrived); |
268 |
|
} |
269 |
|
|
270 |
|
private static long trippedStateFor(int phase, int parties) { |
271 |
|
long lp = (long) parties; |
272 |
< |
return (((long) phase) << 32) | (lp << 16) | lp; |
272 |
> |
return (((long) phase) << (2 * ushortBits)) | (lp << ushortBits) | lp; |
273 |
|
} |
274 |
|
|
275 |
|
/** |
382 |
|
* or greater than the maximum number of parties supported |
383 |
|
*/ |
384 |
|
public Phaser(Phaser parent, int parties) { |
385 |
< |
if (parties < 0 || parties > ushortMask) |
385 |
> |
if (parties >>> ushortBits != 0) |
386 |
|
throw new IllegalArgumentException("Illegal number of parties"); |
387 |
|
int phase; |
388 |
|
this.parent = parent; |
448 |
|
int parties = p + registrations; |
449 |
|
if (u == 0 && p != 0) // if tripped, wait for advance |
450 |
|
untimedWait(phase); |
451 |
< |
else if (parties > ushortMask) |
451 |
> |
else if (parties >>> ushortBits != 0) |
452 |
|
throw new IllegalStateException(badBounds(parties, unarrived)); |
453 |
|
else if (par == null || phaseOf(root.state) == phase) { |
454 |
|
long next = stateFor(phase, parties, unarrived); |