package i.a.n.e.a;

import i.a.h;

/* JADX INFO: compiled from: ObservableObserveOn.java */
/* JADX INFO: loaded from: classes.dex */
public final class l<T> extends i.a.n.e.a.a<T, T> {
    final i.a.h d;
    final boolean e;
    final int f;

    /* JADX INFO: compiled from: ObservableObserveOn.java */
    static final class a<T> extends i.a.n.d.b<T> implements i.a.g<T>, Runnable {
        final i.a.g<? super T> b;
        final h.c d;
        final boolean e;
        final int f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        i.a.n.c.e<T> f852g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        i.a.k.b f853h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        Throwable f854i;

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

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

        /* JADX INFO: renamed from: l, reason: collision with root package name */
        int f857l;

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

        a(i.a.g<? super T> gVar, h.c cVar, boolean z, int i2) {
            this.b = gVar;
            this.d = cVar;
            this.e = z;
            this.f = i2;
        }

        @Override // i.a.g
        public void a(Throwable th) {
            if (this.f855j) {
                i.a.p.a.l(th);
                return;
            }
            this.f854i = th;
            this.f855j = true;
            h();
        }

        @Override // i.a.g
        public void b() {
            if (this.f855j) {
                return;
            }
            this.f855j = true;
            h();
        }

        @Override // i.a.g
        public void c(i.a.k.b bVar) {
            if (i.a.n.a.b.validate(this.f853h, bVar)) {
                this.f853h = bVar;
                if (bVar instanceof i.a.n.c.a) {
                    i.a.n.c.a aVar = (i.a.n.c.a) bVar;
                    int iRequestFusion = aVar.requestFusion(7);
                    if (iRequestFusion == 1) {
                        this.f857l = iRequestFusion;
                        this.f852g = aVar;
                        this.f855j = true;
                        this.b.c(this);
                        h();
                        return;
                    }
                    if (iRequestFusion == 2) {
                        this.f857l = iRequestFusion;
                        this.f852g = aVar;
                        this.b.c(this);
                        return;
                    }
                }
                this.f852g = new i.a.n.f.b(this.f);
                this.b.c(this);
            }
        }

        @Override // i.a.n.c.e
        public void clear() {
            this.f852g.clear();
        }

        @Override // i.a.g
        public void d(T t) {
            if (this.f855j) {
                return;
            }
            if (this.f857l != 2) {
                this.f852g.offer(t);
            }
            h();
        }

        @Override // i.a.k.b
        public void dispose() {
            if (this.f856k) {
                return;
            }
            this.f856k = true;
            this.f853h.dispose();
            this.d.dispose();
            if (getAndIncrement() == 0) {
                this.f852g.clear();
            }
        }

        boolean e(boolean z, boolean z2, i.a.g<? super T> gVar) {
            if (this.f856k) {
                this.f852g.clear();
                return true;
            }
            if (!z) {
                return false;
            }
            Throwable th = this.f854i;
            if (this.e) {
                if (!z2) {
                    return false;
                }
                if (th != null) {
                    gVar.a(th);
                } else {
                    gVar.b();
                }
                this.d.dispose();
                return true;
            }
            if (th != null) {
                this.f852g.clear();
                gVar.a(th);
                this.d.dispose();
                return true;
            }
            if (!z2) {
                return false;
            }
            gVar.b();
            this.d.dispose();
            return true;
        }

        void f() {
            int iAddAndGet = 1;
            while (!this.f856k) {
                boolean z = this.f855j;
                Throwable th = this.f854i;
                if (!this.e && z && th != null) {
                    this.b.a(th);
                    this.d.dispose();
                    return;
                }
                this.b.d(null);
                if (z) {
                    Throwable th2 = this.f854i;
                    if (th2 != null) {
                        this.b.a(th2);
                    } else {
                        this.b.b();
                    }
                    this.d.dispose();
                    return;
                }
                iAddAndGet = addAndGet(-iAddAndGet);
                if (iAddAndGet == 0) {
                    return;
                }
            }
        }

        /* JADX WARN: Code restructure failed: missing block: B:15:0x0027, code lost:
        
            r3 = addAndGet(-r3);
         */
        /* JADX WARN: Code restructure failed: missing block: B:16:0x002c, code lost:
        
            if (r3 != 0) goto L27;
         */
        /* JADX WARN: Code restructure failed: missing block: B:17:0x002e, code lost:
        
            return;
         */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        void g() {
            /*
                r7 = this;
                i.a.n.c.e<T> r0 = r7.f852g
                i.a.g<? super T> r1 = r7.b
                r2 = 1
                r3 = r2
            L6:
                boolean r4 = r7.f855j
                boolean r5 = r0.isEmpty()
                boolean r4 = r7.e(r4, r5, r1)
                if (r4 == 0) goto L13
                return
            L13:
                boolean r4 = r7.f855j
                java.lang.Object r5 = r0.poll()     // Catch: java.lang.Throwable -> L33
                if (r5 != 0) goto L1d
                r6 = r2
                goto L1e
            L1d:
                r6 = 0
            L1e:
                boolean r4 = r7.e(r4, r6, r1)
                if (r4 == 0) goto L25
                return
            L25:
                if (r6 == 0) goto L2f
                int r3 = -r3
                int r3 = r7.addAndGet(r3)
                if (r3 != 0) goto L6
                return
            L2f:
                r1.d(r5)
                goto L13
            L33:
                r2 = move-exception
                i.a.l.b.b(r2)
                i.a.k.b r3 = r7.f853h
                r3.dispose()
                r0.clear()
                r1.a(r2)
                i.a.h$c r0 = r7.d
                r0.dispose()
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: i.a.n.e.a.l.a.g():void");
        }

        void h() {
            if (getAndIncrement() == 0) {
                this.d.b(this);
            }
        }

        @Override // i.a.k.b
        public boolean isDisposed() {
            return this.f856k;
        }

        @Override // i.a.n.c.e
        public boolean isEmpty() {
            return this.f852g.isEmpty();
        }

        @Override // i.a.n.c.e
        public T poll() throws Exception {
            return this.f852g.poll();
        }

        @Override // i.a.n.c.b
        public int requestFusion(int i2) {
            if ((i2 & 2) == 0) {
                return 0;
            }
            this.f858m = true;
            return 2;
        }

        @Override // java.lang.Runnable
        public void run() {
            if (this.f858m) {
                f();
            } else {
                g();
            }
        }
    }

    public l(i.a.e<T> eVar, i.a.h hVar, boolean z, int i2) {
        super(eVar);
        this.d = hVar;
        this.e = z;
        this.f = i2;
    }

    @Override // i.a.d
    protected void B(i.a.g<? super T> gVar) {
        i.a.h hVar = this.d;
        if (hVar instanceof i.a.n.g.m) {
            this.b.a(gVar);
        } else {
            this.b.a(new a(gVar, hVar.a(), this.e, this.f));
        }
    }
}
