package o;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Ve, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0549Ve implements SP {
    public final C1164f5 l;
    public Throwable n;
    public final Object m = new Object();

    /* renamed from: o, reason: collision with root package name */
    public final P9 f380o = new P9(0);
    public UQ p = new UQ();
    public UQ q = new UQ();

    public C0549Ve(C1164f5 c1164f5) {
        this.l = c1164f5;
    }

    @Override // o.InterfaceC2747vn
    public final InterfaceC2747vn M(InterfaceC2747vn interfaceC2747vn) {
        return AbstractC2798wI.t(this, interfaceC2747vn);
    }

    @Override // o.InterfaceC2747vn
    public final Object R(Object obj, SC sc) {
        return sc.f(obj, this);
    }

    public final void a(long j) {
        int i;
        C2448sg c2448sg;
        Object h20;
        synchronized (this.m) {
            try {
                UQ uq = this.p;
                this.p = this.q;
                this.q = uq;
                P9 p9 = this.f380o;
                do {
                    i = p9.get();
                } while (!p9.compareAndSet(i, ((((i >>> 27) & 15) + 1) & 15) << 27));
                int i2 = uq.b;
                for (int i3 = 0; i3 < i2; i3++) {
                    C0497Te c0497Te = (C0497Te) uq.e(i3);
                    OC oc = c0497Te.a;
                    if (oc != null && (c2448sg = c0497Te.b) != null) {
                        try {
                            h20 = oc.g(Long.valueOf(j));
                        } catch (Throwable th) {
                            h20 = new H20(th);
                        }
                        c2448sg.resumeWith(h20);
                    }
                }
                uq.c();
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    @Override // o.InterfaceC2747vn
    public final InterfaceC2747vn l(InterfaceC2652un interfaceC2652un) {
        return IJ.y(this, interfaceC2652un);
    }

    @Override // o.InterfaceC2747vn
    public final InterfaceC2557tn m(InterfaceC2652un interfaceC2652un) {
        return IJ.m(this, interfaceC2652un);
    }

    @Override // o.SP
    public final Object w(OC oc, InterfaceC0220Im interfaceC0220Im) {
        int i;
        int i2;
        int i3;
        C2448sg c2448sg = new C2448sg(1, AbstractC2539te.G(interfaceC0220Im));
        c2448sg.r();
        C0497Te c0497Te = new C0497Te();
        c0497Te.a = oc;
        c0497Te.b = c2448sg;
        C3058z10 c3058z10 = new C3058z10();
        c3058z10.l = -1;
        synchronized (this.m) {
            Throwable th = this.n;
            if (th != null) {
                c2448sg.resumeWith(new H20(th));
            } else {
                P9 p9 = this.f380o;
                do {
                    i = p9.get();
                    i2 = i + 1;
                } while (!p9.compareAndSet(i, i2));
                boolean z = (134217727 & i2) == 1;
                c3058z10.l = (i2 >>> 27) & 15;
                this.p.a(c0497Te);
                c2448sg.w(new C0523Ue(c0497Te, this, c3058z10));
                if (z) {
                    try {
                        this.l.a();
                    } catch (Throwable th2) {
                        synchronized (this.m) {
                            try {
                                if (this.n == null) {
                                    this.n = th2;
                                    UQ uq = this.p;
                                    Object[] objArr = uq.a;
                                    int i4 = uq.b;
                                    for (int i5 = 0; i5 < i4; i5++) {
                                        C2448sg c2448sg2 = ((C0497Te) objArr[i5]).b;
                                        if (c2448sg2 != null) {
                                            c2448sg2.resumeWith(new H20(th2));
                                        }
                                    }
                                    this.p.c();
                                    P9 p92 = this.f380o;
                                    do {
                                        i3 = p92.get();
                                    } while (!p92.compareAndSet(i3, ((((i3 >>> 27) & 15) + 1) & 15) << 27));
                                }
                            } catch (Throwable th3) {
                                throw th3;
                            }
                        }
                    }
                }
            }
        }
        return c2448sg.q();
    }
}
