75 lines
2.3 KiB
Java
75 lines
2.3 KiB
Java
package io.reactivex.internal.schedulers;
|
|
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.internal.functions.Functions;
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Future;
|
|
import java.util.concurrent.FutureTask;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
/* loaded from: classes2.dex */
|
|
final class InstantPeriodicTask implements Callable<Void>, Disposable {
|
|
static final FutureTask<Void> f = new FutureTask<>(Functions.b, null);
|
|
final Runnable a;
|
|
final ExecutorService d;
|
|
Thread e;
|
|
final AtomicReference<Future<?>> c = new AtomicReference<>();
|
|
final AtomicReference<Future<?>> b = new AtomicReference<>();
|
|
|
|
InstantPeriodicTask(Runnable runnable, ExecutorService executorService) {
|
|
this.a = runnable;
|
|
this.d = executorService;
|
|
}
|
|
|
|
void a(Future<?> future) {
|
|
Future<?> future2;
|
|
do {
|
|
future2 = this.c.get();
|
|
if (future2 == f) {
|
|
future.cancel(this.e != Thread.currentThread());
|
|
return;
|
|
}
|
|
} while (!this.c.compareAndSet(future2, future));
|
|
}
|
|
|
|
void b(Future<?> future) {
|
|
Future<?> future2;
|
|
do {
|
|
future2 = this.b.get();
|
|
if (future2 == f) {
|
|
future.cancel(this.e != Thread.currentThread());
|
|
return;
|
|
}
|
|
} while (!this.b.compareAndSet(future2, future));
|
|
}
|
|
|
|
@Override // io.reactivex.disposables.Disposable
|
|
public void dispose() {
|
|
Future<?> andSet = this.c.getAndSet(f);
|
|
if (andSet != null && andSet != f) {
|
|
andSet.cancel(this.e != Thread.currentThread());
|
|
}
|
|
Future<?> andSet2 = this.b.getAndSet(f);
|
|
if (andSet2 == null || andSet2 == f) {
|
|
return;
|
|
}
|
|
andSet2.cancel(this.e != Thread.currentThread());
|
|
}
|
|
|
|
@Override // java.util.concurrent.Callable
|
|
public Void call() throws Exception {
|
|
this.e = Thread.currentThread();
|
|
try {
|
|
this.a.run();
|
|
b(this.d.submit(this));
|
|
this.e = null;
|
|
} catch (Throwable th) {
|
|
this.e = null;
|
|
RxJavaPlugins.b(th);
|
|
}
|
|
return null;
|
|
}
|
|
}
|