197 lines
6.0 KiB
Java
197 lines
6.0 KiB
Java
package j0.l.c;
|
|
|
|
import j0.l.e.i;
|
|
import j0.o.l;
|
|
import java.util.Objects;
|
|
import java.util.concurrent.ThreadFactory;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import rx.Scheduler;
|
|
import rx.Subscription;
|
|
import rx.functions.Action0;
|
|
import rx.internal.util.SubscriptionList;
|
|
import rx.subscriptions.CompositeSubscription;
|
|
/* compiled from: EventLoopsScheduler */
|
|
public final class b extends Scheduler implements k {
|
|
public static final int a;
|
|
public static final c b;
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
|
public static final C0329b f2844c = new C0329b(null, 0);
|
|
public final ThreadFactory d;
|
|
public final AtomicReference<C0329b> e;
|
|
|
|
/* compiled from: EventLoopsScheduler */
|
|
public static final class a extends Scheduler.Worker {
|
|
public final SubscriptionList i;
|
|
public final CompositeSubscription j;
|
|
public final SubscriptionList k;
|
|
public final c l;
|
|
|
|
/* compiled from: EventLoopsScheduler */
|
|
/* renamed from: j0.l.c.b$a$a reason: collision with other inner class name */
|
|
public class C0327a implements Action0 {
|
|
public final /* synthetic */ Action0 i;
|
|
|
|
public C0327a(Action0 action0) {
|
|
this.i = action0;
|
|
}
|
|
|
|
@Override // rx.functions.Action0
|
|
public void call() {
|
|
if (!a.this.k.j) {
|
|
this.i.call();
|
|
}
|
|
}
|
|
}
|
|
|
|
/* compiled from: EventLoopsScheduler */
|
|
/* renamed from: j0.l.c.b$a$b reason: collision with other inner class name */
|
|
public class C0328b implements Action0 {
|
|
public final /* synthetic */ Action0 i;
|
|
|
|
public C0328b(Action0 action0) {
|
|
this.i = action0;
|
|
}
|
|
|
|
@Override // rx.functions.Action0
|
|
public void call() {
|
|
if (!a.this.k.j) {
|
|
this.i.call();
|
|
}
|
|
}
|
|
}
|
|
|
|
public a(c cVar) {
|
|
SubscriptionList subscriptionList = new SubscriptionList();
|
|
this.i = subscriptionList;
|
|
CompositeSubscription compositeSubscription = new CompositeSubscription();
|
|
this.j = compositeSubscription;
|
|
this.k = new SubscriptionList(subscriptionList, compositeSubscription);
|
|
this.l = cVar;
|
|
}
|
|
|
|
@Override // rx.Scheduler.Worker
|
|
public Subscription a(Action0 action0) {
|
|
if (this.k.j) {
|
|
return j0.r.c.a;
|
|
}
|
|
c cVar = this.l;
|
|
C0327a aVar = new C0327a(action0);
|
|
SubscriptionList subscriptionList = this.i;
|
|
Objects.requireNonNull(cVar);
|
|
j jVar = new j(l.d(aVar), subscriptionList);
|
|
subscriptionList.a(jVar);
|
|
jVar.a(cVar.o.submit(jVar));
|
|
return jVar;
|
|
}
|
|
|
|
@Override // rx.Scheduler.Worker
|
|
public Subscription b(Action0 action0, long j, TimeUnit timeUnit) {
|
|
if (this.k.j) {
|
|
return j0.r.c.a;
|
|
}
|
|
c cVar = this.l;
|
|
C0328b bVar = new C0328b(action0);
|
|
CompositeSubscription compositeSubscription = this.j;
|
|
Objects.requireNonNull(cVar);
|
|
j jVar = new j(l.d(bVar), compositeSubscription);
|
|
compositeSubscription.a(jVar);
|
|
jVar.a(j <= 0 ? cVar.o.submit(jVar) : cVar.o.schedule(jVar, j, timeUnit));
|
|
return jVar;
|
|
}
|
|
|
|
@Override // rx.Subscription
|
|
public boolean isUnsubscribed() {
|
|
return this.k.j;
|
|
}
|
|
|
|
@Override // rx.Subscription
|
|
public void unsubscribe() {
|
|
this.k.unsubscribe();
|
|
}
|
|
}
|
|
|
|
/* compiled from: EventLoopsScheduler */
|
|
/* renamed from: j0.l.c.b$b reason: collision with other inner class name */
|
|
public static final class C0329b {
|
|
public final int a;
|
|
public final c[] b;
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
|
public long f2845c;
|
|
|
|
public C0329b(ThreadFactory threadFactory, int i) {
|
|
this.a = i;
|
|
this.b = new c[i];
|
|
for (int i2 = 0; i2 < i; i2++) {
|
|
this.b[i2] = new c(threadFactory);
|
|
}
|
|
}
|
|
|
|
public c a() {
|
|
int i = this.a;
|
|
if (i == 0) {
|
|
return b.b;
|
|
}
|
|
c[] cVarArr = this.b;
|
|
long j = this.f2845c;
|
|
this.f2845c = 1 + j;
|
|
return cVarArr[(int) (j % ((long) i))];
|
|
}
|
|
}
|
|
|
|
/* compiled from: EventLoopsScheduler */
|
|
public static final class c extends g {
|
|
public c(ThreadFactory threadFactory) {
|
|
super(threadFactory);
|
|
}
|
|
}
|
|
|
|
static {
|
|
int intValue = Integer.getInteger("rx.scheduler.max-computation-threads", 0).intValue();
|
|
int availableProcessors = Runtime.getRuntime().availableProcessors();
|
|
if (intValue <= 0 || intValue > availableProcessors) {
|
|
intValue = availableProcessors;
|
|
}
|
|
a = intValue;
|
|
c cVar = new c(i.i);
|
|
b = cVar;
|
|
cVar.unsubscribe();
|
|
}
|
|
|
|
public b(ThreadFactory threadFactory) {
|
|
this.d = threadFactory;
|
|
C0329b bVar = f2844c;
|
|
AtomicReference<C0329b> atomicReference = new AtomicReference<>(bVar);
|
|
this.e = atomicReference;
|
|
C0329b bVar2 = new C0329b(threadFactory, a);
|
|
if (!atomicReference.compareAndSet(bVar, bVar2)) {
|
|
for (c cVar : bVar2.b) {
|
|
cVar.unsubscribe();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // rx.Scheduler
|
|
public Scheduler.Worker a() {
|
|
return new a(this.e.get().a());
|
|
}
|
|
|
|
@Override // j0.l.c.k
|
|
public void shutdown() {
|
|
C0329b bVar;
|
|
C0329b bVar2;
|
|
do {
|
|
bVar = this.e.get();
|
|
bVar2 = f2844c;
|
|
if (bVar == bVar2) {
|
|
return;
|
|
}
|
|
} while (!this.e.compareAndSet(bVar, bVar2));
|
|
for (c cVar : bVar.b) {
|
|
cVar.unsubscribe();
|
|
}
|
|
}
|
|
}
|