491 lines
17 KiB
Java
491 lines
17 KiB
Java
package s.a;
|
|
|
|
import c.d.b.a.a;
|
|
import d0.k;
|
|
import d0.w.g.c;
|
|
import java.util.Objects;
|
|
import java.util.concurrent.CancellationException;
|
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
|
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.functions.Function1;
|
|
import kotlinx.coroutines.CancellableContinuation;
|
|
import kotlinx.coroutines.CompletionHandlerException;
|
|
import kotlinx.coroutines.Job;
|
|
import s.a.a.f;
|
|
import s.a.a.g;
|
|
import s.a.a.s;
|
|
/* compiled from: CancellableContinuationImpl.kt */
|
|
public class j<T> extends i0<T> implements CancellableContinuation<T>, CoroutineStackFrame {
|
|
public static final AtomicIntegerFieldUpdater l = AtomicIntegerFieldUpdater.newUpdater(j.class, "_decision");
|
|
public static final AtomicReferenceFieldUpdater m = AtomicReferenceFieldUpdater.newUpdater(j.class, Object.class, "_state");
|
|
public volatile int _decision = 0;
|
|
public volatile Object _parentHandle = null;
|
|
public volatile Object _state = c.i;
|
|
public final CoroutineContext n;
|
|
public final Continuation<T> o;
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: kotlin.coroutines.Continuation<? super T> */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public j(Continuation<? super T> continuation, int i) {
|
|
super(i);
|
|
this.o = continuation;
|
|
this.n = continuation.getContext();
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r4v3, resolved type: java.util.concurrent.atomic.AtomicReferenceFieldUpdater */
|
|
/* JADX DEBUG: Multi-variable search result rejected for r2v4, resolved type: java.util.concurrent.atomic.AtomicReferenceFieldUpdater */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public final void A() {
|
|
Job job;
|
|
boolean v = v();
|
|
if (this.k == 2) {
|
|
Continuation<T> continuation = this.o;
|
|
Throwable th = null;
|
|
if (!(continuation instanceof f)) {
|
|
continuation = null;
|
|
}
|
|
f fVar = (f) continuation;
|
|
if (fVar != null) {
|
|
while (true) {
|
|
Object obj = fVar._reusableCancellableContinuation;
|
|
s sVar = g.b;
|
|
if (obj == sVar) {
|
|
if (f.l.compareAndSet(fVar, sVar, this)) {
|
|
break;
|
|
}
|
|
} else if (obj != null) {
|
|
if (!(obj instanceof Throwable)) {
|
|
throw new IllegalStateException(a.t("Inconsistent state ", obj).toString());
|
|
} else if (f.l.compareAndSet(fVar, obj, null)) {
|
|
th = (Throwable) obj;
|
|
} else {
|
|
throw new IllegalArgumentException("Failed requirement.".toString());
|
|
}
|
|
}
|
|
}
|
|
if (th != null) {
|
|
if (!v) {
|
|
j(th);
|
|
}
|
|
v = true;
|
|
}
|
|
}
|
|
}
|
|
if (!v && ((k0) this._parentHandle) == null && (job = (Job) this.o.getContext().get(Job.h)) != null) {
|
|
k0 x2 = c.q.a.k.a.x(job, true, false, new m(job, this), 2, null);
|
|
this._parentHandle = x2;
|
|
if (v() && !w()) {
|
|
x2.dispose();
|
|
this._parentHandle = k1.i;
|
|
}
|
|
}
|
|
}
|
|
|
|
public final s B(Object obj, Object obj2, Function1<? super Throwable, Unit> function1) {
|
|
Object obj3;
|
|
do {
|
|
obj3 = this._state;
|
|
if (obj3 instanceof l1) {
|
|
} else if (!(obj3 instanceof t) || obj2 == null || ((t) obj3).d != obj2) {
|
|
return null;
|
|
} else {
|
|
return k.a;
|
|
}
|
|
} while (!m.compareAndSet(this, obj3, z((l1) obj3, obj, this.k, function1, obj2)));
|
|
s();
|
|
return k.a;
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CancellableContinuation
|
|
public boolean a() {
|
|
return this._state instanceof l1;
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CancellableContinuation
|
|
public Object b(T t, Object obj) {
|
|
return B(t, obj, null);
|
|
}
|
|
|
|
@Override // s.a.i0
|
|
public void c(Object obj, Throwable th) {
|
|
while (true) {
|
|
Object obj2 = this._state;
|
|
if (obj2 instanceof l1) {
|
|
throw new IllegalStateException("Not completed".toString());
|
|
} else if (!(obj2 instanceof u)) {
|
|
if (obj2 instanceof t) {
|
|
t tVar = (t) obj2;
|
|
if (!(tVar.e != null)) {
|
|
if (m.compareAndSet(this, obj2, t.a(tVar, null, null, null, null, th, 15))) {
|
|
h hVar = tVar.b;
|
|
if (hVar != null) {
|
|
p(hVar, th);
|
|
}
|
|
Function1<Throwable, Unit> function1 = tVar.f2870c;
|
|
if (function1 != null) {
|
|
q(function1, th);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
} else {
|
|
throw new IllegalStateException("Must be called at most once".toString());
|
|
}
|
|
} else if (m.compareAndSet(this, obj2, new t(obj2, null, null, null, th, 14))) {
|
|
return;
|
|
}
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // s.a.i0
|
|
public final Continuation<T> d() {
|
|
return this.o;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r5v0, resolved type: java.util.concurrent.atomic.AtomicIntegerFieldUpdater */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // kotlinx.coroutines.CancellableContinuation
|
|
public void e(Function1<? super Throwable, Unit> function1) {
|
|
h y0Var = function1 instanceof h ? (h) function1 : new y0(function1);
|
|
while (true) {
|
|
Object obj = this._state;
|
|
if (!(obj instanceof c)) {
|
|
Throwable th = null;
|
|
if (!(obj instanceof h)) {
|
|
boolean z2 = obj instanceof u;
|
|
boolean z3 = true;
|
|
if (z2) {
|
|
u uVar = (u) obj;
|
|
Objects.requireNonNull(uVar);
|
|
if (!u.a.compareAndSet(uVar, 0, 1)) {
|
|
x(function1, obj);
|
|
throw null;
|
|
} else if (obj instanceof l) {
|
|
if (!z2) {
|
|
obj = null;
|
|
}
|
|
u uVar2 = (u) obj;
|
|
if (uVar2 != null) {
|
|
th = uVar2.b;
|
|
}
|
|
o(function1, th);
|
|
return;
|
|
} else {
|
|
return;
|
|
}
|
|
} else if (obj instanceof t) {
|
|
t tVar = (t) obj;
|
|
if (tVar.b != null) {
|
|
x(function1, obj);
|
|
throw null;
|
|
} else if (!(y0Var instanceof e)) {
|
|
Throwable th2 = tVar.e;
|
|
if (th2 == null) {
|
|
z3 = false;
|
|
}
|
|
if (z3) {
|
|
o(function1, th2);
|
|
return;
|
|
} else {
|
|
if (m.compareAndSet(this, obj, t.a(tVar, null, y0Var, null, null, null, 29))) {
|
|
return;
|
|
}
|
|
}
|
|
} else {
|
|
return;
|
|
}
|
|
} else if (!(y0Var instanceof e)) {
|
|
if (m.compareAndSet(this, obj, new t(obj, y0Var, null, null, null, 28))) {
|
|
return;
|
|
}
|
|
} else {
|
|
return;
|
|
}
|
|
} else {
|
|
x(function1, obj);
|
|
throw null;
|
|
}
|
|
} else if (m.compareAndSet(this, obj, y0Var)) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // s.a.i0
|
|
public Throwable f(Object obj) {
|
|
Throwable f = super.f(obj);
|
|
if (f != null) {
|
|
return f;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CancellableContinuation
|
|
public Object g(Throwable th) {
|
|
return B(new u(th, false, 2), null, null);
|
|
}
|
|
|
|
@Override // kotlin.coroutines.Continuation
|
|
public CoroutineContext getContext() {
|
|
return this.n;
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CancellableContinuation
|
|
public Object h(T t, Object obj, Function1<? super Throwable, Unit> function1) {
|
|
return B(t, null, function1);
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CancellableContinuation
|
|
public void i(z zVar, T t) {
|
|
Continuation<T> continuation = this.o;
|
|
if (!(continuation instanceof f)) {
|
|
continuation = null;
|
|
}
|
|
f fVar = (f) continuation;
|
|
y(t, (fVar != null ? fVar.p : null) == zVar ? 4 : this.k, null);
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CancellableContinuation
|
|
public boolean j(Throwable th) {
|
|
Object obj;
|
|
boolean z2;
|
|
do {
|
|
obj = this._state;
|
|
if (!(obj instanceof l1)) {
|
|
return false;
|
|
}
|
|
z2 = obj instanceof h;
|
|
} while (!m.compareAndSet(this, obj, new l(this, th, z2)));
|
|
if (!z2) {
|
|
obj = null;
|
|
}
|
|
h hVar = (h) obj;
|
|
if (hVar != null) {
|
|
p(hVar, th);
|
|
}
|
|
s();
|
|
t(this.k);
|
|
return true;
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CancellableContinuation
|
|
public void k(Object obj) {
|
|
t(this.k);
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: java.lang.Object */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // s.a.i0
|
|
public <T> T l(Object obj) {
|
|
return obj instanceof t ? (T) ((t) obj).a : obj;
|
|
}
|
|
|
|
@Override // s.a.i0
|
|
public Object n() {
|
|
return this._state;
|
|
}
|
|
|
|
public final void o(Function1<? super Throwable, Unit> function1, Throwable th) {
|
|
try {
|
|
function1.invoke(th);
|
|
} catch (Throwable th2) {
|
|
CoroutineContext coroutineContext = this.n;
|
|
c.q.a.k.a.w(coroutineContext, new CompletionHandlerException("Exception in invokeOnCancellation handler for " + this, th2));
|
|
}
|
|
}
|
|
|
|
public final void p(h hVar, Throwable th) {
|
|
try {
|
|
hVar.a(th);
|
|
} catch (Throwable th2) {
|
|
CoroutineContext coroutineContext = this.n;
|
|
c.q.a.k.a.w(coroutineContext, new CompletionHandlerException("Exception in invokeOnCancellation handler for " + this, th2));
|
|
}
|
|
}
|
|
|
|
public final void q(Function1<? super Throwable, Unit> function1, Throwable th) {
|
|
try {
|
|
function1.invoke(th);
|
|
} catch (Throwable th2) {
|
|
CoroutineContext coroutineContext = this.n;
|
|
c.q.a.k.a.w(coroutineContext, new CompletionHandlerException("Exception in resume onCancellation handler for " + this, th2));
|
|
}
|
|
}
|
|
|
|
public final void r() {
|
|
k0 k0Var = (k0) this._parentHandle;
|
|
if (k0Var != null) {
|
|
k0Var.dispose();
|
|
}
|
|
this._parentHandle = k1.i;
|
|
}
|
|
|
|
@Override // kotlin.coroutines.Continuation
|
|
public void resumeWith(Object obj) {
|
|
Throwable r0 = k.m80exceptionOrNullimpl(obj);
|
|
if (r0 != null) {
|
|
obj = new u(r0, false, 2);
|
|
}
|
|
y(obj, this.k, null);
|
|
}
|
|
|
|
public final void s() {
|
|
if (!w()) {
|
|
r();
|
|
}
|
|
}
|
|
|
|
public final void t(int i) {
|
|
boolean z2;
|
|
boolean z3;
|
|
while (true) {
|
|
int i2 = this._decision;
|
|
z2 = false;
|
|
if (i2 == 0) {
|
|
if (l.compareAndSet(this, 0, 2)) {
|
|
z3 = true;
|
|
break;
|
|
}
|
|
} else if (i2 == 1) {
|
|
z3 = false;
|
|
} else {
|
|
throw new IllegalStateException("Already resumed".toString());
|
|
}
|
|
}
|
|
if (!z3) {
|
|
Continuation<T> d = d();
|
|
if (i == 4) {
|
|
z2 = true;
|
|
}
|
|
if (z2 || !(d instanceof f) || c.q.a.k.a.B(i) != c.q.a.k.a.B(this.k)) {
|
|
c.q.a.k.a.L(this, d, z2);
|
|
return;
|
|
}
|
|
z zVar = ((f) d).p;
|
|
CoroutineContext context = d.getContext();
|
|
if (zVar.isDispatchNeeded(context)) {
|
|
zVar.dispatch(context, this);
|
|
return;
|
|
}
|
|
q1 q1Var = q1.b;
|
|
o0 a = q1.a();
|
|
if (a.N()) {
|
|
a.K(this);
|
|
return;
|
|
}
|
|
a.M(true);
|
|
try {
|
|
c.q.a.k.a.L(this, d(), true);
|
|
do {
|
|
} while (a.Q());
|
|
} catch (Throwable th) {
|
|
a.H(true);
|
|
throw th;
|
|
}
|
|
a.H(true);
|
|
}
|
|
}
|
|
|
|
@Override // java.lang.Object
|
|
public String toString() {
|
|
return "CancellableContinuation(" + c.q.a.k.a.c0(this.o) + "){" + this._state + "}@" + c.q.a.k.a.t(this);
|
|
}
|
|
|
|
public final Object u() {
|
|
boolean z2;
|
|
Job job;
|
|
A();
|
|
while (true) {
|
|
int i = this._decision;
|
|
z2 = false;
|
|
if (i == 0) {
|
|
if (l.compareAndSet(this, 0, 1)) {
|
|
z2 = true;
|
|
break;
|
|
}
|
|
} else if (i != 2) {
|
|
throw new IllegalStateException("Already suspended".toString());
|
|
}
|
|
}
|
|
if (z2) {
|
|
return c.getCOROUTINE_SUSPENDED();
|
|
}
|
|
Object obj = this._state;
|
|
if (obj instanceof u) {
|
|
throw ((u) obj).b;
|
|
} else if (!c.q.a.k.a.B(this.k) || (job = (Job) this.n.get(Job.h)) == null || job.a()) {
|
|
return l(obj);
|
|
} else {
|
|
CancellationException p = job.p();
|
|
c(obj, p);
|
|
throw p;
|
|
}
|
|
}
|
|
|
|
public boolean v() {
|
|
return !(this._state instanceof l1);
|
|
}
|
|
|
|
public final boolean w() {
|
|
Continuation<T> continuation = this.o;
|
|
if (!(continuation instanceof f)) {
|
|
return false;
|
|
}
|
|
Object obj = ((f) continuation)._reusableCancellableContinuation;
|
|
return obj != null && (!(obj instanceof j) || obj == this);
|
|
}
|
|
|
|
public final void x(Function1<? super Throwable, Unit> function1, Object obj) {
|
|
throw new IllegalStateException(("It's prohibited to register multiple handlers, tried to register " + function1 + ", already has " + obj).toString());
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r10v4, resolved type: java.util.concurrent.atomic.AtomicIntegerFieldUpdater */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public final void y(Object obj, int i, Function1<? super Throwable, Unit> function1) {
|
|
Object obj2;
|
|
do {
|
|
obj2 = this._state;
|
|
if (obj2 instanceof l1) {
|
|
} else {
|
|
if (obj2 instanceof l) {
|
|
l lVar = (l) obj2;
|
|
Objects.requireNonNull(lVar);
|
|
if (l.f2869c.compareAndSet(lVar, 0, 1)) {
|
|
if (function1 != null) {
|
|
q(function1, lVar.b);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
throw new IllegalStateException(a.t("Already resumed, but proposed with update ", obj).toString());
|
|
}
|
|
} while (!m.compareAndSet(this, obj2, z((l1) obj2, obj, i, function1, null)));
|
|
s();
|
|
t(i);
|
|
}
|
|
|
|
public final Object z(l1 l1Var, Object obj, int i, Function1<? super Throwable, Unit> function1, Object obj2) {
|
|
if (obj instanceof u) {
|
|
return obj;
|
|
}
|
|
if (!c.q.a.k.a.B(i) && obj2 == null) {
|
|
return obj;
|
|
}
|
|
if (function1 == null && ((!(l1Var instanceof h) || (l1Var instanceof e)) && obj2 == null)) {
|
|
return obj;
|
|
}
|
|
if (!(l1Var instanceof h)) {
|
|
l1Var = null;
|
|
}
|
|
return new t(obj, (h) l1Var, function1, obj2, null, 16);
|
|
}
|
|
}
|