package e.a.u.h;

import e.a.m;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: compiled from: HalfSerializer.java */
/* JADX INFO: loaded from: classes.dex */
public final class d {
    public static void a(m<?> mVar, AtomicInteger atomicInteger, b bVar) {
        if (atomicInteger.getAndIncrement() == 0) {
            Throwable thB = bVar.b();
            if (thB != null) {
                mVar.b(thB);
            } else {
                mVar.a();
            }
        }
    }

    public static void b(m<?> mVar, Throwable th, AtomicInteger atomicInteger, b bVar) {
        if (!bVar.a(th)) {
            e.a.w.a.p(th);
        } else if (atomicInteger.getAndIncrement() == 0) {
            mVar.b(bVar.b());
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static <T> void c(m<? super T> mVar, T t, AtomicInteger atomicInteger, b bVar) {
        if (atomicInteger.get() == 0 && atomicInteger.compareAndSet(0, 1)) {
            mVar.d(t);
            if (atomicInteger.decrementAndGet() != 0) {
                Throwable thB = bVar.b();
                if (thB != null) {
                    mVar.b(thB);
                } else {
                    mVar.a();
                }
            }
        }
    }
}
