- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
203 lines
9.0 KiB
Java
203 lines
9.0 KiB
Java
package kotlinx.coroutines.internal;
|
|
|
|
import androidx.concurrent.futures.AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0;
|
|
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
|
import kotlin.Unit;
|
|
import kotlin.coroutines.Continuation;
|
|
import kotlin.coroutines.CoroutineContext;
|
|
import kotlin.coroutines.jvm.internal.CoroutineStackFrame;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
import kotlinx.coroutines.CancellableContinuation;
|
|
import kotlinx.coroutines.CancellableContinuationImpl;
|
|
import kotlinx.coroutines.CompletedWithCancellation;
|
|
import kotlinx.coroutines.CompletionStateKt;
|
|
import kotlinx.coroutines.CoroutineDispatcher;
|
|
import kotlinx.coroutines.DebugStringsKt;
|
|
import kotlinx.coroutines.DispatchedTask;
|
|
import kotlinx.coroutines.EventLoop;
|
|
import kotlinx.coroutines.ThreadLocalEventLoop;
|
|
|
|
/* loaded from: classes5.dex */
|
|
public final class DispatchedContinuation extends DispatchedTask implements CoroutineStackFrame, Continuation {
|
|
public static final AtomicReferenceFieldUpdater _reusableCancellableContinuation$FU = AtomicReferenceFieldUpdater.newUpdater(DispatchedContinuation.class, Object.class, "_reusableCancellableContinuation");
|
|
private volatile Object _reusableCancellableContinuation;
|
|
public Object _state;
|
|
public final Continuation continuation;
|
|
public final Object countOrElement;
|
|
public final CoroutineDispatcher dispatcher;
|
|
|
|
@Override // kotlin.coroutines.Continuation
|
|
public CoroutineContext getContext() {
|
|
return this.continuation.getContext();
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.DispatchedTask
|
|
public Continuation getDelegate$kotlinx_coroutines_core() {
|
|
return this;
|
|
}
|
|
|
|
public DispatchedContinuation(CoroutineDispatcher coroutineDispatcher, Continuation continuation) {
|
|
super(-1);
|
|
Symbol symbol;
|
|
this.dispatcher = coroutineDispatcher;
|
|
this.continuation = continuation;
|
|
symbol = DispatchedContinuationKt.UNDEFINED;
|
|
this._state = symbol;
|
|
this.countOrElement = ThreadContextKt.threadContextElements(getContext());
|
|
}
|
|
|
|
@Override // kotlin.coroutines.jvm.internal.CoroutineStackFrame
|
|
public CoroutineStackFrame getCallerFrame() {
|
|
Continuation continuation = this.continuation;
|
|
if (continuation instanceof CoroutineStackFrame) {
|
|
return (CoroutineStackFrame) continuation;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public final CancellableContinuationImpl getReusableCancellableContinuation() {
|
|
Object obj = _reusableCancellableContinuation$FU.get(this);
|
|
if (obj instanceof CancellableContinuationImpl) {
|
|
return (CancellableContinuationImpl) obj;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public final boolean isReusable$kotlinx_coroutines_core() {
|
|
return _reusableCancellableContinuation$FU.get(this) != null;
|
|
}
|
|
|
|
public final void awaitReusability$kotlinx_coroutines_core() {
|
|
while (_reusableCancellableContinuation$FU.get(this) == DispatchedContinuationKt.REUSABLE_CLAIMED) {
|
|
}
|
|
}
|
|
|
|
public final void release$kotlinx_coroutines_core() {
|
|
awaitReusability$kotlinx_coroutines_core();
|
|
CancellableContinuationImpl reusableCancellableContinuation = getReusableCancellableContinuation();
|
|
if (reusableCancellableContinuation != null) {
|
|
reusableCancellableContinuation.detachChild$kotlinx_coroutines_core();
|
|
}
|
|
}
|
|
|
|
public final CancellableContinuationImpl claimReusableCancellableContinuation$kotlinx_coroutines_core() {
|
|
AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = _reusableCancellableContinuation$FU;
|
|
while (true) {
|
|
Object obj = atomicReferenceFieldUpdater.get(this);
|
|
if (obj == null) {
|
|
_reusableCancellableContinuation$FU.set(this, DispatchedContinuationKt.REUSABLE_CLAIMED);
|
|
return null;
|
|
}
|
|
if (obj instanceof CancellableContinuationImpl) {
|
|
if (AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0.m(_reusableCancellableContinuation$FU, this, obj, DispatchedContinuationKt.REUSABLE_CLAIMED)) {
|
|
return (CancellableContinuationImpl) obj;
|
|
}
|
|
} else if (obj != DispatchedContinuationKt.REUSABLE_CLAIMED && !(obj instanceof Throwable)) {
|
|
throw new IllegalStateException(("Inconsistent state " + obj).toString());
|
|
}
|
|
}
|
|
}
|
|
|
|
public final Throwable tryReleaseClaimedContinuation$kotlinx_coroutines_core(CancellableContinuation cancellableContinuation) {
|
|
Symbol symbol;
|
|
AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = _reusableCancellableContinuation$FU;
|
|
do {
|
|
Object obj = atomicReferenceFieldUpdater.get(this);
|
|
symbol = DispatchedContinuationKt.REUSABLE_CLAIMED;
|
|
if (obj != symbol) {
|
|
if (obj instanceof Throwable) {
|
|
if (!AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0.m(_reusableCancellableContinuation$FU, this, obj, null)) {
|
|
throw new IllegalArgumentException("Failed requirement.".toString());
|
|
}
|
|
return (Throwable) obj;
|
|
}
|
|
throw new IllegalStateException(("Inconsistent state " + obj).toString());
|
|
}
|
|
} while (!AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0.m(_reusableCancellableContinuation$FU, this, symbol, cancellableContinuation));
|
|
return null;
|
|
}
|
|
|
|
public final boolean postponeCancellation$kotlinx_coroutines_core(Throwable th) {
|
|
AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = _reusableCancellableContinuation$FU;
|
|
while (true) {
|
|
Object obj = atomicReferenceFieldUpdater.get(this);
|
|
Symbol symbol = DispatchedContinuationKt.REUSABLE_CLAIMED;
|
|
if (Intrinsics.areEqual(obj, symbol)) {
|
|
if (AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0.m(_reusableCancellableContinuation$FU, this, symbol, th)) {
|
|
return true;
|
|
}
|
|
} else {
|
|
if (obj instanceof Throwable) {
|
|
return true;
|
|
}
|
|
if (AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0.m(_reusableCancellableContinuation$FU, this, obj, null)) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.DispatchedTask
|
|
public Object takeState$kotlinx_coroutines_core() {
|
|
Symbol symbol;
|
|
Object obj = this._state;
|
|
symbol = DispatchedContinuationKt.UNDEFINED;
|
|
this._state = symbol;
|
|
return obj;
|
|
}
|
|
|
|
@Override // kotlin.coroutines.Continuation
|
|
public void resumeWith(Object obj) {
|
|
CoroutineContext context = this.continuation.getContext();
|
|
Object state$default = CompletionStateKt.toState$default(obj, null, 1, null);
|
|
if (this.dispatcher.isDispatchNeeded(context)) {
|
|
this._state = state$default;
|
|
this.resumeMode = 0;
|
|
this.dispatcher.mo4148dispatch(context, this);
|
|
return;
|
|
}
|
|
EventLoop eventLoop$kotlinx_coroutines_core = ThreadLocalEventLoop.INSTANCE.getEventLoop$kotlinx_coroutines_core();
|
|
if (!eventLoop$kotlinx_coroutines_core.isUnconfinedLoopActive()) {
|
|
eventLoop$kotlinx_coroutines_core.incrementUseCount(true);
|
|
try {
|
|
CoroutineContext context2 = getContext();
|
|
Object updateThreadContext = ThreadContextKt.updateThreadContext(context2, this.countOrElement);
|
|
try {
|
|
this.continuation.resumeWith(obj);
|
|
Unit unit = Unit.INSTANCE;
|
|
while (eventLoop$kotlinx_coroutines_core.processUnconfinedEvent()) {
|
|
}
|
|
} finally {
|
|
ThreadContextKt.restoreThreadContext(context2, updateThreadContext);
|
|
}
|
|
} finally {
|
|
try {
|
|
return;
|
|
} finally {
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
this._state = state$default;
|
|
this.resumeMode = 0;
|
|
eventLoop$kotlinx_coroutines_core.dispatchUnconfined(this);
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.DispatchedTask
|
|
public void cancelCompletedResult$kotlinx_coroutines_core(Object obj, Throwable th) {
|
|
if (obj instanceof CompletedWithCancellation) {
|
|
((CompletedWithCancellation) obj).onCancellation.invoke(th);
|
|
}
|
|
}
|
|
|
|
public final void dispatchYield$kotlinx_coroutines_core(CoroutineContext coroutineContext, Object obj) {
|
|
this._state = obj;
|
|
this.resumeMode = 1;
|
|
this.dispatcher.dispatchYield(coroutineContext, this);
|
|
}
|
|
|
|
public String toString() {
|
|
return "DispatchedContinuation[" + this.dispatcher + ", " + DebugStringsKt.toDebugString(this.continuation) + ']';
|
|
}
|
|
}
|