package com.facebook.bolts; import java.io.Closeable; import kotlin.Unit; import kotlin.jvm.internal.Intrinsics; /* loaded from: classes2.dex */ public final class CancellationTokenRegistration implements Closeable { private Runnable action; private boolean closed; private CancellationTokenSource tokenSource; public CancellationTokenRegistration(CancellationTokenSource tokenSource, Runnable runnable) { Intrinsics.checkNotNullParameter(tokenSource, "tokenSource"); this.action = runnable; this.tokenSource = tokenSource; } @Override // java.io.Closeable, java.lang.AutoCloseable public void close() { synchronized (this) { if (this.closed) { return; } this.closed = true; CancellationTokenSource cancellationTokenSource = this.tokenSource; if (cancellationTokenSource != null) { cancellationTokenSource.unregister$facebook_bolts_release(this); } this.tokenSource = null; this.action = null; Unit unit = Unit.INSTANCE; } } public final void runAction$facebook_bolts_release() { synchronized (this) { throwIfClosed(); Runnable runnable = this.action; if (runnable != null) { runnable.run(); } close(); Unit unit = Unit.INSTANCE; } } private final void throwIfClosed() { if (!(!this.closed)) { throw new IllegalStateException("Object already closed".toString()); } } }