package androidx.compose.runtime;

import V4.C0772m;
import a.AbstractC0872a;
import w4.C3137A;

/* JADX INFO: loaded from: classes.dex */
final class ProduceFrameSignal {
    private Object pendingFrameContinuation;

    public final Object awaitFrameRequest(Object obj, A4.d dVar) {
        C0772m c0772m;
        synchronized (obj) {
            if (this.pendingFrameContinuation == RecomposerKt.ProduceAnotherFrame) {
                this.pendingFrameContinuation = RecomposerKt.FramePending;
                return C3137A.f25453a;
            }
            C0772m c0772m2 = new C0772m(1, AbstractC0872a.V(dVar));
            c0772m2.s();
            synchronized (obj) {
                try {
                    if (this.pendingFrameContinuation == RecomposerKt.ProduceAnotherFrame) {
                        this.pendingFrameContinuation = RecomposerKt.FramePending;
                        c0772m = c0772m2;
                    } else {
                        this.pendingFrameContinuation = c0772m2;
                        c0772m = null;
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
            if (c0772m != null) {
                c0772m.resumeWith(C3137A.f25453a);
            }
            Object objR = c0772m2.r();
            return objR == B4.a.f492a ? objR : C3137A.f25453a;
        }
    }

    public final A4.d requestFrameLocked() {
        Object obj = this.pendingFrameContinuation;
        if (obj instanceof A4.d) {
            this.pendingFrameContinuation = RecomposerKt.FramePending;
            return (A4.d) obj;
        }
        if (kotlin.jvm.internal.o.c(obj, RecomposerKt.ProduceAnotherFrame) || kotlin.jvm.internal.o.c(obj, RecomposerKt.FramePending)) {
            return null;
        }
        if (obj == null) {
            this.pendingFrameContinuation = RecomposerKt.ProduceAnotherFrame;
            return null;
        }
        throw new IllegalStateException(("invalid pendingFrameContinuation " + obj).toString());
    }

    public final void takeFrameRequestLocked() {
        if (!(this.pendingFrameContinuation == RecomposerKt.FramePending)) {
            PreconditionsKt.throwIllegalStateException("frame not pending");
        }
        this.pendingFrameContinuation = null;
    }
}
