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

Comparing jsr166/src/main/java/util/concurrent/CountedCompleter.java (file contents):
Revision 1.54 by jsr166, Wed Apr 27 19:51:53 2016 UTC vs.
Revision 1.55 by dl, Thu Jun 2 13:16:27 2016 UTC

# Line 6 | Line 6
6  
7   package java.util.concurrent;
8  
9 + import java.lang.invoke.MethodHandles;
10 + import java.lang.invoke.VarHandle;
11 +
12   /**
13   * A {@link ForkJoinTask} with a completion action performed when
14   * triggered and there are no remaining pending actions.
# Line 495 | Line 498 | public abstract class CountedCompleter<T
498       * @param delta the value to add
499       */
500      public final void addToPendingCount(int delta) {
501 <        U.getAndAddInt(this, PENDING, delta);
501 >        PENDING.getAndAdd(this, delta);
502      }
503  
504      /**
# Line 507 | Line 510 | public abstract class CountedCompleter<T
510       * @return {@code true} if successful
511       */
512      public final boolean compareAndSetPendingCount(int expected, int count) {
513 <        return U.compareAndSwapInt(this, PENDING, expected, count);
513 >        return PENDING.compareAndSet(this, expected, count);
514      }
515  
516      /**
# Line 519 | Line 522 | public abstract class CountedCompleter<T
522      public final int decrementPendingCountUnlessZero() {
523          int c;
524          do {} while ((c = pending) != 0 &&
525 <                     !U.compareAndSwapInt(this, PENDING, c, c - 1));
525 >                     !PENDING.compareAndSet(this, c, c - 1));
526          return c;
527      }
528  
# Line 552 | Line 555 | public abstract class CountedCompleter<T
555                      return;
556                  }
557              }
558 <            else if (U.compareAndSwapInt(a, PENDING, c, c - 1))
558 >            else if (PENDING.compareAndSet(a, c, c - 1))
559                  return;
560          }
561      }
# Line 575 | Line 578 | public abstract class CountedCompleter<T
578                      return;
579                  }
580              }
581 <            else if (U.compareAndSwapInt(a, PENDING, c, c - 1))
581 >            else if (PENDING.compareAndSet(a, c, c - 1))
582                  return;
583          }
584      }
# Line 620 | Line 623 | public abstract class CountedCompleter<T
623          for (int c;;) {
624              if ((c = pending) == 0)
625                  return this;
626 <            else if (U.compareAndSwapInt(this, PENDING, c, c - 1))
626 >            else if (PENDING.compareAndSet(this, c, c - 1))
627                  return null;
628          }
629      }
# Line 724 | Line 727 | public abstract class CountedCompleter<T
727       */
728      protected void setRawResult(T t) { }
729  
730 <    // Unsafe mechanics
731 <    private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
729 <    private static final long PENDING;
730 >    // VarHandle mechanics
731 >    private static final VarHandle PENDING;
732      static {
733          try {
734 <            PENDING = U.objectFieldOffset
735 <                (CountedCompleter.class.getDeclaredField("pending"));
734 >            MethodHandles.Lookup l = MethodHandles.lookup();
735 >            PENDING = l.findVarHandle(CountedCompleter.class, "pending", int.class);
736 >            
737          } catch (ReflectiveOperationException e) {
738              throw new Error(e);
739          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines