package f.a.o;

import f.a.f;
import f.a.k.b;
import f.a.n.h.c;

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

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    f.a.n.h.a<Object> f931h;

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

    public a(f<? super T> fVar) {
        this(fVar, false);
    }

    @Override // f.a.f
    public void a(Throwable th) {
        if (this.f932i) {
            f.a.p.a.m(th);
            return;
        }
        synchronized (this) {
            boolean z = true;
            if (!this.f932i) {
                if (this.f930g) {
                    this.f932i = true;
                    f.a.n.h.a<Object> aVar = this.f931h;
                    if (aVar == null) {
                        aVar = new f.a.n.h.a<>(4);
                        this.f931h = aVar;
                    }
                    Object objError = c.error(th);
                    if (this.f928e) {
                        aVar.b(objError);
                    } else {
                        aVar.d(objError);
                    }
                    return;
                }
                this.f932i = true;
                this.f930g = true;
                z = false;
            }
            if (z) {
                f.a.p.a.m(th);
            } else {
                this.b.a(th);
            }
        }
    }

    @Override // f.a.f
    public void b() {
        if (this.f932i) {
            return;
        }
        synchronized (this) {
            if (this.f932i) {
                return;
            }
            if (!this.f930g) {
                this.f932i = true;
                this.f930g = true;
                this.b.b();
            } else {
                f.a.n.h.a<Object> aVar = this.f931h;
                if (aVar == null) {
                    aVar = new f.a.n.h.a<>(4);
                    this.f931h = aVar;
                }
                aVar.b(c.complete());
            }
        }
    }

    @Override // f.a.f
    public void c(b bVar) {
        if (f.a.n.a.b.validate(this.f929f, bVar)) {
            this.f929f = bVar;
            this.b.c(this);
        }
    }

    @Override // f.a.f
    public void d(T t) {
        if (this.f932i) {
            return;
        }
        if (t == null) {
            this.f929f.dispose();
            a(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
            return;
        }
        synchronized (this) {
            if (this.f932i) {
                return;
            }
            if (!this.f930g) {
                this.f930g = true;
                this.b.d(t);
                e();
            } else {
                f.a.n.h.a<Object> aVar = this.f931h;
                if (aVar == null) {
                    aVar = new f.a.n.h.a<>(4);
                    this.f931h = aVar;
                }
                aVar.b(c.next(t));
            }
        }
    }

    @Override // f.a.k.b
    public void dispose() {
        this.f929f.dispose();
    }

    void e() {
        f.a.n.h.a<Object> aVar;
        do {
            synchronized (this) {
                aVar = this.f931h;
                if (aVar == null) {
                    this.f930g = false;
                    return;
                }
                this.f931h = null;
            }
        } while (!aVar.a(this.b));
    }

    public a(f<? super T> fVar, boolean z) {
        this.b = fVar;
        this.f928e = z;
    }
}
