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

Comparing jsr166/src/jsr166y/Phaser.java (file contents):
Revision 1.57 by dl, Fri Nov 19 16:03:24 2010 UTC vs.
Revision 1.58 by dl, Wed Nov 24 15:48:01 2010 UTC

# Line 86 | Line 86 | import java.util.concurrent.locks.LockSu
86   * #forceTermination} is also available to abruptly release waiting
87   * threads and allow them to terminate.
88   *
89 < * <p> <b>Tiering.</b> Phasers may be <em>tiered</em> (i.e., arranged
90 < * in tree structures) to reduce contention. Phasers with large
91 < * numbers of parties that would otherwise experience heavy
89 > * <p> <b>Tiering.</b> Phasers may be <em>tiered</em> (i.e.,
90 > * constructed in tree structures) to reduce contention. Phasers with
91 > * large numbers of parties that would otherwise experience heavy
92   * synchronization contention costs may instead be set up so that
93   * groups of sub-phasers share a common parent.  This may greatly
94   * increase throughput even though it incurs greater per-operation
# Line 353 | Line 353 | public class Phaser {
353      /**
354       * Implementation of register, bulkRegister
355       *
356 <     * @param registrations number to add to both parties and unarrived fields
356 >     * @param registrations number to add to both parties and
357 >     * unarrived fields. Must be greater than zero.
358       */
359      private int doRegister(int registrations) {
359        // assert registrations > 0;
360          // adjustment to state
361          long adj = ((long)registrations << PARTIES_SHIFT) | registrations;
362          final Phaser parent = this.parent;
363          for (;;) {
364              long s = (parent == null) ? state : reconcileState();
365 +            int parties = (int)s >>> PARTIES_SHIFT;
366              int phase = (int)(s >>> PHASE_SHIFT);
367              if (phase < 0)
368                  return phase;
369 <            int parties = (int)s >>> PARTIES_SHIFT;
369 <            if (parties != 0 && ((int)s & UNARRIVED_MASK) == 0)
369 >            else if (parties != 0 && ((int)s & UNARRIVED_MASK) == 0)
370                  internalAwaitAdvance(phase, null); // wait for onAdvance
371              else if (registrations > MAX_PARTIES - parties)
372                  throw new IllegalStateException(badRegister(s));
# Line 433 | Line 433 | public class Phaser {
433      }
434  
435      /**
436 <     * Creates a new phaser with the given parent, without any
437 <     * initially registered parties. If parent is non-null this phaser
438 <     * is registered with the parent and its initial phase number is
439 <     * the same as that of parent phaser.
436 >     * Equivalent to {@link #Phaser(Phaser, int) Phaser(parent, 0)}.
437       *
438       * @param parent the parent phaser
439       */
# Line 446 | Line 443 | public class Phaser {
443  
444      /**
445       * Creates a new phaser with the given parent and number of
446 <     * registered unarrived parties. If parent is non-null, this phaser
447 <     * is registered with the parent and its initial phase number is
448 <     * the same as that of parent phaser.
446 >     * registered unarrived parties. If parent is non-null, this
447 >     * phaser is registered with the parent and its initial phase
448 >     * number is the same as that of parent phaser.  If the number of
449 >     * parties is zero, the parent phaser will not proceed until this
450 >     * child phaser registers parties and advances, or this child
451 >     * phaser deregisters with its parent, or the parent is otherwise
452 >     * terminated.  This child Phaser will be deregistered from its
453 >     * parent automatically upon any invocation of the child's {@link
454 >     * #arriveAndDeregister} method that results in the child's number
455 >     * of registered parties becoming zero. (Although rarely
456 >     * appropriate, this child may also explicity deregister from its
457 >     * parent using {@code getParent().arriveAndDeregister()}.)  After
458 >     * deregistration, the child cannot re-register. (Instead, you can
459 >     * create a new child Phaser.)
460       *
461       * @param parent the parent phaser
462       * @param parties the number of parties required to trip barrier
# Line 465 | Line 473 | public class Phaser {
473              this.root = r;
474              this.evenQ = r.evenQ;
475              this.oddQ = r.oddQ;
476 <            phase = parent.register();
476 >            phase = parent.doRegister(1);
477          }
478          else {
479              this.root = this;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines