package e.a.y;

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

/* JADX INFO: compiled from: SerializedSubject.java */
/* JADX INFO: loaded from: classes.dex */
final class b<T> extends c<T> implements a.InterfaceC0119a<Object> {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    final c<T> f3890b;

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

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

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

    b(c<T> cVar) {
        this.f3890b = cVar;
    }

    @Override // e.a.h
    protected void S(m<? super T> mVar) {
        this.f3890b.e(mVar);
    }

    @Override // e.a.m
    public void a() {
        if (this.f3893h) {
            return;
        }
        synchronized (this) {
            if (this.f3893h) {
                return;
            }
            this.f3893h = true;
            if (!this.f3891f) {
                this.f3891f = true;
                this.f3890b.a();
                return;
            }
            e.a.u.h.a<Object> aVar = this.f3892g;
            if (aVar == null) {
                aVar = new e.a.u.h.a<>(4);
                this.f3892g = aVar;
            }
            aVar.b(e.complete());
        }
    }

    void a0() {
        e.a.u.h.a<Object> aVar;
        while (true) {
            synchronized (this) {
                aVar = this.f3892g;
                if (aVar == null) {
                    this.f3891f = false;
                    return;
                }
                this.f3892g = null;
            }
            aVar.c(this);
        }
    }

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

    @Override // e.a.m
    public void c(e.a.r.b bVar) {
        boolean z = true;
        if (!this.f3893h) {
            synchronized (this) {
                if (!this.f3893h) {
                    if (this.f3891f) {
                        e.a.u.h.a<Object> aVar = this.f3892g;
                        if (aVar == null) {
                            aVar = new e.a.u.h.a<>(4);
                            this.f3892g = aVar;
                        }
                        aVar.b(e.disposable(bVar));
                        return;
                    }
                    this.f3891f = true;
                    z = false;
                }
            }
        }
        if (z) {
            bVar.dispose();
        } else {
            this.f3890b.c(bVar);
            a0();
        }
    }

    @Override // e.a.m
    public void d(T t) {
        if (this.f3893h) {
            return;
        }
        synchronized (this) {
            if (this.f3893h) {
                return;
            }
            if (!this.f3891f) {
                this.f3891f = true;
                this.f3890b.d(t);
                a0();
            } else {
                e.a.u.h.a<Object> aVar = this.f3892g;
                if (aVar == null) {
                    aVar = new e.a.u.h.a<>(4);
                    this.f3892g = aVar;
                }
                aVar.b(e.next(t));
            }
        }
    }

    @Override // e.a.u.h.a.InterfaceC0119a, e.a.t.e
    public boolean test(Object obj) {
        return e.acceptFull(obj, this.f3890b);
    }
}
