package e.a.v;

import e.a.m;
import e.a.r.b;
import e.a.u.h.e;

/* JADX INFO: compiled from: SerializedObserver.java */
/* JADX INFO: loaded from: classes.dex */
public final class a<T> implements m<T>, b {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    final m<? super T> f3866b;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    final boolean f3867f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    b f3868g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    boolean f3869h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    e.a.u.h.a<Object> f3870i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    volatile boolean f3871j;

    public a(m<? super T> mVar) {
        this(mVar, false);
    }

    @Override // e.a.m
    public void a() {
        if (this.f3871j) {
            return;
        }
        synchronized (this) {
            if (this.f3871j) {
                return;
            }
            if (!this.f3869h) {
                this.f3871j = true;
                this.f3869h = true;
                this.f3866b.a();
            } else {
                e.a.u.h.a<Object> aVar = this.f3870i;
                if (aVar == null) {
                    aVar = new e.a.u.h.a<>(4);
                    this.f3870i = aVar;
                }
                aVar.b(e.complete());
            }
        }
    }

    @Override // e.a.m
    public void b(Throwable th) {
        if (this.f3871j) {
            e.a.w.a.p(th);
            return;
        }
        synchronized (this) {
            boolean z = true;
            if (!this.f3871j) {
                if (this.f3869h) {
                    this.f3871j = true;
                    e.a.u.h.a<Object> aVar = this.f3870i;
                    if (aVar == null) {
                        aVar = new e.a.u.h.a<>(4);
                        this.f3870i = aVar;
                    }
                    Object objError = e.error(th);
                    if (this.f3867f) {
                        aVar.b(objError);
                    } else {
                        aVar.d(objError);
                    }
                    return;
                }
                this.f3871j = true;
                this.f3869h = true;
                z = false;
            }
            if (z) {
                e.a.w.a.p(th);
            } else {
                this.f3866b.b(th);
            }
        }
    }

    @Override // e.a.m
    public void c(b bVar) {
        if (e.a.u.a.b.validate(this.f3868g, bVar)) {
            this.f3868g = bVar;
            this.f3866b.c(this);
        }
    }

    @Override // e.a.m
    public void d(T t) {
        if (this.f3871j) {
            return;
        }
        if (t == null) {
            this.f3868g.dispose();
            b(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
            return;
        }
        synchronized (this) {
            if (this.f3871j) {
                return;
            }
            if (!this.f3869h) {
                this.f3869h = true;
                this.f3866b.d(t);
                e();
            } else {
                e.a.u.h.a<Object> aVar = this.f3870i;
                if (aVar == null) {
                    aVar = new e.a.u.h.a<>(4);
                    this.f3870i = aVar;
                }
                aVar.b(e.next(t));
            }
        }
    }

    @Override // e.a.r.b
    public void dispose() {
        this.f3868g.dispose();
    }

    void e() {
        e.a.u.h.a<Object> aVar;
        do {
            synchronized (this) {
                aVar = this.f3870i;
                if (aVar == null) {
                    this.f3869h = false;
                    return;
                }
                this.f3870i = null;
            }
        } while (!aVar.a(this.f3866b));
    }

    @Override // e.a.r.b
    public boolean isDisposed() {
        return this.f3868g.isDisposed();
    }

    public a(m<? super T> mVar, boolean z) {
        this.f3866b = mVar;
        this.f3867f = z;
    }
}
