package kotlinx.coroutines.internal;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes3.dex */
@kotlinx.coroutines.InternalCoroutinesApi
@kotlin.Metadata(d1 = {"\u0000D\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0002\b\u0005\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u000b\n\u0002\u0010\u000e\n\u0002\b\n\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0017\u0018\u00002\u00020\u0001B\u0007¢\u0006\u0004\b\u0002\u0010\u0003J\u000f\u0010\u0005\u001a\u00020\u0004H\u0002¢\u0006\u0004\b\u0005\u0010\u0006J \u0010\t\u001a\u00060\u0000j\u0002`\u00072\n\u0010\b\u001a\u00060\u0000j\u0002`\u0007H\u0082\u0010¢\u0006\u0004\b\t\u0010\nJ\u001b\u0010\r\u001a\u00020\f2\n\u0010\u000b\u001a\u00060\u0000j\u0002`\u0007H\u0002¢\u0006\u0004\b\r\u0010\u000eJ\u0018\u0010\u000f\u001a\n\u0018\u00010\u0000j\u0004\u0018\u0001`\u0007H\u0082\u0010¢\u0006\u0004\b\u000f\u0010\u0010J\u0019\u0010\u0013\u001a\u00020\u00122\n\u0010\u0011\u001a\u00060\u0000j\u0002`\u0007¢\u0006\u0004\b\u0013\u0010\u0014J!\u0010\u0017\u001a\u00020\u00122\n\u0010\u0011\u001a\u00060\u0000j\u0002`\u00072\u0006\u0010\u0016\u001a\u00020\u0015¢\u0006\u0004\b\u0017\u0010\u0018J\u0015\u0010\u001a\u001a\u00020\f2\u0006\u0010\u0019\u001a\u00020\u0015¢\u0006\u0004\b\u001a\u0010\u001bJ'\u0010\u001c\u001a\u00020\u00122\n\u0010\u0011\u001a\u00060\u0000j\u0002`\u00072\n\u0010\u000b\u001a\u00060\u0000j\u0002`\u0007H\u0001¢\u0006\u0004\b\u001c\u0010\u001dJ\u000f\u0010\u001e\u001a\u00020\u0012H\u0016¢\u0006\u0004\b\u001e\u0010\u001fJ\u0017\u0010 \u001a\n\u0018\u00010\u0000j\u0004\u0018\u0001`\u0007H\u0001¢\u0006\u0004\b \u0010\u0010J\u000f\u0010\"\u001a\u00020!H\u0016¢\u0006\u0004\b\"\u0010#R\u0014\u0010%\u001a\u00020\u00128VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b$\u0010\u001fR\u0011\u0010\u000b\u001a\u00020\u00018F¢\u0006\u0006\u001a\u0004\b&\u0010'R\u0015\u0010)\u001a\u00060\u0000j\u0002`\u00078F¢\u0006\u0006\u001a\u0004\b(\u0010\u0010R\u0015\u0010+\u001a\u00060\u0000j\u0002`\u00078F¢\u0006\u0006\u001a\u0004\b*\u0010\u0010R\u0011\u0010-\u001a\b\u0012\u0004\u0012\u00020\u00010,8\u0002X\u0082\u0004R\u0011\u0010.\u001a\b\u0012\u0004\u0012\u00020\u00000,8\u0002X\u0082\u0004R\u0013\u0010/\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u00040,8\u0002X\u0082\u0004¨\u00060"}, d2 = {"Lkotlinx/coroutines/internal/LockFreeLinkedListNode;", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "<init>", "()V", "Lkotlinx/coroutines/internal/Removed;", "s", "()Lkotlinx/coroutines/internal/Removed;", "Lkotlinx/coroutines/internal/Node;", "current", "h", "(Lkotlinx/coroutines/internal/LockFreeLinkedListNode;)Lkotlinx/coroutines/internal/LockFreeLinkedListNode;", "next", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "i", "(Lkotlinx/coroutines/internal/LockFreeLinkedListNode;)V", "g", "()Lkotlinx/coroutines/internal/LockFreeLinkedListNode;", "node", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "e", "(Lkotlinx/coroutines/internal/LockFreeLinkedListNode;)Z", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "permissionsBitmask", "c", "(Lkotlinx/coroutines/internal/LockFreeLinkedListNode;I)Z", "forbiddenElementsBit", "f", "(I)V", "d", "(Lkotlinx/coroutines/internal/LockFreeLinkedListNode;Lkotlinx/coroutines/internal/LockFreeLinkedListNode;)Z", "q", "()Z", "r", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "toString", "()Ljava/lang/String;", "p", "isRemoved", "j", "()Ljava/lang/Object;", "k", "nextNode", "l", "prevNode", "Lkotlinx/atomicfu/AtomicRef;", "_next", "_prev", "_removedRef", "kotlinx-coroutines-core"}, k = 1, mv = {2, 1, 0}, xi = 48)
@kotlin.jvm.internal.SourceDebugExtension
public class LockFreeLinkedListNode {
    private static final /* synthetic */ java.util.concurrent.atomic.AtomicReferenceFieldUpdater a = java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(kotlinx.coroutines.internal.LockFreeLinkedListNode.class, java.lang.Object.class, "_next$volatile");
    private static final /* synthetic */ java.util.concurrent.atomic.AtomicReferenceFieldUpdater b = java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(kotlinx.coroutines.internal.LockFreeLinkedListNode.class, java.lang.Object.class, "_prev$volatile");
    private static final /* synthetic */ java.util.concurrent.atomic.AtomicReferenceFieldUpdater c = java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(kotlinx.coroutines.internal.LockFreeLinkedListNode.class, java.lang.Object.class, "_removedRef$volatile");
    private volatile /* synthetic */ java.lang.Object _next$volatile = this;
    private volatile /* synthetic */ java.lang.Object _prev$volatile = this;
    private volatile /* synthetic */ java.lang.Object _removedRef$volatile;

