package com.google.android.gms.internal.ads;

/* JADX INFO: loaded from: classes2.dex */
public final class cv extends k30 {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Object f10086c = new Object();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f10087d = false;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f10088e = 0;

    public final zu p() {
        zu zuVar = new zu(this);
        p7.l0.g("createNewReference: Trying to acquire lock");
        synchronized (this.f10086c) {
            p7.l0.g("createNewReference: Lock acquired");
            l(new av(this, zuVar, 0), new av(this, zuVar, 3));
            com.google.android.gms.common.internal.w.g(this.f10088e >= 0);
            this.f10088e++;
        }
        p7.l0.g("createNewReference: Lock released");
        return zuVar;
    }

    public final void q() {
        p7.l0.g("releaseOneReference: Trying to acquire lock");
        synchronized (this.f10086c) {
            p7.l0.g("releaseOneReference: Lock acquired");
            com.google.android.gms.common.internal.w.g(this.f10088e > 0);
            p7.l0.g("Releasing 1 reference for JS Engine");
            this.f10088e--;
            s();
        }
        p7.l0.g("releaseOneReference: Lock released");
    }

    public final void r() {
        p7.l0.g("markAsDestroyable: Trying to acquire lock");
        synchronized (this.f10086c) {
            p7.l0.g("markAsDestroyable: Lock acquired");
            com.google.android.gms.common.internal.w.g(this.f10088e >= 0);
            p7.l0.g("Releasing root reference. JS Engine will be destroyed once other references are released.");
            this.f10087d = true;
            s();
        }
        p7.l0.g("markAsDestroyable: Lock released");
    }

    public final void s() {
        p7.l0.g("maybeDestroy: Trying to acquire lock");
        synchronized (this.f10086c) {
            try {
                p7.l0.g("maybeDestroy: Lock acquired");
                com.google.android.gms.common.internal.w.g(this.f10088e >= 0);
                if (this.f10087d && this.f10088e == 0) {
                    p7.l0.g("No reference is left (including root). Cleaning up engine.");
                    l(new ru(this), new g30(0));
                } else {
                    p7.l0.g("There are still references to the engine. Not destroying.");
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        p7.l0.g("maybeDestroy: Lock released");
    }
}
