package xp;

import java.util.Arrays;
import rm.n0;
import rm.x;
import wp.h0;

/* loaded from: classes3.dex */
public abstract class b {

    /* renamed from: p, reason: collision with root package name */
    private d[] f50954p;

    /* renamed from: q, reason: collision with root package name */
    private int f50955q;

    /* renamed from: r, reason: collision with root package name */
    private int f50956r;

    /* renamed from: s, reason: collision with root package name */
    private v f50957s;

    public static final /* synthetic */ int e(b bVar) {
        return bVar.f50955q;
    }

    public static final /* synthetic */ d[] f(b bVar) {
        return bVar.f50954p;
    }

    public final h0 g() {
        v vVar;
        synchronized (this) {
            vVar = this.f50957s;
            if (vVar == null) {
                vVar = new v(this.f50955q);
                this.f50957s = vVar;
            }
        }
        return vVar;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public final d h() {
        d dVar;
        v vVar;
        synchronized (this) {
            d[] dVarArr = this.f50954p;
            if (dVarArr == null) {
                dVarArr = j(2);
                this.f50954p = dVarArr;
            } else if (this.f50955q >= dVarArr.length) {
                Object[] copyOf = Arrays.copyOf(dVarArr, dVarArr.length * 2);
                kotlin.jvm.internal.t.f(copyOf, "copyOf(this, newSize)");
                this.f50954p = (d[]) copyOf;
                dVarArr = (d[]) copyOf;
            }
            int i10 = this.f50956r;
            do {
                dVar = dVarArr[i10];
                if (dVar == null) {
                    dVar = i();
                    dVarArr[i10] = dVar;
                }
                i10++;
                if (i10 >= dVarArr.length) {
                    i10 = 0;
                }
                kotlin.jvm.internal.t.e(dVar, "null cannot be cast to non-null type kotlinx.coroutines.flow.internal.AbstractSharedFlowSlot<kotlin.Any>");
            } while (!dVar.a(this));
            this.f50956r = i10;
            this.f50955q++;
            vVar = this.f50957s;
        }
        if (vVar != null) {
            vVar.Z(1);
        }
        return dVar;
    }

    protected abstract d i();

    protected abstract d[] j(int i10);

    /* JADX INFO: Access modifiers changed from: protected */
    public final void k(d dVar) {
        v vVar;
        int i10;
        vm.d[] b10;
        synchronized (this) {
            int i11 = this.f50955q - 1;
            this.f50955q = i11;
            vVar = this.f50957s;
            if (i11 == 0) {
                this.f50956r = 0;
            }
            kotlin.jvm.internal.t.e(dVar, "null cannot be cast to non-null type kotlinx.coroutines.flow.internal.AbstractSharedFlowSlot<kotlin.Any>");
            b10 = dVar.b(this);
        }
        for (vm.d dVar2 : b10) {
            if (dVar2 != null) {
                x.a aVar = x.f34910p;
                dVar2.resumeWith(x.a(n0.f34904a));
            }
        }
        if (vVar != null) {
            vVar.Z(-1);
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public final int l() {
        return this.f50955q;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public final d[] m() {
        return this.f50954p;
    }
}
