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. |
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 |
|
/** |
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 |
|
/** |
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 |
|
|
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
} |