package kotlinx.coroutines.flow.internal;

import java.util.Arrays;
import kotlin.coroutines.Continuation;

/* JADX INFO: loaded from: classes.dex */
public abstract class a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public c[] f29381a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f29382b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f29383c;

    public final c d() {
        c cVarE;
        synchronized (this) {
            try {
                c[] cVarArrF = this.f29381a;
                if (cVarArrF == null) {
                    cVarArrF = f();
                    this.f29381a = cVarArrF;
                } else if (this.f29382b >= cVarArrF.length) {
                    Object[] objArrCopyOf = Arrays.copyOf(cVarArrF, cVarArrF.length * 2);
                    nb.g.h(objArrCopyOf, "copyOf(...)");
                    this.f29381a = (c[]) objArrCopyOf;
                    cVarArrF = (c[]) objArrCopyOf;
                }
                int i10 = this.f29383c;
                do {
                    cVarE = cVarArrF[i10];
                    if (cVarE == null) {
                        cVarE = e();
                        cVarArrF[i10] = cVarE;
                    }
                    i10++;
                    if (i10 >= cVarArrF.length) {
                        i10 = 0;
                    }
                    nb.g.g(cVarE, "null cannot be cast to non-null type kotlinx.coroutines.flow.internal.AbstractSharedFlowSlot<kotlin.Any>");
                } while (!cVarE.a(this));
                this.f29383c = i10;
                this.f29382b++;
            } catch (Throwable th) {
                throw th;
            }
        }
        return cVarE;
    }

    public abstract c e();

    public abstract c[] f();

    public final void g(c cVar) {
        int i10;
        Continuation[] continuationArrB;
        synchronized (this) {
            try {
                int i11 = this.f29382b - 1;
                this.f29382b = i11;
                if (i11 == 0) {
                    this.f29383c = 0;
                }
                nb.g.g(cVar, "null cannot be cast to non-null type kotlinx.coroutines.flow.internal.AbstractSharedFlowSlot<kotlin.Any>");
                continuationArrB = cVar.b(this);
            } catch (Throwable th) {
                throw th;
            }
        }
        for (Continuation continuation : continuationArrB) {
            if (continuation != null) {
                continuation.resumeWith(kd.e.f29109a);
            }
        }
    }
}
