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.133 by jsr166, Thu Aug 28 11:40:51 2014 UTC vs.
Revision 1.134 by jsr166, Thu Aug 28 12:13:25 2014 UTC

# Line 200 | Line 200 | public class CompletableFuture<T> implem
200      /** Returns true if successfully pushed c onto stack. */
201      final boolean tryPushStack(Completion c) {
202          Completion h = stack;
203 <        c.lazySetNext(h);
203 >        lazySetNext(c, h);
204          return UNSAFE.compareAndSwapObject(this, STACK, h, c);
205      }
206  
# Line 414 | Line 414 | public class CompletableFuture<T> implem
414          public final boolean exec()            { tryFire(ASYNC); return true; }
415          public final Void getRawResult()       { return null; }
416          public final void setRawResult(Void v) {}
417 +    }
418  
419 <        void lazySetNext(Completion val) {
420 <            UNSAFE.putOrderedObject(this, NEXT, val);
420 <        }
421 <
422 <        // Unsafe mechanics
423 <
424 <        private static final sun.misc.Unsafe UNSAFE;
425 <        private static final long NEXT;
426 <
427 <        static {
428 <            try {
429 <                UNSAFE = sun.misc.Unsafe.getUnsafe();
430 <                NEXT = UNSAFE.objectFieldOffset
431 <                    (Completion.class.getDeclaredField("next"));
432 <            } catch (Exception e) {
433 <                throw new Error(e);
434 <            }
435 <        }
419 >    static void lazySetNext(Completion c, Completion next) {
420 >        UNSAFE.putOrderedObject(c, NEXT, next);
421      }
422  
423      /**
# Line 524 | Line 509 | public class CompletableFuture<T> implem
509      final void push(UniCompletion<?,?> c) {
510          if (c != null) {
511              while (result == null && !tryPushStack(c))
512 <                c.lazySetNext(null); // clear on failure
512 >                lazySetNext(c, null); // clear on failure
513          }
514      }
515  
# Line 1011 | Line 996 | public class CompletableFuture<T> implem
996          if (c != null) {
997              Object r;
998              while ((r = result) == null && !tryPushStack(c))
999 <                c.lazySetNext(null); // clear on failure
999 >                lazySetNext(c, null); // clear on failure
1000              if (b != null && b != this && b.result == null) {
1001                  Completion q = (r != null) ? c : new CoCompletion(c);
1002                  while (b.result == null && !b.tryPushStack(q))
1003 <                    q.lazySetNext(null); // clear on failure
1003 >                    lazySetNext(q, null); // clear on failure
1004              }
1005          }
1006      }
# Line 1302 | Line 1287 | public class CompletableFuture<T> implem
1287                          Completion q = new CoCompletion(c);
1288                          while (result == null && b.result == null &&
1289                                 !b.tryPushStack(q))
1290 <                            q.lazySetNext(null); // clear on failure
1290 >                            lazySetNext(q, null); // clear on failure
1291                      }
1292                      break;
1293                  }
1294 <                c.lazySetNext(null); // clear on failure
1294 >                lazySetNext(c, null); // clear on failure
1295              }
1296          }
1297      }
# Line 2346 | Line 2331 | public class CompletableFuture<T> implem
2331      private static final sun.misc.Unsafe UNSAFE;
2332      private static final long RESULT;
2333      private static final long STACK;
2334 +    private static final long NEXT;
2335      static {
2336          try {
2337              UNSAFE = sun.misc.Unsafe.getUnsafe();
# Line 2354 | Line 2340 | public class CompletableFuture<T> implem
2340                  (k.getDeclaredField("result"));
2341              STACK = UNSAFE.objectFieldOffset
2342                  (k.getDeclaredField("stack"));
2343 +            NEXT = UNSAFE.objectFieldOffset
2344 +                (Completion.class.getDeclaredField("next"));
2345          } catch (Exception x) {
2346              throw new Error(x);
2347          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines