package defpackage;

import com.google.common.util.concurrent.ListenableFuture;
import java.util.Locale;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.concurrent.locks.LockSupport;
import java.util.logging.Level;
import java.util.logging.Logger;

/* renamed from: ᵖⁱʣʘ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public abstract class AbstractC2414 implements ListenableFuture {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public static final Object f9409;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public static final ʼٴ f9410;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public volatile C0329 f9413;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public volatile Object f9414;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public volatile C3398 f9415;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public static final boolean f9412 = Boolean.parseBoolean(System.getProperty("guava.concurrent.generate_cancellation_cause", "false"));

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public static final Logger f9411 = Logger.getLogger(AbstractC2414.class.getName());

    static {
        ʼٴ c0785;
        try {
            c0785 = new C1147(AtomicReferenceFieldUpdater.newUpdater(C3398.class, Thread.class, "ᵥᵯˎ"), AtomicReferenceFieldUpdater.newUpdater(C3398.class, C3398.class, "ᵴᵳ"), AtomicReferenceFieldUpdater.newUpdater(AbstractC2414.class, C3398.class, "ᵿʗᵝʽ"), AtomicReferenceFieldUpdater.newUpdater(AbstractC2414.class, C0329.class, "ᵢˇᵭ"), AtomicReferenceFieldUpdater.newUpdater(AbstractC2414.class, Object.class, "ᵧᵾˀˈ"));
            th = null;
        } catch (Throwable th) {
            th = th;
            c0785 = new C0785();
        }
        f9410 = c0785;
        if (th != null) {
            f9411.log(Level.SEVERE, "SafeAtomicHelper is broken!", th);
        }
        f9409 = new Object();
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public static void m6175(AbstractC2414 abstractC2414) {
        C3398 c3398;
        C0329 c0329;
        C0329 c03292;
        C0329 c03293;
        do {
            c3398 = abstractC2414.f9415;
        } while (!f9410.ᵹᵝᵶ(abstractC2414, c3398, C3398.f12671));
        while (true) {
            c0329 = null;
            if (c3398 == null) {
                break;
            }
            Thread thread = c3398.f12672;
            if (thread != null) {
                c3398.f12672 = null;
                LockSupport.unpark(thread);
            }
            c3398 = c3398.f12673;
        }
        abstractC2414.mo4328();
        do {
            c03292 = abstractC2414.f9413;
        } while (!f9410.ˏˋٴ(abstractC2414, c03292, C0329.f2022));
        while (true) {
            c03293 = c0329;
            c0329 = c03292;
            if (c0329 == null) {
                break;
            }
            c03292 = c0329.f2023;
            c0329.f2023 = c03293;
        }
        while (c03293 != null) {
            C0329 c03294 = c03293.f2023;
            m6177(c03293.f2024, c03293.f2025);
            c03293 = c03294;
        }
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public static Object m6176(Object obj) throws ExecutionException {
        if (obj instanceof C1143) {
            Throwable th = ((C1143) obj).f4896;
            CancellationException cancellationException = new CancellationException("Task was cancelled.");
            cancellationException.initCause(th);
            throw cancellationException;
        }
        if (obj instanceof C2163) {
            throw new ExecutionException(((C2163) obj).f8553);
        }
        if (obj == f9409) {
            return null;
        }
        return obj;
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public static void m6177(Runnable runnable, Executor executor) {
        try {
            executor.execute(runnable);
        } catch (RuntimeException e) {
            f9411.log(Level.SEVERE, "RuntimeException while executing runnable " + runnable + " with executor " + executor, (Throwable) e);
        }
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public static Object m6178(Future future) {
        Object obj;
        boolean z = false;
        while (true) {
            try {
                obj = future.get();
                break;
            } catch (InterruptedException unused) {
                z = true;
            } catch (Throwable th) {
                if (z) {
                    Thread.currentThread().interrupt();
                }
                throw th;
            }
        }
        if (z) {
            Thread.currentThread().interrupt();
        }
        return obj;
    }

    @Override // java.util.concurrent.Future
    public final boolean cancel(boolean z) {
        Object obj = this.f9414;
        if (obj == null) {
            if (f9410.ˎˏʜʾ(this, obj, f9412 ? new C1143(new CancellationException("Future.cancel() was called."), z) : z ? C1143.f4893 : C1143.f4894)) {
                m6175(this);
                return true;
            }
        }
        return false;
    }

    @Override // java.util.concurrent.Future
    public final Object get() throws InterruptedException {
        Object obj;
        C3398 c3398 = C3398.f12671;
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Object obj2 = this.f9414;
        if (obj2 != null) {
            return m6176(obj2);
        }
        C3398 c33982 = this.f9415;
        if (c33982 != c3398) {
            C3398 c33983 = new C3398();
            do {
                ʼٴ r3 = f9410;
                r3.ˌᵪ(c33983, c33982);
                if (r3.ᵹᵝᵶ(this, c33982, c33983)) {
                    do {
                        LockSupport.park(this);
                        if (Thread.interrupted()) {
                            m6180(c33983);
                            throw new InterruptedException();
                        }
                        obj = this.f9414;
                    } while (obj == null);
                    return m6176(obj);
                }
                c33982 = this.f9415;
            } while (c33982 != c3398);
        }
        return m6176(this.f9414);
    }

    @Override // java.util.concurrent.Future
    public final Object get(long j, TimeUnit timeUnit) throws InterruptedException, TimeoutException {
        C3398 c3398 = C3398.f12671;
        long nanos = timeUnit.toNanos(j);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Object obj = this.f9414;
        if (obj != null) {
            return m6176(obj);
        }
        long jNanoTime = nanos > 0 ? System.nanoTime() + nanos : 0L;
        if (nanos >= 1000) {
            C3398 c33982 = this.f9415;
            if (c33982 != c3398) {
                C3398 c33983 = new C3398();
                do {
                    ʼٴ r15 = f9410;
                    r15.ˌᵪ(c33983, c33982);
                    if (r15.ᵹᵝᵶ(this, c33982, c33983)) {
                        while (true) {
                            LockSupport.parkNanos(this, nanos);
                            if (Thread.interrupted()) {
                                m6180(c33983);
                                throw new InterruptedException();
                            }
                            Object obj2 = this.f9414;
                            if (obj2 != null) {
                                return m6176(obj2);
                            }
                            long jNanoTime2 = jNanoTime - System.nanoTime();
                            if (jNanoTime2 < 1000) {
                                m6180(c33983);
                                nanos = jNanoTime2;
                                break;
                            }
                            nanos = jNanoTime2;
                        }
                    } else {
                        c33982 = this.f9415;
                    }
                } while (c33982 != c3398);
            }
            return m6176(this.f9414);
        }
        while (nanos > 0) {
            Object obj3 = this.f9414;
            if (obj3 != null) {
                return m6176(obj3);
            }
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }
            nanos = jNanoTime - System.nanoTime();
        }
        String string = toString();
        String string2 = timeUnit.toString();
        Locale locale = Locale.ROOT;
        String lowerCase = string2.toLowerCase(locale);
        StringBuilder sbM4110 = AbstractC1327.m4110(j, "Waited ", " ");
        sbM4110.append(timeUnit.toString().toLowerCase(locale));
        String string3 = sbM4110.toString();
        if (nanos + 1000 < 0) {
            String strConcat = string3.concat(" (plus ");
            long j2 = -nanos;
            long jConvert = timeUnit.convert(j2, TimeUnit.NANOSECONDS);
            long nanos2 = j2 - timeUnit.toNanos(jConvert);
            boolean z = jConvert == 0 || nanos2 > 1000;
            if (jConvert > 0) {
                String strConcat2 = strConcat + jConvert + " " + lowerCase;
                if (z) {
                    strConcat2 = strConcat2.concat(",");
                }
                strConcat = strConcat2.concat(" ");
            }
            if (z) {
                strConcat = strConcat + nanos2 + " nanoseconds ";
            }
            string3 = strConcat.concat("delay)");
        }
        if (isDone()) {
            throw new TimeoutException(string3.concat(" but future completed as timeout expired"));
        }
        throw new TimeoutException(AbstractC1327.m4106(string3, " for ", string));
    }

    @Override // java.util.concurrent.Future
    public final boolean isCancelled() {
        return this.f9414 instanceof C1143;
    }

    @Override // java.util.concurrent.Future
    public final boolean isDone() {
        return this.f9414 != null;
    }

    public final String toString() {
        String strMo5923;
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString());
        sb.append("[status=");
        if (this.f9414 instanceof C1143) {
            sb.append("CANCELLED");
        } else if (isDone()) {
            m6179(sb);
        } else {
            try {
                strMo5923 = mo5923();
            } catch (RuntimeException e) {
                strMo5923 = "Exception thrown from implementation: " + e.getClass();
            }
            if (strMo5923 != null && !strMo5923.isEmpty()) {
                sb.append("PENDING, info=[");
                sb.append(strMo5923);
                sb.append("]");
            } else if (isDone()) {
                m6179(sb);
            } else {
                sb.append("PENDING");
            }
        }
        sb.append("]");
        return sb.toString();
    }

    /* renamed from: ˌᵜᵹᵩ */
    public boolean mo2504(Throwable th) {
        th.getClass();
        if (!f9410.ˎˏʜʾ(this, (Object) null, new C2163(th))) {
            return false;
        }
        m6175(this);
        return true;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final void m6179(StringBuilder sb) {
        try {
            Object objM6178 = m6178(this);
            sb.append("SUCCESS, result=[");
            sb.append(objM6178 == this ? "this future" : String.valueOf(objM6178));
            sb.append("]");
        } catch (CancellationException unused) {
            sb.append("CANCELLED");
        } catch (RuntimeException e) {
            sb.append("UNKNOWN, cause=[");
            sb.append(e.getClass());
            sb.append(" thrown from get()]");
        } catch (ExecutionException e2) {
            sb.append("FAILURE, cause=[");
            sb.append(e2.getCause());
            sb.append("]");
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* renamed from: ᵝᵵᵺ */
    public String mo5923() {
        if (!(this instanceof ScheduledFuture)) {
            return null;
        }
        return "remaining delay=[" + ((ScheduledFuture) this).getDelay(TimeUnit.MILLISECONDS) + " ms]";
    }

    @Override // com.google.common.util.concurrent.ListenableFuture
    /* renamed from: ᵥᵯˎ */
    public final void mo833(Runnable runnable, Executor executor) {
        executor.getClass();
        C0329 c0329 = this.f9413;
        C0329 c03292 = C0329.f2022;
        if (c0329 != c03292) {
            C0329 c03293 = new C0329(runnable, executor);
            do {
                c03293.f2023 = c0329;
                if (f9410.ˏˋٴ(this, c0329, c03293)) {
                    return;
                } else {
                    c0329 = this.f9413;
                }
            } while (c0329 != c03292);
        }
        m6177(runnable, executor);
    }

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final void m6180(C3398 c3398) {
        c3398.f12672 = null;
        while (true) {
            C3398 c33982 = this.f9415;
            if (c33982 == C3398.f12671) {
                return;
            }
            C3398 c33983 = null;
            while (c33982 != null) {
                C3398 c33984 = c33982.f12673;
                if (c33982.f12672 != null) {
                    c33983 = c33982;
                } else if (c33983 != null) {
                    c33983.f12673 = c33984;
                    if (c33983.f12672 == null) {
                        break;
                    }
                } else if (!f9410.ᵹᵝᵶ(this, c33982, c33984)) {
                    break;
                }
                c33982 = c33984;
            }
            return;
        }
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public boolean m6181(Object obj) {
        if (obj == null) {
            obj = f9409;
        }
        if (!f9410.ˎˏʜʾ(this, (Object) null, obj)) {
            return false;
        }
        m6175(this);
        return true;
    }

    /* renamed from: ᵻᵢﹳᵰ */
    public void mo4328() {
    }
}
