package p138.p176.p177.p190.p193;

import java.lang.Exception;
import java.util.ArrayDeque;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p190.p193.AbstractC3512;
import p138.p176.p177.p190.p193.C3511;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ࢫ.ބ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC3513<I extends C3511, O extends AbstractC3512, E extends Exception> implements InterfaceC3509<I, O, E> {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Thread f10468;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final Object f10469 = new Object();

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final ArrayDeque<I> f10470 = new ArrayDeque<>();

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final ArrayDeque<O> f10471 = new ArrayDeque<>();

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final I[] f10472;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final O[] f10473;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public int f10474;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public int f10475;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public I f10476;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public E f10477;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public boolean f10478;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public boolean f10479;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public int f10480;

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ࢫ.ބ$֏, reason: contains not printable characters */
    public class C3514 extends Thread {
        public C3514() {
        }

        @Override // java.lang.Thread, java.lang.Runnable
        public void run() {
            AbstractC3513 abstractC3513 = AbstractC3513.this;
            if (abstractC3513 == null) {
                throw null;
            }
            do {
                try {
                } catch (InterruptedException e) {
                    throw new IllegalStateException(e);
                }
            } while (abstractC3513.m5819());
        }
    }

    public AbstractC3513(I[] iArr, O[] oArr) {
        this.f10472 = iArr;
        this.f10474 = iArr.length;
        for (int i = 0; i < this.f10474; i++) {
            ((I[]) this.f10472)[i] = mo1136();
        }
        this.f10473 = oArr;
        this.f10475 = oArr.length;
        for (int i2 = 0; i2 < this.f10475; i2++) {
            ((O[]) this.f10473)[i2] = mo1137();
        }
        C3514 c3514 = new C3514();
        this.f10468 = c3514;
        c3514.start();
    }

    @Override // p138.p176.p177.p190.p193.InterfaceC3509
    public final void flush() {
        synchronized (this.f10469) {
            this.f10478 = true;
            this.f10480 = 0;
            if (this.f10476 != null) {
                m5818(this.f10476);
                this.f10476 = null;
            }
            while (!this.f10470.isEmpty()) {
                m5818(this.f10470.removeFirst());
            }
            while (!this.f10471.isEmpty()) {
                this.f10471.removeFirst().mo5814();
            }
            this.f10477 = null;
        }
    }

    /* JADX INFO: renamed from: ֏ */
    public abstract E mo1132(Throwable th);

    /* JADX INFO: renamed from: ֏ */
    public abstract E mo1133(I i, O o, boolean z);

    @Override // p138.p176.p177.p190.p193.InterfaceC3509
    /* JADX INFO: renamed from: ֏ */
    public void mo1134() {
        synchronized (this.f10469) {
            this.f10479 = true;
            this.f10469.notify();
        }
        try {
            this.f10468.join();
        } catch (InterruptedException unused) {
            Thread.currentThread().interrupt();
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m5815(int i) {
        C0567.m1932(this.f10474 == this.f10472.length);
        for (I i2 : this.f10472) {
            i2.m5811(i);
        }
    }

    @Override // p138.p176.p177.p190.p193.InterfaceC3509
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters and merged with bridge method [inline-methods] */
    public final void mo5806(I i) {
        synchronized (this.f10469) {
            m5821();
            C0567.m1896(i == this.f10476);
            this.f10470.addLast(i);
            m5820();
            this.f10476 = null;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void mo5817(O o) {
        synchronized (this.f10469) {
            o.mo5803();
            O[] oArr = this.f10473;
            int i = this.f10475;
            this.f10475 = i + 1;
            oArr[i] = o;
            m5820();
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m5818(I i) {
        i.mo5803();
        I[] iArr = this.f10472;
        int i2 = this.f10474;
        this.f10474 = i2 + 1;
        iArr[i2] = i;
    }

    @Override // p138.p176.p177.p190.p193.InterfaceC3509
    /* JADX INFO: renamed from: ހ */
    public final O mo5807() {
        synchronized (this.f10469) {
            m5821();
            if (this.f10471.isEmpty()) {
                return null;
            }
            return this.f10471.removeFirst();
        }
    }

    @Override // p138.p176.p177.p190.p193.InterfaceC3509
    /* JADX INFO: renamed from: ށ */
    public final I mo5808() {
        I i;
        synchronized (this.f10469) {
            m5821();
            C0567.m1932(this.f10476 == null);
            if (this.f10474 == 0) {
                i = null;
            } else {
                I[] iArr = this.f10472;
                int i2 = this.f10474 - 1;
                this.f10474 = i2;
                i = iArr[i2];
            }
            this.f10476 = i;
        }
        return i;
    }

    /* JADX INFO: renamed from: ނ */
    public abstract I mo1136();

    /* JADX INFO: renamed from: ރ */
    public abstract O mo1137();

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final boolean m5819() {
        E e;
        synchronized (this.f10469) {
            while (!this.f10479) {
                if (!this.f10470.isEmpty() && this.f10475 > 0) {
                    break;
                }
                this.f10469.wait();
            }
            if (this.f10479) {
                return false;
            }
            I iRemoveFirst = this.f10470.removeFirst();
            O[] oArr = this.f10473;
            int i = this.f10475 - 1;
            this.f10475 = i;
            O o = oArr[i];
            boolean z = this.f10478;
            this.f10478 = false;
            if (iRemoveFirst.m5805()) {
                o.m5801(4);
            } else {
                if (iRemoveFirst.m5804()) {
                    o.m5801(Integer.MIN_VALUE);
                }
                try {
                    e = (E) mo1133(iRemoveFirst, o, z);
                } catch (OutOfMemoryError e2) {
                    e = (E) mo1132((Throwable) e2);
                } catch (RuntimeException e3) {
                    e = (E) mo1132((Throwable) e3);
                }
                if (e != null) {
                    synchronized (this.f10469) {
                        this.f10477 = e;
                    }
                    return false;
                }
            }
            synchronized (this.f10469) {
                if (this.f10478) {
                    o.mo5814();
                } else if (o.m5804()) {
                    this.f10480++;
                    o.mo5814();
                } else {
                    o.f10467 = this.f10480;
                    this.f10480 = 0;
                    this.f10471.addLast(o);
                }
                m5818(iRemoveFirst);
            }
            return true;
        }
    }

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final void m5820() {
        if (!this.f10470.isEmpty() && this.f10475 > 0) {
            this.f10469.notify();
        }
    }

    /* JADX INFO: Thrown type has an unknown type hierarchy: E extends java.lang.Exception */
    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final void m5821() throws E {
        E e = this.f10477;
        if (e != null) {
            throw e;
        }
    }
}
