package com.google.common.util.concurrent; import com.google.common.collect.Sets; import com.google.common.util.concurrent.AbstractFuture; import java.util.Set; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import java.util.logging.Level; import java.util.logging.Logger; /* loaded from: classes2.dex */ abstract class AggregateFutureState extends AbstractFuture.TrustedFuture { private static final AtomicHelper ATOMIC_HELPER; private static final Logger log = Logger.getLogger(AggregateFutureState.class.getName()); private volatile int remaining; private volatile Set seenExceptions = null; abstract void addInitialException(Set set); static /* synthetic */ int access$306(AggregateFutureState aggregateFutureState) { int i = aggregateFutureState.remaining - 1; aggregateFutureState.remaining = i; return i; } /* JADX WARN: Multi-variable type inference failed */ static { AtomicHelper synchronizedAtomicHelper; Throwable th = null; Object[] objArr = 0; try { synchronizedAtomicHelper = new SafeAtomicHelper(AtomicReferenceFieldUpdater.newUpdater(AggregateFutureState.class, Set.class, "seenExceptions"), AtomicIntegerFieldUpdater.newUpdater(AggregateFutureState.class, "remaining")); } catch (Throwable th2) { synchronizedAtomicHelper = new SynchronizedAtomicHelper(); th = th2; } ATOMIC_HELPER = synchronizedAtomicHelper; if (th != null) { log.log(Level.SEVERE, "SafeAtomicHelper is broken!", th); } } /* JADX INFO: Access modifiers changed from: package-private */ public AggregateFutureState(int i) { this.remaining = i; } /* JADX INFO: Access modifiers changed from: package-private */ public final Set getOrInitSeenExceptions() { Set set = this.seenExceptions; if (set != null) { return set; } Set newConcurrentHashSet = Sets.newConcurrentHashSet(); addInitialException(newConcurrentHashSet); ATOMIC_HELPER.compareAndSetSeenExceptions(this, null, newConcurrentHashSet); return this.seenExceptions; } /* JADX INFO: Access modifiers changed from: package-private */ public final int decrementRemainingAndGet() { return ATOMIC_HELPER.decrementAndGetRemainingCount(this); } /* loaded from: classes2.dex */ static abstract class AtomicHelper { abstract void compareAndSetSeenExceptions(AggregateFutureState aggregateFutureState, Set set, Set set2); abstract int decrementAndGetRemainingCount(AggregateFutureState aggregateFutureState); private AtomicHelper() { } } /* loaded from: classes2.dex */ static final class SafeAtomicHelper extends AtomicHelper { final AtomicIntegerFieldUpdater remainingCountUpdater; final AtomicReferenceFieldUpdater> seenExceptionsUpdater; SafeAtomicHelper(AtomicReferenceFieldUpdater atomicReferenceFieldUpdater, AtomicIntegerFieldUpdater atomicIntegerFieldUpdater) { super(); this.seenExceptionsUpdater = atomicReferenceFieldUpdater; this.remainingCountUpdater = atomicIntegerFieldUpdater; } @Override // com.google.common.util.concurrent.AggregateFutureState.AtomicHelper final int decrementAndGetRemainingCount(AggregateFutureState aggregateFutureState) { return this.remainingCountUpdater.decrementAndGet(aggregateFutureState); } @Override // com.google.common.util.concurrent.AggregateFutureState.AtomicHelper final void compareAndSetSeenExceptions(AggregateFutureState aggregateFutureState, Set set, Set set2) { AtomicReferenceFieldUpdater> atomicReferenceFieldUpdater = this.seenExceptionsUpdater; while (!atomicReferenceFieldUpdater.compareAndSet(aggregateFutureState, set, set2) && atomicReferenceFieldUpdater.get(aggregateFutureState) == set) { } } } /* loaded from: classes2.dex */ static final class SynchronizedAtomicHelper extends AtomicHelper { private SynchronizedAtomicHelper() { super(); } @Override // com.google.common.util.concurrent.AggregateFutureState.AtomicHelper final void compareAndSetSeenExceptions(AggregateFutureState aggregateFutureState, Set set, Set set2) { synchronized (aggregateFutureState) { if (aggregateFutureState.seenExceptions == set) { aggregateFutureState.seenExceptions = set2; } } } @Override // com.google.common.util.concurrent.AggregateFutureState.AtomicHelper final int decrementAndGetRemainingCount(AggregateFutureState aggregateFutureState) { int access$306; synchronized (aggregateFutureState) { access$306 = AggregateFutureState.access$306(aggregateFutureState); } return access$306; } } /* JADX INFO: Access modifiers changed from: package-private */ public final void clearSeenExceptions() { this.seenExceptions = null; } }