discord-jadx/app/src/main/java/s/a/k.java

491 lines
17 KiB
Java

package s.a;
import c.d.b.a.a;
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.CoroutineDispatcher;
import kotlinx.coroutines.Job;
import s.a.a.g;
import s.a.a.h;
import s.a.a.t;
/* compiled from: CancellableContinuationImpl.kt */
public class k<T> extends i0<T> implements CancellableContinuation<T>, CoroutineStackFrame {
public static final AtomicIntegerFieldUpdater l = AtomicIntegerFieldUpdater.newUpdater(k.class, "_decision");
public static final AtomicReferenceFieldUpdater m = AtomicReferenceFieldUpdater.newUpdater(k.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 k(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 g)) {
continuation = null;
}
g gVar = (g) continuation;
if (gVar != null) {
while (true) {
Object obj = gVar._reusableCancellableContinuation;
t tVar = h.b;
if (obj == tVar) {
if (g.l.compareAndSet(gVar, tVar, this)) {
break;
}
} else if (obj != null) {
if (!(obj instanceof Throwable)) {
throw new IllegalStateException(a.t("Inconsistent state ", obj).toString());
} else if (g.l.compareAndSet(gVar, obj, null)) {
th = (Throwable) obj;
} else {
throw new IllegalArgumentException("Failed requirement.".toString());
}
}
}
if (th != null) {
if (!v) {
j(th);
}
v = true;
}
}
}
if (!v && ((l0) this._parentHandle) == null && (job = (Job) this.o.getContext().get(Job.h)) != null) {
l0 y2 = c.q.a.k.a.y(job, true, false, new n(job, this), 2, null);
this._parentHandle = y2;
if (v() && !w()) {
y2.dispose();
this._parentHandle = m1.i;
}
}
}
public final t B(Object obj, Object obj2, Function1<? super Throwable, Unit> function1) {
Object obj3;
do {
obj3 = this._state;
if (obj3 instanceof n1) {
} else if (!(obj3 instanceof u) || obj2 == null || ((u) obj3).d != obj2) {
return null;
} else {
return l.a;
}
} while (!m.compareAndSet(this, obj3, z((n1) obj3, obj, this.k, function1, obj2)));
s();
return l.a;
}
@Override // kotlinx.coroutines.CancellableContinuation
public boolean a() {
return this._state instanceof n1;
}
@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 n1) {
throw new IllegalStateException("Not completed".toString());
} else if (!(obj2 instanceof v)) {
if (obj2 instanceof u) {
u uVar = (u) obj2;
if (!(uVar.e != null)) {
if (m.compareAndSet(this, obj2, u.a(uVar, null, null, null, null, th, 15))) {
i iVar = uVar.b;
if (iVar != null) {
p(iVar, th);
}
Function1<Throwable, Unit> function1 = uVar.f2873c;
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 u(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) {
i a1Var = function1 instanceof i ? (i) function1 : new a1(function1);
while (true) {
Object obj = this._state;
if (!(obj instanceof c)) {
Throwable th = null;
if (!(obj instanceof i)) {
boolean z2 = obj instanceof v;
boolean z3 = true;
if (z2) {
v vVar = (v) obj;
Objects.requireNonNull(vVar);
if (!v.a.compareAndSet(vVar, 0, 1)) {
x(function1, obj);
throw null;
} else if (obj instanceof m) {
if (!z2) {
obj = null;
}
v vVar2 = (v) obj;
if (vVar2 != null) {
th = vVar2.b;
}
o(function1, th);
return;
} else {
return;
}
} else if (obj instanceof u) {
u uVar = (u) obj;
if (uVar.b != null) {
x(function1, obj);
throw null;
} else if (!(a1Var instanceof e)) {
Throwable th2 = uVar.e;
if (th2 == null) {
z3 = false;
}
if (z3) {
o(function1, th2);
return;
} else {
if (m.compareAndSet(this, obj, u.a(uVar, null, a1Var, null, null, null, 29))) {
return;
}
}
} else {
return;
}
} else if (!(a1Var instanceof e)) {
if (m.compareAndSet(this, obj, new u(obj, a1Var, null, null, null, 28))) {
return;
}
} else {
return;
}
} else {
x(function1, obj);
throw null;
}
} else if (m.compareAndSet(this, obj, a1Var)) {
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 v(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(CoroutineDispatcher coroutineDispatcher, T t) {
Continuation<T> continuation = this.o;
if (!(continuation instanceof g)) {
continuation = null;
}
g gVar = (g) continuation;
y(t, (gVar != null ? gVar.p : null) == coroutineDispatcher ? 4 : this.k, null);
}
@Override // kotlinx.coroutines.CancellableContinuation
public boolean j(Throwable th) {
Object obj;
boolean z2;
do {
obj = this._state;
if (!(obj instanceof n1)) {
return false;
}
z2 = obj instanceof i;
} while (!m.compareAndSet(this, obj, new m(this, th, z2)));
if (!z2) {
obj = null;
}
i iVar = (i) obj;
if (iVar != null) {
p(iVar, 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 u ? (T) ((u) 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.x(coroutineContext, new CompletionHandlerException("Exception in invokeOnCancellation handler for " + this, th2));
}
}
public final void p(i iVar, Throwable th) {
try {
iVar.a(th);
} catch (Throwable th2) {
CoroutineContext coroutineContext = this.n;
c.q.a.k.a.x(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.x(coroutineContext, new CompletionHandlerException("Exception in resume onCancellation handler for " + this, th2));
}
}
public final void r() {
l0 l0Var = (l0) this._parentHandle;
if (l0Var != null) {
l0Var.dispose();
}
this._parentHandle = m1.i;
}
@Override // kotlin.coroutines.Continuation
public void resumeWith(Object obj) {
Throwable r0 = d0.k.m80exceptionOrNullimpl(obj);
if (r0 != null) {
obj = new v(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 g) || c.q.a.k.a.C(i) != c.q.a.k.a.C(this.k)) {
c.q.a.k.a.M(this, d, z2);
return;
}
CoroutineDispatcher coroutineDispatcher = ((g) d).p;
CoroutineContext context = d.getContext();
if (coroutineDispatcher.isDispatchNeeded(context)) {
coroutineDispatcher.dispatch(context, this);
return;
}
t1 t1Var = t1.b;
p0 a = t1.a();
if (a.N()) {
a.K(this);
return;
}
a.M(true);
try {
c.q.a.k.a.M(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.d0(this.o) + "){" + this._state + "}@" + c.q.a.k.a.u(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 v) {
throw ((v) obj).b;
} else if (!c.q.a.k.a.C(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 n1);
}
public final boolean w() {
Continuation<T> continuation = this.o;
if (!(continuation instanceof g)) {
return false;
}
Object obj = ((g) continuation)._reusableCancellableContinuation;
return obj != null && (!(obj instanceof k) || 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 n1) {
} else {
if (obj2 instanceof m) {
m mVar = (m) obj2;
Objects.requireNonNull(mVar);
if (m.f2872c.compareAndSet(mVar, 0, 1)) {
if (function1 != null) {
q(function1, mVar.b);
return;
}
return;
}
}
throw new IllegalStateException(a.t("Already resumed, but proposed with update ", obj).toString());
}
} while (!m.compareAndSet(this, obj2, z((n1) obj2, obj, i, function1, null)));
s();
t(i);
}
public final Object z(n1 n1Var, Object obj, int i, Function1<? super Throwable, Unit> function1, Object obj2) {
if (obj instanceof v) {
return obj;
}
if (!c.q.a.k.a.C(i) && obj2 == null) {
return obj;
}
if (function1 == null && ((!(n1Var instanceof i) || (n1Var instanceof e)) && obj2 == null)) {
return obj;
}
if (!(n1Var instanceof i)) {
n1Var = null;
}
return new u(obj, (i) n1Var, function1, obj2, null, 16);
}
}