Initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.internal.functions.Functions;
|
||||
import io.reactivex.schedulers.SchedulerRunnableIntrospection;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
abstract class AbstractDirectTask extends AtomicReference<Future<?>> implements Disposable, SchedulerRunnableIntrospection {
|
||||
private static final long serialVersionUID = 1811839108042568751L;
|
||||
protected final Runnable runnable;
|
||||
protected Thread runner;
|
||||
protected static final FutureTask<Void> FINISHED = new FutureTask<>(Functions.b, null);
|
||||
protected static final FutureTask<Void> DISPOSED = new FutureTask<>(Functions.b, null);
|
||||
|
||||
AbstractDirectTask(Runnable runnable) {
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.disposables.Disposable
|
||||
public final void dispose() {
|
||||
FutureTask<Void> futureTask;
|
||||
Future<?> future = get();
|
||||
if (future == FINISHED || future == (futureTask = DISPOSED) || !compareAndSet(future, futureTask) || future == null) {
|
||||
return;
|
||||
}
|
||||
future.cancel(this.runner != Thread.currentThread());
|
||||
}
|
||||
|
||||
public Runnable getWrappedRunnable() {
|
||||
return this.runnable;
|
||||
}
|
||||
|
||||
public final boolean isDisposed() {
|
||||
Future<?> future = get();
|
||||
return future == FINISHED || future == DISPOSED;
|
||||
}
|
||||
|
||||
public final void setFuture(Future<?> future) {
|
||||
Future<?> future2;
|
||||
do {
|
||||
future2 = get();
|
||||
if (future2 == FINISHED) {
|
||||
return;
|
||||
}
|
||||
if (future2 == DISPOSED) {
|
||||
future.cancel(this.runner != Thread.currentThread());
|
||||
return;
|
||||
}
|
||||
} while (!compareAndSet(future2, future));
|
||||
}
|
||||
}
|
@@ -0,0 +1,137 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.internal.disposables.EmptyDisposable;
|
||||
import io.reactivex.internal.disposables.ListCompositeDisposable;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class ComputationScheduler extends Scheduler implements SchedulerMultiWorkerSupport {
|
||||
static final FixedSchedulerPool d;
|
||||
static final RxThreadFactory e;
|
||||
static final int f = a(Runtime.getRuntime().availableProcessors(), Integer.getInteger("rx2.computation-threads", 0).intValue());
|
||||
static final PoolWorker g = new PoolWorker(new RxThreadFactory("RxComputationShutdown"));
|
||||
final ThreadFactory b;
|
||||
final AtomicReference<FixedSchedulerPool> c;
|
||||
|
||||
static final class FixedSchedulerPool implements SchedulerMultiWorkerSupport {
|
||||
final int a;
|
||||
final PoolWorker[] b;
|
||||
long c;
|
||||
|
||||
FixedSchedulerPool(int i, ThreadFactory threadFactory) {
|
||||
this.a = i;
|
||||
this.b = new PoolWorker[i];
|
||||
for (int i2 = 0; i2 < i; i2++) {
|
||||
this.b[i2] = new PoolWorker(threadFactory);
|
||||
}
|
||||
}
|
||||
|
||||
public PoolWorker a() {
|
||||
int i = this.a;
|
||||
if (i == 0) {
|
||||
return ComputationScheduler.g;
|
||||
}
|
||||
PoolWorker[] poolWorkerArr = this.b;
|
||||
long j = this.c;
|
||||
this.c = 1 + j;
|
||||
return poolWorkerArr[(int) (j % i)];
|
||||
}
|
||||
|
||||
public void b() {
|
||||
for (PoolWorker poolWorker : this.b) {
|
||||
poolWorker.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final class PoolWorker extends NewThreadWorker {
|
||||
PoolWorker(ThreadFactory threadFactory) {
|
||||
super(threadFactory);
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
g.dispose();
|
||||
e = new RxThreadFactory("RxComputationThreadPool", Math.max(1, Math.min(10, Integer.getInteger("rx2.computation-priority", 5).intValue())), true);
|
||||
d = new FixedSchedulerPool(0, e);
|
||||
d.b();
|
||||
}
|
||||
|
||||
public ComputationScheduler() {
|
||||
this(e);
|
||||
}
|
||||
|
||||
static int a(int i, int i2) {
|
||||
return (i2 <= 0 || i2 > i) ? i : i2;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Scheduler.Worker a() {
|
||||
return new EventLoopWorker(this.c.get().a());
|
||||
}
|
||||
|
||||
public void b() {
|
||||
FixedSchedulerPool fixedSchedulerPool = new FixedSchedulerPool(f, this.b);
|
||||
if (this.c.compareAndSet(d, fixedSchedulerPool)) {
|
||||
return;
|
||||
}
|
||||
fixedSchedulerPool.b();
|
||||
}
|
||||
|
||||
public ComputationScheduler(ThreadFactory threadFactory) {
|
||||
this.b = threadFactory;
|
||||
this.c = new AtomicReference<>(d);
|
||||
b();
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
return this.c.get().a().b(runnable, j, timeUnit);
|
||||
}
|
||||
|
||||
static final class EventLoopWorker extends Scheduler.Worker {
|
||||
private final ListCompositeDisposable a = new ListCompositeDisposable();
|
||||
private final CompositeDisposable b = new CompositeDisposable();
|
||||
private final ListCompositeDisposable c = new ListCompositeDisposable();
|
||||
private final PoolWorker d;
|
||||
volatile boolean e;
|
||||
|
||||
EventLoopWorker(PoolWorker poolWorker) {
|
||||
this.d = poolWorker;
|
||||
this.c.b(this.a);
|
||||
this.c.b(this.b);
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler.Worker
|
||||
public Disposable a(Runnable runnable) {
|
||||
return this.e ? EmptyDisposable.INSTANCE : this.d.a(runnable, 0L, TimeUnit.MILLISECONDS, this.a);
|
||||
}
|
||||
|
||||
@Override // io.reactivex.disposables.Disposable
|
||||
public void dispose() {
|
||||
if (this.e) {
|
||||
return;
|
||||
}
|
||||
this.e = true;
|
||||
this.c.dispose();
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler.Worker
|
||||
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
if (this.e) {
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
return this.d.a(runnable, j, timeUnit, this.b);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Disposable a(Runnable runnable, long j, long j2, TimeUnit timeUnit) {
|
||||
return this.c.get().a().b(runnable, j, j2, timeUnit);
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
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;
|
||||
}
|
||||
}
|
186
sources/io/reactivex/internal/schedulers/IoScheduler.java
Normal file
186
sources/io/reactivex/internal/schedulers/IoScheduler.java
Normal file
@@ -0,0 +1,186 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.internal.disposables.EmptyDisposable;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class IoScheduler extends Scheduler {
|
||||
static final RxThreadFactory d;
|
||||
static final RxThreadFactory e;
|
||||
private static final TimeUnit f = TimeUnit.SECONDS;
|
||||
static final ThreadWorker g = new ThreadWorker(new RxThreadFactory("RxCachedThreadSchedulerShutdown"));
|
||||
static final CachedWorkerPool h;
|
||||
final ThreadFactory b;
|
||||
final AtomicReference<CachedWorkerPool> c;
|
||||
|
||||
static final class EventLoopWorker extends Scheduler.Worker {
|
||||
private final CachedWorkerPool b;
|
||||
private final ThreadWorker c;
|
||||
final AtomicBoolean d = new AtomicBoolean();
|
||||
private final CompositeDisposable a = new CompositeDisposable();
|
||||
|
||||
EventLoopWorker(CachedWorkerPool cachedWorkerPool) {
|
||||
this.b = cachedWorkerPool;
|
||||
this.c = cachedWorkerPool.b();
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler.Worker
|
||||
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
return this.a.b() ? EmptyDisposable.INSTANCE : this.c.a(runnable, j, timeUnit, this.a);
|
||||
}
|
||||
|
||||
@Override // io.reactivex.disposables.Disposable
|
||||
public void dispose() {
|
||||
if (this.d.compareAndSet(false, true)) {
|
||||
this.a.dispose();
|
||||
this.b.a(this.c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final class ThreadWorker extends NewThreadWorker {
|
||||
private long c;
|
||||
|
||||
ThreadWorker(ThreadFactory threadFactory) {
|
||||
super(threadFactory);
|
||||
this.c = 0L;
|
||||
}
|
||||
|
||||
public void a(long j) {
|
||||
this.c = j;
|
||||
}
|
||||
|
||||
public long b() {
|
||||
return this.c;
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
g.dispose();
|
||||
int max = Math.max(1, Math.min(10, Integer.getInteger("rx2.io-priority", 5).intValue()));
|
||||
d = new RxThreadFactory("RxCachedThreadScheduler", max);
|
||||
e = new RxThreadFactory("RxCachedWorkerPoolEvictor", max);
|
||||
h = new CachedWorkerPool(0L, null, d);
|
||||
h.d();
|
||||
}
|
||||
|
||||
public IoScheduler() {
|
||||
this(d);
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Scheduler.Worker a() {
|
||||
return new EventLoopWorker(this.c.get());
|
||||
}
|
||||
|
||||
public void b() {
|
||||
CachedWorkerPool cachedWorkerPool = new CachedWorkerPool(60L, f, this.b);
|
||||
if (this.c.compareAndSet(h, cachedWorkerPool)) {
|
||||
return;
|
||||
}
|
||||
cachedWorkerPool.d();
|
||||
}
|
||||
|
||||
static final class CachedWorkerPool implements Runnable {
|
||||
private final long a;
|
||||
private final ConcurrentLinkedQueue<ThreadWorker> b;
|
||||
final CompositeDisposable c;
|
||||
private final ScheduledExecutorService d;
|
||||
private final Future<?> e;
|
||||
private final ThreadFactory f;
|
||||
|
||||
CachedWorkerPool(long j, TimeUnit timeUnit, ThreadFactory threadFactory) {
|
||||
ScheduledFuture<?> scheduledFuture;
|
||||
this.a = timeUnit != null ? timeUnit.toNanos(j) : 0L;
|
||||
this.b = new ConcurrentLinkedQueue<>();
|
||||
this.c = new CompositeDisposable();
|
||||
this.f = threadFactory;
|
||||
ScheduledExecutorService scheduledExecutorService = null;
|
||||
if (timeUnit != null) {
|
||||
scheduledExecutorService = Executors.newScheduledThreadPool(1, IoScheduler.e);
|
||||
long j2 = this.a;
|
||||
scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(this, j2, j2, TimeUnit.NANOSECONDS);
|
||||
} else {
|
||||
scheduledFuture = null;
|
||||
}
|
||||
this.d = scheduledExecutorService;
|
||||
this.e = scheduledFuture;
|
||||
}
|
||||
|
||||
void a(ThreadWorker threadWorker) {
|
||||
threadWorker.a(c() + this.a);
|
||||
this.b.offer(threadWorker);
|
||||
}
|
||||
|
||||
ThreadWorker b() {
|
||||
if (this.c.b()) {
|
||||
return IoScheduler.g;
|
||||
}
|
||||
while (!this.b.isEmpty()) {
|
||||
ThreadWorker poll = this.b.poll();
|
||||
if (poll != null) {
|
||||
return poll;
|
||||
}
|
||||
}
|
||||
ThreadWorker threadWorker = new ThreadWorker(this.f);
|
||||
this.c.b(threadWorker);
|
||||
return threadWorker;
|
||||
}
|
||||
|
||||
long c() {
|
||||
return System.nanoTime();
|
||||
}
|
||||
|
||||
void d() {
|
||||
this.c.dispose();
|
||||
Future<?> future = this.e;
|
||||
if (future != null) {
|
||||
future.cancel(true);
|
||||
}
|
||||
ScheduledExecutorService scheduledExecutorService = this.d;
|
||||
if (scheduledExecutorService != null) {
|
||||
scheduledExecutorService.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
a();
|
||||
}
|
||||
|
||||
void a() {
|
||||
if (this.b.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
long c = c();
|
||||
Iterator<ThreadWorker> it = this.b.iterator();
|
||||
while (it.hasNext()) {
|
||||
ThreadWorker next = it.next();
|
||||
if (next.b() > c) {
|
||||
return;
|
||||
}
|
||||
if (this.b.remove(next)) {
|
||||
this.c.a(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IoScheduler(ThreadFactory threadFactory) {
|
||||
this.b = threadFactory;
|
||||
this.c = new AtomicReference<>(h);
|
||||
b();
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import io.reactivex.Scheduler;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class NewThreadScheduler extends Scheduler {
|
||||
private static final RxThreadFactory c = new RxThreadFactory("RxNewThreadScheduler", Math.max(1, Math.min(10, Integer.getInteger("rx2.newthread-priority", 5).intValue())));
|
||||
final ThreadFactory b;
|
||||
|
||||
public NewThreadScheduler() {
|
||||
this(c);
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Scheduler.Worker a() {
|
||||
return new NewThreadWorker(this.b);
|
||||
}
|
||||
|
||||
public NewThreadScheduler(ThreadFactory threadFactory) {
|
||||
this.b = threadFactory;
|
||||
}
|
||||
}
|
111
sources/io/reactivex/internal/schedulers/NewThreadWorker.java
Normal file
111
sources/io/reactivex/internal/schedulers/NewThreadWorker.java
Normal file
@@ -0,0 +1,111 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.internal.disposables.DisposableContainer;
|
||||
import io.reactivex.internal.disposables.EmptyDisposable;
|
||||
import io.reactivex.plugins.RxJavaPlugins;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class NewThreadWorker extends Scheduler.Worker implements Disposable {
|
||||
private final ScheduledExecutorService a;
|
||||
volatile boolean b;
|
||||
|
||||
public NewThreadWorker(ThreadFactory threadFactory) {
|
||||
this.a = SchedulerPoolFactory.a(threadFactory);
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler.Worker
|
||||
public Disposable a(Runnable runnable) {
|
||||
return a(runnable, 0L, null);
|
||||
}
|
||||
|
||||
public Disposable b(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
ScheduledDirectTask scheduledDirectTask = new ScheduledDirectTask(RxJavaPlugins.a(runnable));
|
||||
try {
|
||||
scheduledDirectTask.setFuture(j <= 0 ? this.a.submit(scheduledDirectTask) : this.a.schedule(scheduledDirectTask, j, timeUnit));
|
||||
return scheduledDirectTask;
|
||||
} catch (RejectedExecutionException e) {
|
||||
RxJavaPlugins.b(e);
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // io.reactivex.disposables.Disposable
|
||||
public void dispose() {
|
||||
if (this.b) {
|
||||
return;
|
||||
}
|
||||
this.b = true;
|
||||
this.a.shutdownNow();
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler.Worker
|
||||
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
return this.b ? EmptyDisposable.INSTANCE : a(runnable, j, timeUnit, (DisposableContainer) null);
|
||||
}
|
||||
|
||||
public ScheduledRunnable a(Runnable runnable, long j, TimeUnit timeUnit, DisposableContainer disposableContainer) {
|
||||
Future<?> schedule;
|
||||
ScheduledRunnable scheduledRunnable = new ScheduledRunnable(RxJavaPlugins.a(runnable), disposableContainer);
|
||||
if (disposableContainer != null && !disposableContainer.b(scheduledRunnable)) {
|
||||
return scheduledRunnable;
|
||||
}
|
||||
try {
|
||||
if (j <= 0) {
|
||||
schedule = this.a.submit((Callable) scheduledRunnable);
|
||||
} else {
|
||||
schedule = this.a.schedule((Callable) scheduledRunnable, j, timeUnit);
|
||||
}
|
||||
scheduledRunnable.setFuture(schedule);
|
||||
} catch (RejectedExecutionException e) {
|
||||
if (disposableContainer != null) {
|
||||
disposableContainer.a(scheduledRunnable);
|
||||
}
|
||||
RxJavaPlugins.b(e);
|
||||
}
|
||||
return scheduledRunnable;
|
||||
}
|
||||
|
||||
public Disposable b(Runnable runnable, long j, long j2, TimeUnit timeUnit) {
|
||||
Future<?> schedule;
|
||||
Runnable a = RxJavaPlugins.a(runnable);
|
||||
if (j2 <= 0) {
|
||||
InstantPeriodicTask instantPeriodicTask = new InstantPeriodicTask(a, this.a);
|
||||
try {
|
||||
if (j <= 0) {
|
||||
schedule = this.a.submit(instantPeriodicTask);
|
||||
} else {
|
||||
schedule = this.a.schedule(instantPeriodicTask, j, timeUnit);
|
||||
}
|
||||
instantPeriodicTask.a(schedule);
|
||||
return instantPeriodicTask;
|
||||
} catch (RejectedExecutionException e) {
|
||||
RxJavaPlugins.b(e);
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
}
|
||||
ScheduledDirectPeriodicTask scheduledDirectPeriodicTask = new ScheduledDirectPeriodicTask(a);
|
||||
try {
|
||||
scheduledDirectPeriodicTask.setFuture(this.a.scheduleAtFixedRate(scheduledDirectPeriodicTask, j, j2, timeUnit));
|
||||
return scheduledDirectPeriodicTask;
|
||||
} catch (RejectedExecutionException e2) {
|
||||
RxJavaPlugins.b(e2);
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
public void a() {
|
||||
if (this.b) {
|
||||
return;
|
||||
}
|
||||
this.b = true;
|
||||
this.a.shutdown();
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface NonBlockingThread {
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class RxThreadFactory extends AtomicLong implements ThreadFactory {
|
||||
private static final long serialVersionUID = -7789753024099756196L;
|
||||
final boolean nonBlocking;
|
||||
final String prefix;
|
||||
final int priority;
|
||||
|
||||
static final class RxCustomThread extends Thread implements NonBlockingThread {
|
||||
RxCustomThread(Runnable runnable, String str) {
|
||||
super(runnable, str);
|
||||
}
|
||||
}
|
||||
|
||||
public RxThreadFactory(String str) {
|
||||
this(str, 5, false);
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ThreadFactory
|
||||
public Thread newThread(Runnable runnable) {
|
||||
String str = this.prefix + '-' + incrementAndGet();
|
||||
Thread rxCustomThread = this.nonBlocking ? new RxCustomThread(runnable, str) : new Thread(runnable, str);
|
||||
rxCustomThread.setPriority(this.priority);
|
||||
rxCustomThread.setDaemon(true);
|
||||
return rxCustomThread;
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.atomic.AtomicLong
|
||||
public String toString() {
|
||||
return "RxThreadFactory[" + this.prefix + "]";
|
||||
}
|
||||
|
||||
public RxThreadFactory(String str, int i) {
|
||||
this(str, i, false);
|
||||
}
|
||||
|
||||
public RxThreadFactory(String str, int i, boolean z) {
|
||||
this.prefix = str;
|
||||
this.priority = i;
|
||||
this.nonBlocking = z;
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import io.reactivex.plugins.RxJavaPlugins;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class ScheduledDirectPeriodicTask extends AbstractDirectTask implements Runnable {
|
||||
private static final long serialVersionUID = 1811839108042568751L;
|
||||
|
||||
public ScheduledDirectPeriodicTask(Runnable runnable) {
|
||||
super(runnable);
|
||||
}
|
||||
|
||||
@Override // io.reactivex.internal.schedulers.AbstractDirectTask
|
||||
public /* bridge */ /* synthetic */ Runnable getWrappedRunnable() {
|
||||
return super.getWrappedRunnable();
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
this.runner = Thread.currentThread();
|
||||
try {
|
||||
this.runnable.run();
|
||||
this.runner = null;
|
||||
} catch (Throwable th) {
|
||||
this.runner = null;
|
||||
lazySet(AbstractDirectTask.FINISHED);
|
||||
RxJavaPlugins.b(th);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class ScheduledDirectTask extends AbstractDirectTask implements Callable<Void> {
|
||||
private static final long serialVersionUID = 1811839108042568751L;
|
||||
|
||||
public ScheduledDirectTask(Runnable runnable) {
|
||||
super(runnable);
|
||||
}
|
||||
|
||||
@Override // io.reactivex.internal.schedulers.AbstractDirectTask
|
||||
public /* bridge */ /* synthetic */ Runnable getWrappedRunnable() {
|
||||
return super.getWrappedRunnable();
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.Callable
|
||||
public Void call() throws Exception {
|
||||
this.runner = Thread.currentThread();
|
||||
try {
|
||||
this.runnable.run();
|
||||
return null;
|
||||
} finally {
|
||||
lazySet(AbstractDirectTask.FINISHED);
|
||||
this.runner = null;
|
||||
}
|
||||
}
|
||||
}
|
128
sources/io/reactivex/internal/schedulers/ScheduledRunnable.java
Normal file
128
sources/io/reactivex/internal/schedulers/ScheduledRunnable.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.internal.disposables.DisposableContainer;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class ScheduledRunnable extends AtomicReferenceArray<Object> implements Runnable, Callable<Object>, Disposable {
|
||||
static final int FUTURE_INDEX = 1;
|
||||
static final int PARENT_INDEX = 0;
|
||||
static final int THREAD_INDEX = 2;
|
||||
private static final long serialVersionUID = -6120223772001106981L;
|
||||
final Runnable actual;
|
||||
static final Object PARENT_DISPOSED = new Object();
|
||||
static final Object SYNC_DISPOSED = new Object();
|
||||
static final Object ASYNC_DISPOSED = new Object();
|
||||
static final Object DONE = new Object();
|
||||
|
||||
public ScheduledRunnable(Runnable runnable, DisposableContainer disposableContainer) {
|
||||
super(3);
|
||||
this.actual = runnable;
|
||||
lazySet(0, disposableContainer);
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.Callable
|
||||
public Object call() {
|
||||
run();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.disposables.Disposable
|
||||
public void dispose() {
|
||||
Object obj;
|
||||
Object obj2;
|
||||
while (true) {
|
||||
Object obj3 = get(1);
|
||||
if (obj3 == DONE || obj3 == SYNC_DISPOSED || obj3 == ASYNC_DISPOSED) {
|
||||
break;
|
||||
}
|
||||
boolean z = get(2) != Thread.currentThread();
|
||||
if (compareAndSet(1, obj3, z ? ASYNC_DISPOSED : SYNC_DISPOSED)) {
|
||||
if (obj3 != null) {
|
||||
((Future) obj3).cancel(z);
|
||||
}
|
||||
}
|
||||
}
|
||||
do {
|
||||
obj = get(0);
|
||||
if (obj == DONE || obj == (obj2 = PARENT_DISPOSED) || obj == null) {
|
||||
return;
|
||||
}
|
||||
} while (!compareAndSet(0, obj, obj2));
|
||||
((DisposableContainer) obj).c(this);
|
||||
}
|
||||
|
||||
public boolean isDisposed() {
|
||||
Object obj = get(0);
|
||||
return obj == PARENT_DISPOSED || obj == DONE;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
Object obj;
|
||||
Object obj2;
|
||||
Object obj3;
|
||||
boolean compareAndSet;
|
||||
Object obj4;
|
||||
Object obj5;
|
||||
lazySet(2, Thread.currentThread());
|
||||
try {
|
||||
this.actual.run();
|
||||
} finally {
|
||||
try {
|
||||
lazySet(2, null);
|
||||
obj4 = get(0);
|
||||
if (obj4 != PARENT_DISPOSED) {
|
||||
((DisposableContainer) obj4).c(this);
|
||||
}
|
||||
do {
|
||||
obj5 = get(1);
|
||||
if (obj5 != SYNC_DISPOSED) {
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} while (!compareAndSet(1, obj5, DONE));
|
||||
} catch (Throwable th) {
|
||||
do {
|
||||
if (obj == obj2) {
|
||||
break;
|
||||
} else if (obj == obj3) {
|
||||
break;
|
||||
}
|
||||
} while (!compareAndSet);
|
||||
}
|
||||
}
|
||||
lazySet(2, null);
|
||||
obj4 = get(0);
|
||||
if (obj4 != PARENT_DISPOSED && compareAndSet(0, obj4, DONE) && obj4 != null) {
|
||||
((DisposableContainer) obj4).c(this);
|
||||
}
|
||||
do {
|
||||
obj5 = get(1);
|
||||
if (obj5 != SYNC_DISPOSED || obj5 == ASYNC_DISPOSED) {
|
||||
return;
|
||||
}
|
||||
} while (!compareAndSet(1, obj5, DONE));
|
||||
}
|
||||
|
||||
public void setFuture(Future<?> future) {
|
||||
Object obj;
|
||||
do {
|
||||
obj = get(1);
|
||||
if (obj == DONE) {
|
||||
return;
|
||||
}
|
||||
if (obj == SYNC_DISPOSED) {
|
||||
future.cancel(false);
|
||||
return;
|
||||
} else if (obj == ASYNC_DISPOSED) {
|
||||
future.cancel(true);
|
||||
return;
|
||||
}
|
||||
} while (!compareAndSet(1, obj, future));
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface SchedulerMultiWorkerSupport {
|
||||
}
|
@@ -0,0 +1,109 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class SchedulerPoolFactory {
|
||||
public static final boolean a;
|
||||
public static final int b;
|
||||
static final AtomicReference<ScheduledExecutorService> c = new AtomicReference<>();
|
||||
static final Map<ScheduledThreadPoolExecutor, Object> d = new ConcurrentHashMap();
|
||||
|
||||
static final class PurgeProperties {
|
||||
boolean a;
|
||||
int b;
|
||||
|
||||
PurgeProperties() {
|
||||
}
|
||||
|
||||
void a(Properties properties) {
|
||||
if (properties.containsKey("rx2.purge-enabled")) {
|
||||
this.a = Boolean.parseBoolean(properties.getProperty("rx2.purge-enabled"));
|
||||
} else {
|
||||
this.a = true;
|
||||
}
|
||||
if (!this.a || !properties.containsKey("rx2.purge-period-seconds")) {
|
||||
this.b = 1;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.b = Integer.parseInt(properties.getProperty("rx2.purge-period-seconds"));
|
||||
} catch (NumberFormatException unused) {
|
||||
this.b = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final class ScheduledTask implements Runnable {
|
||||
ScheduledTask() {
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
Iterator it = new ArrayList(SchedulerPoolFactory.d.keySet()).iterator();
|
||||
while (it.hasNext()) {
|
||||
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = (ScheduledThreadPoolExecutor) it.next();
|
||||
if (scheduledThreadPoolExecutor.isShutdown()) {
|
||||
SchedulerPoolFactory.d.remove(scheduledThreadPoolExecutor);
|
||||
} else {
|
||||
scheduledThreadPoolExecutor.purge();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
Properties properties = System.getProperties();
|
||||
PurgeProperties purgeProperties = new PurgeProperties();
|
||||
purgeProperties.a(properties);
|
||||
a = purgeProperties.a;
|
||||
b = purgeProperties.b;
|
||||
a();
|
||||
}
|
||||
|
||||
public static void a() {
|
||||
a(a);
|
||||
}
|
||||
|
||||
static void a(boolean z) {
|
||||
if (!z) {
|
||||
return;
|
||||
}
|
||||
while (true) {
|
||||
ScheduledExecutorService scheduledExecutorService = c.get();
|
||||
if (scheduledExecutorService != null) {
|
||||
return;
|
||||
}
|
||||
ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1, new RxThreadFactory("RxSchedulerPurge"));
|
||||
if (c.compareAndSet(scheduledExecutorService, newScheduledThreadPool)) {
|
||||
ScheduledTask scheduledTask = new ScheduledTask();
|
||||
int i = b;
|
||||
newScheduledThreadPool.scheduleAtFixedRate(scheduledTask, i, i, TimeUnit.SECONDS);
|
||||
return;
|
||||
}
|
||||
newScheduledThreadPool.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
public static ScheduledExecutorService a(ThreadFactory threadFactory) {
|
||||
ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1, threadFactory);
|
||||
a(a, newScheduledThreadPool);
|
||||
return newScheduledThreadPool;
|
||||
}
|
||||
|
||||
static void a(boolean z, ScheduledExecutorService scheduledExecutorService) {
|
||||
if (z && (scheduledExecutorService instanceof ScheduledThreadPoolExecutor)) {
|
||||
d.put((ScheduledThreadPoolExecutor) scheduledExecutorService, scheduledExecutorService);
|
||||
}
|
||||
}
|
||||
}
|
129
sources/io/reactivex/internal/schedulers/SingleScheduler.java
Normal file
129
sources/io/reactivex/internal/schedulers/SingleScheduler.java
Normal file
@@ -0,0 +1,129 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.internal.disposables.EmptyDisposable;
|
||||
import io.reactivex.plugins.RxJavaPlugins;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class SingleScheduler extends Scheduler {
|
||||
static final RxThreadFactory c;
|
||||
static final ScheduledExecutorService d = Executors.newScheduledThreadPool(0);
|
||||
final AtomicReference<ScheduledExecutorService> b;
|
||||
|
||||
static final class ScheduledWorker extends Scheduler.Worker {
|
||||
final ScheduledExecutorService a;
|
||||
final CompositeDisposable b = new CompositeDisposable();
|
||||
volatile boolean c;
|
||||
|
||||
ScheduledWorker(ScheduledExecutorService scheduledExecutorService) {
|
||||
this.a = scheduledExecutorService;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler.Worker
|
||||
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
if (this.c) {
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
ScheduledRunnable scheduledRunnable = new ScheduledRunnable(RxJavaPlugins.a(runnable), this.b);
|
||||
this.b.b(scheduledRunnable);
|
||||
try {
|
||||
scheduledRunnable.setFuture(j <= 0 ? this.a.submit((Callable) scheduledRunnable) : this.a.schedule((Callable) scheduledRunnable, j, timeUnit));
|
||||
return scheduledRunnable;
|
||||
} catch (RejectedExecutionException e) {
|
||||
dispose();
|
||||
RxJavaPlugins.b(e);
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // io.reactivex.disposables.Disposable
|
||||
public void dispose() {
|
||||
if (this.c) {
|
||||
return;
|
||||
}
|
||||
this.c = true;
|
||||
this.b.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
d.shutdown();
|
||||
c = new RxThreadFactory("RxSingleScheduler", Math.max(1, Math.min(10, Integer.getInteger("rx2.single-priority", 5).intValue())), true);
|
||||
}
|
||||
|
||||
public SingleScheduler() {
|
||||
this(c);
|
||||
}
|
||||
|
||||
static ScheduledExecutorService a(ThreadFactory threadFactory) {
|
||||
return SchedulerPoolFactory.a(threadFactory);
|
||||
}
|
||||
|
||||
public SingleScheduler(ThreadFactory threadFactory) {
|
||||
this.b = new AtomicReference<>();
|
||||
this.b.lazySet(a(threadFactory));
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Scheduler.Worker a() {
|
||||
return new ScheduledWorker(this.b.get());
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
Future<?> schedule;
|
||||
ScheduledDirectTask scheduledDirectTask = new ScheduledDirectTask(RxJavaPlugins.a(runnable));
|
||||
try {
|
||||
if (j <= 0) {
|
||||
schedule = this.b.get().submit(scheduledDirectTask);
|
||||
} else {
|
||||
schedule = this.b.get().schedule(scheduledDirectTask, j, timeUnit);
|
||||
}
|
||||
scheduledDirectTask.setFuture(schedule);
|
||||
return scheduledDirectTask;
|
||||
} catch (RejectedExecutionException e) {
|
||||
RxJavaPlugins.b(e);
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Disposable a(Runnable runnable, long j, long j2, TimeUnit timeUnit) {
|
||||
Future<?> schedule;
|
||||
Runnable a = RxJavaPlugins.a(runnable);
|
||||
if (j2 <= 0) {
|
||||
ScheduledExecutorService scheduledExecutorService = this.b.get();
|
||||
InstantPeriodicTask instantPeriodicTask = new InstantPeriodicTask(a, scheduledExecutorService);
|
||||
try {
|
||||
if (j <= 0) {
|
||||
schedule = scheduledExecutorService.submit(instantPeriodicTask);
|
||||
} else {
|
||||
schedule = scheduledExecutorService.schedule(instantPeriodicTask, j, timeUnit);
|
||||
}
|
||||
instantPeriodicTask.a(schedule);
|
||||
return instantPeriodicTask;
|
||||
} catch (RejectedExecutionException e) {
|
||||
RxJavaPlugins.b(e);
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
}
|
||||
ScheduledDirectPeriodicTask scheduledDirectPeriodicTask = new ScheduledDirectPeriodicTask(a);
|
||||
try {
|
||||
scheduledDirectPeriodicTask.setFuture(this.b.get().scheduleAtFixedRate(scheduledDirectPeriodicTask, j, j2, timeUnit));
|
||||
return scheduledDirectPeriodicTask;
|
||||
} catch (RejectedExecutionException e2) {
|
||||
RxJavaPlugins.b(e2);
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,166 @@
|
||||
package io.reactivex.internal.schedulers;
|
||||
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.disposables.Disposables;
|
||||
import io.reactivex.internal.disposables.EmptyDisposable;
|
||||
import io.reactivex.internal.functions.ObjectHelper;
|
||||
import io.reactivex.plugins.RxJavaPlugins;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class TrampolineScheduler extends Scheduler {
|
||||
private static final TrampolineScheduler b = new TrampolineScheduler();
|
||||
|
||||
static final class SleepingRunnable implements Runnable {
|
||||
private final Runnable a;
|
||||
private final TrampolineWorker b;
|
||||
private final long c;
|
||||
|
||||
SleepingRunnable(Runnable runnable, TrampolineWorker trampolineWorker, long j) {
|
||||
this.a = runnable;
|
||||
this.b = trampolineWorker;
|
||||
this.c = j;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
if (this.b.d) {
|
||||
return;
|
||||
}
|
||||
long a = this.b.a(TimeUnit.MILLISECONDS);
|
||||
long j = this.c;
|
||||
if (j > a) {
|
||||
try {
|
||||
Thread.sleep(j - a);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
RxJavaPlugins.b(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.b.d) {
|
||||
return;
|
||||
}
|
||||
this.a.run();
|
||||
}
|
||||
}
|
||||
|
||||
static final class TimedRunnable implements Comparable<TimedRunnable> {
|
||||
final Runnable a;
|
||||
final long b;
|
||||
final int c;
|
||||
volatile boolean d;
|
||||
|
||||
TimedRunnable(Runnable runnable, Long l, int i) {
|
||||
this.a = runnable;
|
||||
this.b = l.longValue();
|
||||
this.c = i;
|
||||
}
|
||||
|
||||
@Override // java.lang.Comparable
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public int compareTo(TimedRunnable timedRunnable) {
|
||||
int a = ObjectHelper.a(this.b, timedRunnable.b);
|
||||
return a == 0 ? ObjectHelper.a(this.c, timedRunnable.c) : a;
|
||||
}
|
||||
}
|
||||
|
||||
static final class TrampolineWorker extends Scheduler.Worker implements Disposable {
|
||||
final PriorityBlockingQueue<TimedRunnable> a = new PriorityBlockingQueue<>();
|
||||
private final AtomicInteger b = new AtomicInteger();
|
||||
final AtomicInteger c = new AtomicInteger();
|
||||
volatile boolean d;
|
||||
|
||||
final class AppendToQueueTask implements Runnable {
|
||||
final TimedRunnable a;
|
||||
|
||||
AppendToQueueTask(TimedRunnable timedRunnable) {
|
||||
this.a = timedRunnable;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
TimedRunnable timedRunnable = this.a;
|
||||
timedRunnable.d = true;
|
||||
TrampolineWorker.this.a.remove(timedRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
TrampolineWorker() {
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler.Worker
|
||||
public Disposable a(Runnable runnable) {
|
||||
return a(runnable, a(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Override // io.reactivex.disposables.Disposable
|
||||
public void dispose() {
|
||||
this.d = true;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler.Worker
|
||||
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
long a = a(TimeUnit.MILLISECONDS) + timeUnit.toMillis(j);
|
||||
return a(new SleepingRunnable(runnable, this, a), a);
|
||||
}
|
||||
|
||||
Disposable a(Runnable runnable, long j) {
|
||||
if (this.d) {
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
TimedRunnable timedRunnable = new TimedRunnable(runnable, Long.valueOf(j), this.c.incrementAndGet());
|
||||
this.a.add(timedRunnable);
|
||||
if (this.b.getAndIncrement() == 0) {
|
||||
int i = 1;
|
||||
while (!this.d) {
|
||||
TimedRunnable poll = this.a.poll();
|
||||
if (poll == null) {
|
||||
i = this.b.addAndGet(-i);
|
||||
if (i == 0) {
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
} else if (!poll.d) {
|
||||
poll.a.run();
|
||||
}
|
||||
}
|
||||
this.a.clear();
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
return Disposables.a(new AppendToQueueTask(timedRunnable));
|
||||
}
|
||||
}
|
||||
|
||||
TrampolineScheduler() {
|
||||
}
|
||||
|
||||
public static TrampolineScheduler b() {
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Scheduler.Worker a() {
|
||||
return new TrampolineWorker();
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Disposable a(Runnable runnable) {
|
||||
RxJavaPlugins.a(runnable).run();
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
try {
|
||||
timeUnit.sleep(j);
|
||||
RxJavaPlugins.a(runnable).run();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
RxJavaPlugins.b(e);
|
||||
}
|
||||
return EmptyDisposable.INSTANCE;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user