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;

/* JADX INFO: renamed from: ᵣːʓˆ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC3353 implements ListenableFuture {

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public static final Object f12866;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public static final boolean f12867 = Boolean.parseBoolean(System.getProperty("guava.concurrent.generate_cancellation_cause", "false"));

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public static final Logger f12868 = Logger.getLogger(AbstractC3353.class.getName());

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public static final ᵥˈᵛ f12869;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public volatile Object f12870;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public volatile C4651 f12871;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public volatile C2046 f12872;

    static {
        ᵥˈᵛ c3775;
        try {
            c3775 = new C1391(AtomicReferenceFieldUpdater.newUpdater(C4651.class, Thread.class, "ᵲᵶᵳˈ"), AtomicReferenceFieldUpdater.newUpdater(C4651.class, C4651.class, "ʽˈˋ"), AtomicReferenceFieldUpdater.newUpdater(AbstractC3353.class, C4651.class, "ᵔᵖᵹᵫ"), AtomicReferenceFieldUpdater.newUpdater(AbstractC3353.class, C2046.class, "ᵜᵪʾ"), AtomicReferenceFieldUpdater.newUpdater(AbstractC3353.class, Object.class, "ˌᴵ"));
            th = null;
        } catch (Throwable th) {
            th = th;
            c3775 = new C3775();
        }
        f12869 = c3775;
        if (th != null) {
            f12868.log(Level.SEVERE, "SafeAtomicHelper is broken!", th);
        }
        f12866 = new Object();
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public static Object m7698(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;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static void m7699(AbstractC3353 abstractC3353) {
        C4651 c4651;
        C2046 c2046;
        C2046 c20462;
        C2046 c20463;
        do {
            c4651 = abstractC3353.f12871;
        } while (!f12869.ˋˈ(abstractC3353, c4651, C4651.f17663));
        while (true) {
            c2046 = null;
            if (c4651 == null) {
                break;
            }
            Thread thread = c4651.f17665;
            if (thread != null) {
                c4651.f17665 = null;
                LockSupport.unpark(thread);
            }
            c4651 = c4651.f17664;
        }
        abstractC3353.mo6302();
        do {
            c20462 = abstractC3353.f12872;
        } while (!f12869.ᵮᵣᵗˈ(abstractC3353, c20462, C2046.f8125));
        while (true) {
            c20463 = c2046;
            c2046 = c20462;
            if (c2046 == null) {
                break;
            }
            c20462 = c2046.f8127;
            c2046.f8127 = c20463;
        }
        while (c20463 != null) {
            C2046 c20464 = c20463.f8127;
            m7701(c20463.f8128, c20463.f8126);
            c20463 = c20464;
        }
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public static Object m7700(Object obj) throws ExecutionException {
        if (obj instanceof C3153) {
            Throwable th = ((C3153) obj).f12005;
            CancellationException cancellationException = new CancellationException("Task was cancelled.");
            cancellationException.initCause(th);
            throw cancellationException;
        }
        if (obj instanceof C1458) {
            throw new ExecutionException(((C1458) obj).f5925);
        }
        if (obj == f12866) {
            return null;
        }
        return obj;
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public static void m7701(Runnable runnable, Executor executor) {
        try {
            executor.execute(runnable);
        } catch (RuntimeException e) {
            f12868.log(Level.SEVERE, "RuntimeException while executing runnable " + runnable + " with executor " + executor, (Throwable) e);
        }
    }

    @Override // java.util.concurrent.Future
    public final boolean cancel(boolean z) {
        Object obj = this.f12870;
        if (obj == null) {
            if (f12869.ᵝᵶ(this, obj, f12867 ? new C3153(new CancellationException("Future.cancel() was called."), z) : z ? C3153.f12003 : C3153.f12004)) {
                m7699(this);
                return true;
            }
        }
        return false;
    }

    @Override // java.util.concurrent.Future
    public final Object get() throws InterruptedException {
        Object obj;
        C4651 c4651 = C4651.f17663;
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Object obj2 = this.f12870;
        if (obj2 != null) {
            return m7700(obj2);
        }
        C4651 c46512 = this.f12871;
        if (c46512 != c4651) {
            C4651 c46513 = new C4651();
            do {
                ᵥˈᵛ r3 = f12869;
                r3.ʽᵡᵢᵾ(c46513, c46512);
                if (r3.ˋˈ(this, c46512, c46513)) {
                    do {
                        LockSupport.park(this);
                        if (Thread.interrupted()) {
                            m7704(c46513);
                            throw new InterruptedException();
                        }
                        obj = this.f12870;
                    } while (obj == null);
                    return m7700(obj);
                }
                c46512 = this.f12871;
            } while (c46512 != c4651);
        }
        return m7700(this.f12870);
    }

    @Override // java.util.concurrent.Future
    public final Object get(long j, TimeUnit timeUnit) throws InterruptedException, TimeoutException {
        C4651 c4651 = C4651.f17663;
        long nanos = timeUnit.toNanos(j);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Object obj = this.f12870;
        if (obj != null) {
            return m7700(obj);
        }
        long jNanoTime = nanos > 0 ? System.nanoTime() + nanos : 0L;
        if (nanos >= 1000) {
            C4651 c46512 = this.f12871;
            if (c46512 != c4651) {
                C4651 c46513 = new C4651();
                do {
                    ᵥˈᵛ r15 = f12869;
                    r15.ʽᵡᵢᵾ(c46513, c46512);
                    if (r15.ˋˈ(this, c46512, c46513)) {
                        while (true) {
                            LockSupport.parkNanos(this, nanos);
                            if (Thread.interrupted()) {
                                m7704(c46513);
                                throw new InterruptedException();
                            }
                            Object obj2 = this.f12870;
                            if (obj2 != null) {
                                return m7700(obj2);
                            }
                            long jNanoTime2 = jNanoTime - System.nanoTime();
                            if (jNanoTime2 < 1000) {
                                m7704(c46513);
                                nanos = jNanoTime2;
                                break;
                            }
                            nanos = jNanoTime2;
                        }
                    } else {
                        c46512 = this.f12871;
                    }
                } while (c46512 != c4651);
            }
            return m7700(this.f12870);
        }
        while (nanos > 0) {
            Object obj3 = this.f12870;
            if (obj3 != null) {
                return m7700(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 sbM8220 = AbstractC3653.m8220(j, "Waited ", " ");
        sbM8220.append(timeUnit.toString().toLowerCase(locale));
        String string3 = sbM8220.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(AbstractC3653.m8223(string3, " for ", string));
    }

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

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

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

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final void m7702(StringBuilder sb) {
        try {
            Object objM7698 = m7698(this);
            sb.append("SUCCESS, result=[");
            sb.append(objM7698 == this ? "this future" : String.valueOf(objM7698));
            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 INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public boolean mo7703(Throwable th) {
        th.getClass();
        if (!f12869.ᵝᵶ(this, (Object) null, new C1458(th))) {
            return false;
        }
        m7699(this);
        return true;
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final void m7704(C4651 c4651) {
        c4651.f17665 = null;
        while (true) {
            C4651 c46512 = this.f12871;
            if (c46512 == C4651.f17663) {
                return;
            }
            C4651 c46513 = null;
            while (c46512 != null) {
                C4651 c46514 = c46512.f17664;
                if (c46512.f17665 != null) {
                    c46513 = c46512;
                } else if (c46513 != null) {
                    c46513.f17664 = c46514;
                    if (c46513.f17665 == null) {
                        break;
                    }
                } else if (!f12869.ˋˈ(this, c46512, c46514)) {
                    break;
                }
                c46512 = c46514;
            }
            return;
        }
    }

    @Override // com.google.common.util.concurrent.ListenableFuture
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final void mo834(Runnable runnable, Executor executor) {
        executor.getClass();
        C2046 c2046 = this.f12872;
        C2046 c20462 = C2046.f8125;
        if (c2046 != c20462) {
            C2046 c20463 = new C2046(runnable, executor);
            do {
                c20463.f8127 = c2046;
                if (f12869.ᵮᵣᵗˈ(this, c2046, c20463)) {
                    return;
                } else {
                    c2046 = this.f12872;
                }
            } while (c2046 != c20462);
        }
        m7701(runnable, executor);
    }

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public boolean m7705(Object obj) {
        if (obj == null) {
            obj = f12866;
        }
        if (!f12869.ᵝᵶ(this, (Object) null, obj)) {
            return false;
        }
        m7699(this);
        return true;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    public void mo6302() {
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public String mo7706() {
        if (!(this instanceof ScheduledFuture)) {
            return null;
        }
        return "remaining delay=[" + ((ScheduledFuture) this).getDelay(TimeUnit.MILLISECONDS) + " ms]";
    }
}