    private final kotlinx.coroutines.internal.LockFreeLinkedListNode g() {
        kotlinx.coroutines.internal.LockFreeLinkedListNode lockFreeLinkedListNode;
        java.lang.Object obj;
        while (true) {
            kotlinx.coroutines.internal.LockFreeLinkedListNode lockFreeLinkedListNode2 = (kotlinx.coroutines.internal.LockFreeLinkedListNode) b.get(this);
            lockFreeLinkedListNode = lockFreeLinkedListNode2;
            while (true) {
                kotlinx.coroutines.internal.LockFreeLinkedListNode lockFreeLinkedListNode3 = null;
                while (true) {
                    obj = a.get(lockFreeLinkedListNode);
                    if (obj == this) {
                        if (lockFreeLinkedListNode2 != lockFreeLinkedListNode && !androidx.concurrent.futures.a.a(b, this, lockFreeLinkedListNode2, lockFreeLinkedListNode)) {
                            break;
                        }
                        break;
                    }
                    if (p()) {
                        return null;
                    }
                    if (!(obj instanceof kotlinx.coroutines.internal.Removed)) {
                        kotlin.jvm.internal.Intrinsics.j(obj, "null cannot be cast to non-null type kotlinx.coroutines.internal.LockFreeLinkedListNode");
                        lockFreeLinkedListNode3 = lockFreeLinkedListNode;
                        lockFreeLinkedListNode = (kotlinx.coroutines.internal.LockFreeLinkedListNode) obj;
                    } else {
                        if (lockFreeLinkedListNode3 != null) {
                            break;
                        }
                        lockFreeLinkedListNode = (kotlinx.coroutines.internal.LockFreeLinkedListNode) b.get(lockFreeLinkedListNode);
                    }
                }
                if (!androidx.concurrent.futures.a.a(a, lockFreeLinkedListNode3, lockFreeLinkedListNode, ((kotlinx.coroutines.internal.Removed) obj).ref)) {
                    break;
                }
                lockFreeLinkedListNode = lockFreeLinkedListNode3;
            }
        }
        return lockFreeLinkedListNode;
    }

    private final kotlinx.coroutines.internal.LockFreeLinkedListNode h(kotlinx.coroutines.internal.LockFreeLinkedListNode current) {
        while (current.p()) {
            current = (kotlinx.coroutines.internal.LockFreeLinkedListNode) b.get(current);
        }
        return current;
    }

    private final void i(kotlinx.coroutines.internal.LockFreeLinkedListNode next) {
        kotlinx.coroutines.internal.LockFreeLinkedListNode lockFreeLinkedListNode;
        java.util.concurrent.atomic.AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = b;
        do {
            lockFreeLinkedListNode = (kotlinx.coroutines.internal.LockFreeLinkedListNode) atomicReferenceFieldUpdater.get(next);
            if (j() != next) {
                return;
            }
        } while (!androidx.concurrent.futures.a.a(b, next, lockFreeLinkedListNode, this));
        if (p()) {
            next.g();
        }
    }

    private final kotlinx.coroutines.internal.Removed s() {
        kotlinx.coroutines.internal.Removed removed = (kotlinx.coroutines.internal.Removed) c.get(this);
        if (removed != null) {
            return removed;
        }
        kotlinx.coroutines.internal.Removed removed2 = new kotlinx.coroutines.internal.Removed(this);
        c.set(this, removed2);
        return removed2;
    }

