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

Comparing jsr166/src/main/java/util/concurrent/CompletableFuture.java (file contents):
Revision 1.197 by jsr166, Mon Jun 20 21:05:28 2016 UTC vs.
Revision 1.198 by jsr166, Mon Jun 20 23:30:05 2016 UTC

# Line 525 | Line 525 | public class CompletableFuture<T> implem
525  
526      /**
527       * Pushes the given completion unless it completes while trying.
528 <     * Caller should have first checked that result is null.
528 >     * Caller should first check that result is null.
529       */
530 <    final void unipush(UniCompletion<?,?> c) {
530 >    final void unipush(Completion c) {
531          if (c != null) {
532              while (!tryPushStack(c)) {
533                  if (result != null) {
# Line 1092 | Line 1092 | public class CompletableFuture<T> implem
1092          }
1093      }
1094  
1095 <    /** Pushes completion to this and b unless both done. */
1095 >    /**
1096 >     * Pushes completion to this and b unless both done.
1097 >     * Caller should first check that either result or b.result is null.
1098 >     */
1099      final void bipush(CompletableFuture<?> b, BiCompletion<?,?,?> c) {
1100          if (c != null) {
1101 <            Object r;
1102 <            while ((r = result) == null && !tryPushStack(c))
1103 <                NEXT.set(c, null);  // clear on failure
1104 <            if (b != null && b != this && b.result == null) {
1105 <                Completion q = (r != null) ? c : new CoCompletion(c);
1106 <                while (b.result == null && !b.tryPushStack(q))
1107 <                    NEXT.set(q, null);  // clear on failure
1101 >            while (result == null) {
1102 >                if (tryPushStack(c)) {
1103 >                    if (b.result == null)
1104 >                        b.unipush(new CoCompletion(c));
1105 >                    else if (result != null)
1106 >                        c.tryFire(SYNC);
1107 >                    return;
1108 >                }
1109              }
1110 +            b.unipush(c);
1111          }
1112      }
1113  
# Line 1193 | Line 1198 | public class CompletableFuture<T> implem
1198              }
1199              else {
1200                  bipush(b, c);
1196                c.tryFire(SYNC);
1201              }
1202          }
1203          return d;
# Line 1274 | Line 1278 | public class CompletableFuture<T> implem
1278              }
1279              else {
1280                  bipush(b, c);
1277                c.tryFire(SYNC);
1281              }
1282          }
1283          return d;
# Line 1342 | Line 1345 | public class CompletableFuture<T> implem
1345              }
1346              else {
1347                  bipush(b, c);
1345                c.tryFire(SYNC);
1348              }
1349          }
1350          return d;
# Line 1396 | Line 1398 | public class CompletableFuture<T> implem
1398                  (b = (lo == hi ? a : (hi == mid+1) ? cfs[hi] :
1399                        andTree(cfs, mid+1, hi))) == null)
1400                  throw new NullPointerException();
1401 <            if (!d.biRelay(a, b)) {
1402 <                BiRelay<?,?> c = new BiRelay<>(d, a, b);
1401 <                a.bipush(b, c);
1402 <                c.tryFire(SYNC);
1403 <            }
1401 >            if (!d.biRelay(a, b))
1402 >                a.bipush(b, new BiRelay<>(d, a, b));
1403          }
1404          return d;
1405      }
1406  
1407      /* ------------- Projected (Ored) BiCompletions -------------- */
1408  
1409 <    /** Pushes completion to this and b unless either done. */
1409 >    /**
1410 >     * Pushes completion to this and b unless either done.
1411 >     * Caller should first check that result and b.result are both null.
1412 >     */
1413      final void orpush(CompletableFuture<?> b, BiCompletion<?,?,?> c) {
1414          if (c != null) {
1415 <            while ((b == null || b.result == null) && result == null) {
1416 <                if (tryPushStack(c)) {
1417 <                    if (b != null && b != this && b.result == null) {
1416 <                        Completion q = new CoCompletion(c);
1417 <                        while (result == null && b.result == null &&
1418 <                               !b.tryPushStack(q))
1419 <                            NEXT.set(q, null);  // clear on failure
1420 <                    }
1415 >            while (!tryPushStack(c)) {
1416 >                if (result != null) {
1417 >                    NEXT.set(c, null);
1418                      break;
1419                  }
1423                NEXT.set(c, null);  // clear on failure
1420              }
1421 +            if (result != null)
1422 +                c.tryFire(SYNC);
1423 +            else
1424 +                b.unipush(new CoCompletion(c));
1425          }
1426      }
1427  
# Line 1492 | Line 1492 | public class CompletableFuture<T> implem
1492              }
1493              else {
1494                  orpush(b, c);
1495                c.tryFire(SYNC);
1495              }
1496          }
1497          return d;
# Line 1565 | Line 1564 | public class CompletableFuture<T> implem
1564              }
1565              else {
1566                  orpush(b, c);
1568                c.tryFire(SYNC);
1567              }
1568          }
1569          return d;
# Line 1632 | Line 1630 | public class CompletableFuture<T> implem
1630              }
1631              else {
1632                  orpush(b, c);
1635                c.tryFire(SYNC);
1633              }
1634          }
1635          return d;
# Line 1677 | Line 1674 | public class CompletableFuture<T> implem
1674                  (b = (lo == hi ? a : (hi == mid+1) ? cfs[hi] :
1675                        orTree(cfs, mid+1, hi))) == null)
1676                  throw new NullPointerException();
1677 <            if (!d.orRelay(a, b)) {
1678 <                OrRelay<?,?> c = new OrRelay<>(d, a, b);
1682 <                a.orpush(b, c);
1683 <                c.tryFire(SYNC);
1684 <            }
1677 >            if (!d.orRelay(a, b))
1678 >                a.orpush(b, new OrRelay<>(d, a, b));
1679          }
1680          return d;
1681      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines