package kotlinx.coroutines.internal;

import kotlin.coroutines.EmptyCoroutineContext;
import kotlin.jvm.functions.Function2;
import kotlinx.coroutines.p1;

/* JADX INFO: loaded from: classes.dex */
public final class w implements p1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Object f29494a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ThreadLocal f29495b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final x f29496c;

    public w(Object obj, ThreadLocal threadLocal) {
        this.f29494a = obj;
        this.f29495b = threadLocal;
        this.f29496c = new x(threadLocal);
    }

    @Override // kotlin.coroutines.h
    public final Object E(Object obj, Function2 function2) {
        nb.g.i(function2, "operation");
        return function2.invoke(obj, this);
    }

    @Override // kotlinx.coroutines.p1
    public final Object H(kotlin.coroutines.h hVar) {
        ThreadLocal threadLocal = this.f29495b;
        Object obj = threadLocal.get();
        threadLocal.set(this.f29494a);
        return obj;
    }

    public final void a(Object obj) {
        this.f29495b.set(obj);
    }

    @Override // kotlin.coroutines.f
    public final kotlin.coroutines.g getKey() {
        return this.f29496c;
    }

    @Override // kotlin.coroutines.h
    public final kotlin.coroutines.f m(kotlin.coroutines.g gVar) {
        if (nb.g.c(this.f29496c, gVar)) {
            return this;
        }
        return null;
    }

    @Override // kotlin.coroutines.h
    public final kotlin.coroutines.h p(kotlin.coroutines.h hVar) {
        nb.g.i(hVar, "context");
        return kotlin.coroutines.e.a(this, hVar);
    }

    public final String toString() {
        return "ThreadLocal(value=" + this.f29494a + ", threadLocal = " + this.f29495b + ')';
    }

    @Override // kotlin.coroutines.h
    public final kotlin.coroutines.h x(kotlin.coroutines.g gVar) {
        return nb.g.c(this.f29496c, gVar) ? EmptyCoroutineContext.f29221a : this;
    }
}
