Skip to content

Commit

Permalink
Stop qualifying references to local types.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=143116418
  • Loading branch information
cpovirk committed Dec 28, 2016
1 parent c27d09c commit 34891e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions guava/src/com/google/common/util/concurrent/AbstractFuture.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public V get(long timeout, TimeUnit unit)
throw new InterruptedException(); throw new InterruptedException();
} }
Object localValue = value; Object localValue = value;
if (localValue != null & !(localValue instanceof AbstractFuture.SetFuture)) { if (localValue != null & !(localValue instanceof SetFuture)) {
return getDoneValue(localValue); return getDoneValue(localValue);
} }
// we delay calling nanoTime until we know we will need to either park or spin // we delay calling nanoTime until we know we will need to either park or spin
Expand All @@ -399,7 +399,7 @@ public V get(long timeout, TimeUnit unit)
// Otherwise re-read and check doneness. If we loop then it must have been a spurious // Otherwise re-read and check doneness. If we loop then it must have been a spurious
// wakeup // wakeup
localValue = value; localValue = value;
if (localValue != null & !(localValue instanceof AbstractFuture.SetFuture)) { if (localValue != null & !(localValue instanceof SetFuture)) {
return getDoneValue(localValue); return getDoneValue(localValue);
} }


Expand All @@ -423,7 +423,7 @@ public V get(long timeout, TimeUnit unit)
// waiters list // waiters list
while (remainingNanos > 0) { while (remainingNanos > 0) {
localValue = value; localValue = value;
if (localValue != null & !(localValue instanceof AbstractFuture.SetFuture)) { if (localValue != null & !(localValue instanceof SetFuture)) {
return getDoneValue(localValue); return getDoneValue(localValue);
} }
if (Thread.interrupted()) { if (Thread.interrupted()) {
Expand Down Expand Up @@ -457,7 +457,7 @@ public V get() throws InterruptedException, ExecutionException {
throw new InterruptedException(); throw new InterruptedException();
} }
Object localValue = value; Object localValue = value;
if (localValue != null & !(localValue instanceof AbstractFuture.SetFuture)) { if (localValue != null & !(localValue instanceof SetFuture)) {
return getDoneValue(localValue); return getDoneValue(localValue);
} }
Waiter oldHead = waiters; Waiter oldHead = waiters;
Expand All @@ -477,7 +477,7 @@ public V get() throws InterruptedException, ExecutionException {
// Otherwise re-read and check doneness. If we loop then it must have been a spurious // Otherwise re-read and check doneness. If we loop then it must have been a spurious
// wakeup // wakeup
localValue = value; localValue = value;
if (localValue != null & !(localValue instanceof AbstractFuture.SetFuture)) { if (localValue != null & !(localValue instanceof SetFuture)) {
return getDoneValue(localValue); return getDoneValue(localValue);
} }
} }
Expand Down Expand Up @@ -512,7 +512,7 @@ private V getDoneValue(Object obj) throws ExecutionException {
@Override @Override
public boolean isDone() { public boolean isDone() {
final Object localValue = value; final Object localValue = value;
return localValue != null & !(localValue instanceof AbstractFuture.SetFuture); return localValue != null & !(localValue instanceof SetFuture);
} }


@Override @Override
Expand All @@ -533,7 +533,7 @@ public boolean isCancelled() {
public boolean cancel(boolean mayInterruptIfRunning) { public boolean cancel(boolean mayInterruptIfRunning) {
Object localValue = value; Object localValue = value;
boolean rValue = false; boolean rValue = false;
if (localValue == null | localValue instanceof AbstractFuture.SetFuture) { if (localValue == null | localValue instanceof SetFuture) {
// Try to delay allocating the exception. At this point we may still lose the CAS, but it is // Try to delay allocating the exception. At this point we may still lose the CAS, but it is
// certainly less likely. // certainly less likely.
Throwable cause = Throwable cause =
Expand All @@ -551,11 +551,10 @@ public boolean cancel(boolean mayInterruptIfRunning) {
abstractFuture.interruptTask(); abstractFuture.interruptTask();
} }
complete(abstractFuture); complete(abstractFuture);
if (localValue instanceof AbstractFuture.SetFuture) { if (localValue instanceof SetFuture) {
// propagate cancellation to the future set in setfuture, this is racy, and we don't // propagate cancellation to the future set in setfuture, this is racy, and we don't
// care if we are successful or not. // care if we are successful or not.
ListenableFuture<?> futureToPropagateTo = ListenableFuture<?> futureToPropagateTo = ((SetFuture) localValue).future;
((AbstractFuture.SetFuture) localValue).future;
if (futureToPropagateTo instanceof TrustedFuture) { if (futureToPropagateTo instanceof TrustedFuture) {
// If the future is a TrustedFuture then we specifically avoid calling cancel() // If the future is a TrustedFuture then we specifically avoid calling cancel()
// this has 2 benefits // this has 2 benefits
Expand All @@ -566,7 +565,7 @@ public boolean cancel(boolean mayInterruptIfRunning) {
// does nothing but delegate to this method. // does nothing but delegate to this method.
AbstractFuture<?> trusted = (AbstractFuture<?>) futureToPropagateTo; AbstractFuture<?> trusted = (AbstractFuture<?>) futureToPropagateTo;
localValue = trusted.value; localValue = trusted.value;
if (localValue == null | localValue instanceof AbstractFuture.SetFuture) { if (localValue == null | localValue instanceof SetFuture) {
abstractFuture = trusted; abstractFuture = trusted;
continue; // loop back up and try to complete the new future continue; // loop back up and try to complete the new future
} }
Expand All @@ -579,7 +578,7 @@ public boolean cancel(boolean mayInterruptIfRunning) {
} }
// obj changed, reread // obj changed, reread
localValue = abstractFuture.value; localValue = abstractFuture.value;
if (!(localValue instanceof AbstractFuture.SetFuture)) { if (!(localValue instanceof SetFuture)) {
// obj cannot be null at this point, because value can only change from null to non-null. // obj cannot be null at this point, because value can only change from null to non-null.
// So if value changed (and it did since we lost the CAS), then it cannot be null and // So if value changed (and it did since we lost the CAS), then it cannot be null and
// since it isn't a SetFuture, then the future must be done and we should exit the loop // since it isn't a SetFuture, then the future must be done and we should exit the loop
Expand Down Expand Up @@ -794,8 +793,8 @@ private static void complete(AbstractFuture<?> future) {
Listener curr = next; Listener curr = next;
next = next.next; next = next.next;
Runnable task = curr.task; Runnable task = curr.task;
if (task instanceof AbstractFuture.SetFuture) { if (task instanceof SetFuture) {
AbstractFuture.SetFuture<?> setFuture = (AbstractFuture.SetFuture) task; SetFuture<?> setFuture = (SetFuture<?>) task;
// We unwind setFuture specifically to avoid StackOverflowErrors in the case of long // We unwind setFuture specifically to avoid StackOverflowErrors in the case of long
// chains of SetFutures // chains of SetFutures
// Handling this special case is important because there is no way to pass an executor to // Handling this special case is important because there is no way to pass an executor to
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static <V> ListenableFuture<V> create(
TimeUnit unit, TimeUnit unit,
ScheduledExecutorService scheduledExecutor) { ScheduledExecutorService scheduledExecutor) {
TimeoutFuture<V> result = new TimeoutFuture<V>(delegate); TimeoutFuture<V> result = new TimeoutFuture<V>(delegate);
TimeoutFuture.Fire<V> fire = new TimeoutFuture.Fire<V>(result); Fire<V> fire = new Fire<V>(result);
result.timer = scheduledExecutor.schedule(fire, time, unit); result.timer = scheduledExecutor.schedule(fire, time, unit);
delegate.addListener(fire, directExecutor()); delegate.addListener(fire, directExecutor());
return result; return result;
Expand Down

0 comments on commit 34891e6

Please sign in to comment.