package kotlin.coroutines; import androidx.concurrent.futures.AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import kotlin.Result; import kotlin.coroutines.intrinsics.CoroutineSingletons; import kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsKt; import kotlin.coroutines.jvm.internal.CoroutineStackFrame; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; /* loaded from: classes5.dex */ public final class SafeContinuation implements Continuation, CoroutineStackFrame { public static final Companion Companion = new Companion(null); public static final AtomicReferenceFieldUpdater RESULT = AtomicReferenceFieldUpdater.newUpdater(SafeContinuation.class, Object.class, "result"); public final Continuation delegate; private volatile Object result; public SafeContinuation(Continuation delegate, Object obj) { Intrinsics.checkNotNullParameter(delegate, "delegate"); this.delegate = delegate; this.result = obj; } /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */ public SafeContinuation(Continuation delegate) { this(delegate, CoroutineSingletons.UNDECIDED); Intrinsics.checkNotNullParameter(delegate, "delegate"); } @Override // kotlin.coroutines.Continuation public CoroutineContext getContext() { return this.delegate.getContext(); } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public Companion() { } } @Override // kotlin.coroutines.Continuation public void resumeWith(Object obj) { Object coroutine_suspended; Object coroutine_suspended2; while (true) { Object obj2 = this.result; CoroutineSingletons coroutineSingletons = CoroutineSingletons.UNDECIDED; if (obj2 != coroutineSingletons) { coroutine_suspended = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); if (obj2 != coroutine_suspended) { throw new IllegalStateException("Already resumed"); } AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = RESULT; coroutine_suspended2 = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); if (AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0.m(atomicReferenceFieldUpdater, this, coroutine_suspended2, CoroutineSingletons.RESUMED)) { this.delegate.resumeWith(obj); return; } } else if (AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0.m(RESULT, this, coroutineSingletons, obj)) { return; } } } public final Object getOrThrow() { Object coroutine_suspended; Object coroutine_suspended2; Object coroutine_suspended3; Object obj = this.result; CoroutineSingletons coroutineSingletons = CoroutineSingletons.UNDECIDED; if (obj == coroutineSingletons) { AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = RESULT; coroutine_suspended2 = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); if (AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0.m(atomicReferenceFieldUpdater, this, coroutineSingletons, coroutine_suspended2)) { coroutine_suspended3 = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); return coroutine_suspended3; } obj = this.result; } if (obj == CoroutineSingletons.RESUMED) { coroutine_suspended = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); return coroutine_suspended; } if (obj instanceof Result.Failure) { throw ((Result.Failure) obj).exception; } return obj; } @Override // kotlin.coroutines.jvm.internal.CoroutineStackFrame public CoroutineStackFrame getCallerFrame() { Continuation continuation = this.delegate; if (continuation instanceof CoroutineStackFrame) { return (CoroutineStackFrame) continuation; } return null; } public String toString() { return "SafeContinuation for " + this.delegate; } }