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.137 by jsr166, Sun Jan 4 01:06:15 2015 UTC vs.
Revision 1.138 by jsr166, Sun Jan 4 09:15:11 2015 UTC

# Line 180 | Line 180 | public class CompletableFuture<T> implem
180      volatile Completion stack;    // Top of Treiber stack of dependent actions
181  
182      final boolean internalComplete(Object r) { // CAS from null to r
183 <        return UNSAFE.compareAndSwapObject(this, RESULT, null, r);
183 >        return U.compareAndSwapObject(this, RESULT, null, r);
184      }
185  
186      final boolean casStack(Completion cmp, Completion val) {
187 <        return UNSAFE.compareAndSwapObject(this, STACK, cmp, val);
187 >        return U.compareAndSwapObject(this, STACK, cmp, val);
188      }
189  
190      /** Returns true if successfully pushed c onto stack. */
191      final boolean tryPushStack(Completion c) {
192          Completion h = stack;
193          lazySetNext(c, h);
194 <        return UNSAFE.compareAndSwapObject(this, STACK, h, c);
194 >        return U.compareAndSwapObject(this, STACK, h, c);
195      }
196  
197      /** Unconditionally pushes c onto stack, retrying if necessary. */
# Line 211 | Line 211 | public class CompletableFuture<T> implem
211  
212      /** Completes with the null value, unless already completed. */
213      final boolean completeNull() {
214 <        return UNSAFE.compareAndSwapObject(this, RESULT, null,
214 >        return U.compareAndSwapObject(this, RESULT, null,
215                                             NIL);
216      }
217  
# Line 222 | Line 222 | public class CompletableFuture<T> implem
222  
223      /** Completes with a non-exceptional result, unless already completed. */
224      final boolean completeValue(T t) {
225 <        return UNSAFE.compareAndSwapObject(this, RESULT, null,
225 >        return U.compareAndSwapObject(this, RESULT, null,
226                                             (t == null) ? NIL : t);
227      }
228  
# Line 237 | Line 237 | public class CompletableFuture<T> implem
237  
238      /** Completes with an exceptional result, unless already completed. */
239      final boolean completeThrowable(Throwable x) {
240 <        return UNSAFE.compareAndSwapObject(this, RESULT, null,
240 >        return U.compareAndSwapObject(this, RESULT, null,
241                                             encodeThrowable(x));
242      }
243  
# Line 265 | Line 265 | public class CompletableFuture<T> implem
265       * existing CompletionException.
266       */
267      final boolean completeThrowable(Throwable x, Object r) {
268 <        return UNSAFE.compareAndSwapObject(this, RESULT, null,
268 >        return U.compareAndSwapObject(this, RESULT, null,
269                                             encodeThrowable(x, r));
270      }
271  
# Line 295 | Line 295 | public class CompletableFuture<T> implem
295       * If exceptional, r is first coerced to a CompletionException.
296       */
297      final boolean completeRelay(Object r) {
298 <        return UNSAFE.compareAndSwapObject(this, RESULT, null,
298 >        return U.compareAndSwapObject(this, RESULT, null,
299                                             encodeRelay(r));
300      }
301  
# Line 407 | Line 407 | public class CompletableFuture<T> implem
407      }
408  
409      static void lazySetNext(Completion c, Completion next) {
410 <        UNSAFE.putOrderedObject(c, NEXT, next);
410 >        U.putOrderedObject(c, NEXT, next);
411      }
412  
413      /**
# Line 2318 | Line 2318 | public class CompletableFuture<T> implem
2318      }
2319  
2320      // Unsafe mechanics
2321 <    private static final sun.misc.Unsafe UNSAFE;
2321 >    private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
2322      private static final long RESULT;
2323      private static final long STACK;
2324      private static final long NEXT;
2325      static {
2326          try {
2327 <            final sun.misc.Unsafe u;
2328 <            UNSAFE = u = sun.misc.Unsafe.getUnsafe();
2329 <            Class<?> k = CompletableFuture.class;
2330 <            RESULT = u.objectFieldOffset(k.getDeclaredField("result"));
2331 <            STACK = u.objectFieldOffset(k.getDeclaredField("stack"));
2332 <            NEXT = u.objectFieldOffset
2327 >            RESULT = U.objectFieldOffset
2328 >                (CompletableFuture.class.getDeclaredField("result"));
2329 >            STACK = U.objectFieldOffset
2330 >                (CompletableFuture.class.getDeclaredField("stack"));
2331 >            NEXT = U.objectFieldOffset
2332                  (Completion.class.getDeclaredField("next"));
2333          } catch (ReflectiveOperationException e) {
2334              throw new Error(e);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines