package e5;

import I2.C0317a;
import V4.C0772m;
import V4.E;
import a.AbstractC0872a;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import w4.C3137A;

/* JADX INFO: loaded from: classes3.dex */
public final class c extends h implements a {

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f16345h = AtomicReferenceFieldUpdater.newUpdater(c.class, Object.class, "owner$volatile");
    private volatile /* synthetic */ Object owner$volatile;

    public c(boolean z6) {
        super(1, z6 ? 1 : 0);
        this.owner$volatile = z6 ? null : d.f16346a;
    }

    public final boolean d() {
        return Math.max(h.f16353g.get(this), 0) == 0;
    }

    /* JADX WARN: Code restructure failed: missing block: B:10:0x0022, code lost:
    
        r2 = e5.c.f16345h;
        r3 = r0.f16344b;
        r2.set(r3, null);
        r2 = new c0.C1217r(1, r3, r0);
        r0 = r0.f16343a;
        r0.A(r1, r0.f8257c, new K.R0(r2, 4));
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object e(A4.d dVar) {
        boolean zF = f();
        C3137A c3137a = C3137A.f25453a;
        if (!zF) {
            C0772m c0772mR = E.r(AbstractC0872a.V(dVar));
            try {
                b bVar = new b(this, c0772mR);
                while (true) {
                    int andDecrement = h.f16353g.getAndDecrement(this);
                    if (andDecrement <= this.f16354a) {
                        if (andDecrement > 0) {
                            break;
                        }
                        if (b(bVar)) {
                            break;
                        }
                    }
                }
                Object objR = c0772mR.r();
                B4.a aVar = B4.a.f492a;
                if (objR != aVar) {
                    objR = c3137a;
                }
                if (objR == aVar) {
                    return objR;
                }
            } catch (Throwable th) {
                c0772mR.z();
                throw th;
            }
        }
        return c3137a;
    }

    public final boolean f() {
        int i6;
        char c6;
        while (true) {
            AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = h.f16353g;
            int i7 = atomicIntegerFieldUpdater.get(this);
            int i8 = this.f16354a;
            if (i7 > i8) {
                do {
                    i6 = atomicIntegerFieldUpdater.get(this);
                    if (i6 > i8) {
                    }
                } while (!atomicIntegerFieldUpdater.compareAndSet(this, i6, i8));
            } else {
                if (i7 <= 0) {
                    c6 = 1;
                    break;
                }
                if (atomicIntegerFieldUpdater.compareAndSet(this, i7, i7 - 1)) {
                    f16345h.set(this, null);
                    c6 = 0;
                    break;
                }
            }
        }
        if (c6 == 0) {
            return true;
        }
        if (c6 == 1) {
            return false;
        }
        if (c6 != 2) {
            throw new IllegalStateException("unexpected");
        }
        throw new IllegalStateException("This mutex is already locked by the specified owner: null".toString());
    }

    public final void g(Object obj) {
        while (d()) {
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f16345h;
            Object obj2 = atomicReferenceFieldUpdater.get(this);
            C0317a c0317a = d.f16346a;
            if (obj2 != c0317a) {
                if (obj2 == obj || obj == null) {
                    while (!atomicReferenceFieldUpdater.compareAndSet(this, obj2, c0317a)) {
                        if (atomicReferenceFieldUpdater.get(this) != obj2) {
                            break;
                        }
                    }
                    c();
                    return;
                }
                throw new IllegalStateException(("This mutex is locked by " + obj2 + ", but " + obj + " is expected").toString());
            }
        }
        throw new IllegalStateException("This mutex is not locked");
    }

    public final String toString() {
        return "Mutex@" + E.p(this) + "[isLocked=" + d() + ",owner=" + f16345h.get(this) + ']';
    }
}