    public final boolean c(kotlinx.coroutines.internal.LockFreeLinkedListNode node, int permissionsBitmask) {
        kotlinx.coroutines.internal.LockFreeLinkedListNode lockFreeLinkedListNodeL;
        do {
            lockFreeLinkedListNodeL = l();
            if (lockFreeLinkedListNodeL instanceof kotlinx.coroutines.internal.ListClosed) {
                return (((kotlinx.coroutines.internal.ListClosed) lockFreeLinkedListNodeL).forbiddenElementsBitmask & permissionsBitmask) == 0 && lockFreeLinkedListNodeL.c(node, permissionsBitmask);
            }
        } while (!lockFreeLinkedListNodeL.d(node, this));
        return true;
    }

    public final boolean d(kotlinx.coroutines.internal.LockFreeLinkedListNode node, kotlinx.coroutines.internal.LockFreeLinkedListNode next) {
        b.set(node, this);
        a.set(node, next);
        if (!androidx.concurrent.futures.a.a(a, this, next, node)) {
            return false;
        }
        node.i(next);
        return true;
    }

    public final boolean e(kotlinx.coroutines.internal.LockFreeLinkedListNode node) {
        b.set(node, this);
        a.set(node, this);
        while (j() == this) {
            if (androidx.concurrent.futures.a.a(a, this, this, node)) {
                node.i(this);
                return true;
            }
        }
        return false;
    }

    public final void f(int forbiddenElementsBit) {
        c(new kotlinx.coroutines.internal.ListClosed(forbiddenElementsBit), forbiddenElementsBit);
    }

    public final java.lang.Object j() {
        return a.get(this);
    }

    public final kotlinx.coroutines.internal.LockFreeLinkedListNode k() {
        kotlinx.coroutines.internal.LockFreeLinkedListNode lockFreeLinkedListNode;
        java.lang.Object objJ = j();
        kotlinx.coroutines.internal.Removed removed = objJ instanceof kotlinx.coroutines.internal.Removed ? (kotlinx.coroutines.internal.Removed) objJ : null;
        if (removed != null && (lockFreeLinkedListNode = removed.ref) != null) {
            return lockFreeLinkedListNode;
        }
        kotlin.jvm.internal.Intrinsics.j(objJ, "null cannot be cast to non-null type kotlinx.coroutines.internal.LockFreeLinkedListNode");
        return (kotlinx.coroutines.internal.LockFreeLinkedListNode) objJ;
    }

    public final kotlinx.coroutines.internal.LockFreeLinkedListNode l() {
        kotlinx.coroutines.internal.LockFreeLinkedListNode lockFreeLinkedListNodeG = g();
        return lockFreeLinkedListNodeG == null ? h((kotlinx.coroutines.internal.LockFreeLinkedListNode) b.get(this)) : lockFreeLinkedListNodeG;
    }

    public boolean p() {
        return j() instanceof kotlinx.coroutines.internal.Removed;
    }

    public boolean q() {
        return r() == null;
    }

    public final kotlinx.coroutines.internal.LockFreeLinkedListNode r() {
        java.lang.Object objJ;
        kotlinx.coroutines.internal.LockFreeLinkedListNode lockFreeLinkedListNode;
        do {
            objJ = j();
            if (objJ instanceof kotlinx.coroutines.internal.Removed) {
                return ((kotlinx.coroutines.internal.Removed) objJ).ref;
            }
            if (objJ == this) {
                return (kotlinx.coroutines.internal.LockFreeLinkedListNode) objJ;
            }
            kotlin.jvm.internal.Intrinsics.j(objJ, "null cannot be cast to non-null type kotlinx.coroutines.internal.LockFreeLinkedListNode");
            lockFreeLinkedListNode = (kotlinx.coroutines.internal.LockFreeLinkedListNode) objJ;
        } while (!androidx.concurrent.futures.a.a(a, this, objJ, lockFreeLinkedListNode.s()));
        lockFreeLinkedListNode.g();
        return null;
    }

    public java.lang.String toString() {
        return new kotlin.jvm.internal.PropertyReference0Impl(this) { // from class: kotlinx.coroutines.internal.LockFreeLinkedListNode.toString.1
            public java.lang.Object get() {
                return kotlinx.coroutines.DebugStringsKt.a(((kotlin.jvm.internal.CallableReference) this).receiver);
            }
        } + '@' + kotlinx.coroutines.DebugStringsKt.b(this);
    }
}
