package kotlin.reflect.jvm.internal.impl.storage;

import defpackage.cr4;
import defpackage.e6a;
import defpackage.kp6;
import defpackage.sq3;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/* JADX INFO: loaded from: classes3.dex */
public final class CancellableSimpleLock extends DefaultSimpleLock {

    @kp6
    private final Runnable checkCancelled;

    @kp6
    private final sq3<InterruptedException, e6a> interruptedExceptionHandler;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    /* JADX WARN: Multi-variable type inference failed */
    public CancellableSimpleLock(@kp6 Lock lock, @kp6 Runnable runnable, @kp6 sq3<? super InterruptedException, e6a> sq3Var) {
        super(lock);
        cr4.g(lock, "lock");
        cr4.g(runnable, "checkCancelled");
        cr4.g(sq3Var, "interruptedExceptionHandler");
        this.checkCancelled = runnable;
        this.interruptedExceptionHandler = sq3Var;
    }

    @Override // kotlin.reflect.jvm.internal.impl.storage.DefaultSimpleLock, kotlin.reflect.jvm.internal.impl.storage.SimpleLock
    public void lock() {
        while (!getLock().tryLock(50L, TimeUnit.MILLISECONDS)) {
            try {
                this.checkCancelled.run();
            } catch (InterruptedException e) {
                this.interruptedExceptionHandler.invoke(e);
                return;
            }
        }
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public CancellableSimpleLock(@kp6 Runnable runnable, @kp6 sq3<? super InterruptedException, e6a> sq3Var) {
        this(new ReentrantLock(), runnable, sq3Var);
        cr4.g(runnable, "checkCancelled");
        cr4.g(sq3Var, "interruptedExceptionHandler");
    }
}
