ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/Phaser.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/Phaser.java (file contents):
Revision 1.15 by dl, Sat Nov 6 16:11:50 2010 UTC vs.
Revision 1.16 by jsr166, Sun Nov 7 19:01:42 2010 UTC

# Line 241 | Line 241 | public class Phaser {
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) {
# Line 261 | Line 262 | public class Phaser {
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      /**
# Line 380 | Line 382 | public class Phaser {
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;
# Line 446 | Line 448 | public class Phaser {
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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines