Add decompiled APK source code (JADX)

- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-18 14:52:23 -08:00
parent cc210a65ea
commit f9d20bb3fc
26991 changed files with 2541449 additions and 0 deletions

View File

@@ -0,0 +1,739 @@
package kotlinx.coroutines.scheduling;
import androidx.work.WorkRequest;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.locks.LockSupport;
import kotlin.Unit;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Ref;
import kotlin.random.Random;
import kotlin.ranges.RangesKt___RangesKt;
import kotlinx.coroutines.AbstractTimeSourceKt;
import kotlinx.coroutines.DebugStringsKt;
import kotlinx.coroutines.internal.ResizableAtomicArray;
import kotlinx.coroutines.internal.Symbol;
/* loaded from: classes5.dex */
public final class CoroutineScheduler implements Executor, Closeable {
private volatile int _isTerminated;
private volatile long controlState;
public final int corePoolSize;
public final GlobalQueue globalBlockingQueue;
public final GlobalQueue globalCpuQueue;
public final long idleWorkerKeepAliveNs;
public final int maxPoolSize;
private volatile long parkedWorkersStack;
public final String schedulerName;
public final ResizableAtomicArray workers;
public static final Companion Companion = new Companion(null);
public static final AtomicLongFieldUpdater parkedWorkersStack$FU = AtomicLongFieldUpdater.newUpdater(CoroutineScheduler.class, "parkedWorkersStack");
public static final AtomicLongFieldUpdater controlState$FU = AtomicLongFieldUpdater.newUpdater(CoroutineScheduler.class, "controlState");
public static final AtomicIntegerFieldUpdater _isTerminated$FU = AtomicIntegerFieldUpdater.newUpdater(CoroutineScheduler.class, "_isTerminated");
public static final Symbol NOT_IN_STACK = new Symbol("NOT_IN_STACK");
public /* synthetic */ class WhenMappings {
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
static {
int[] iArr = new int[WorkerState.values().length];
try {
iArr[WorkerState.PARKING.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
iArr[WorkerState.BLOCKING.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
iArr[WorkerState.CPU_ACQUIRED.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
iArr[WorkerState.DORMANT.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
iArr[WorkerState.TERMINATED.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
$EnumSwitchMapping$0 = iArr;
}
}
public enum WorkerState {
CPU_ACQUIRED,
BLOCKING,
PARKING,
DORMANT,
TERMINATED
}
public final int createNewWorker() {
int coerceAtLeast;
synchronized (this.workers) {
try {
if (isTerminated()) {
return -1;
}
AtomicLongFieldUpdater atomicLongFieldUpdater = controlState$FU;
long j = atomicLongFieldUpdater.get(this);
int i = (int) (j & 2097151);
coerceAtLeast = RangesKt___RangesKt.coerceAtLeast(i - ((int) ((j & 4398044413952L) >> 21)), 0);
if (coerceAtLeast >= this.corePoolSize) {
return 0;
}
if (i >= this.maxPoolSize) {
return 0;
}
int i2 = ((int) (controlState$FU.get(this) & 2097151)) + 1;
if (i2 <= 0 || this.workers.get(i2) != null) {
throw new IllegalArgumentException("Failed requirement.".toString());
}
Worker worker = new Worker(this, i2);
this.workers.setSynchronized(i2, worker);
if (i2 != ((int) (2097151 & atomicLongFieldUpdater.incrementAndGet(this)))) {
throw new IllegalArgumentException("Failed requirement.".toString());
}
int i3 = coerceAtLeast + 1;
worker.start();
return i3;
} catch (Throwable th) {
throw th;
}
}
}
public final class Worker extends Thread {
public static final AtomicIntegerFieldUpdater workerCtl$FU = AtomicIntegerFieldUpdater.newUpdater(Worker.class, "workerCtl");
private volatile int indexInArray;
public final WorkQueue localQueue;
public boolean mayHaveLocalTasks;
public long minDelayUntilStealableTaskNs;
private volatile Object nextParkedWorker;
public int rngState;
public WorkerState state;
public final Ref.ObjectRef stolenTask;
public long terminationDeadline;
private volatile int workerCtl;
public final int getIndexInArray() {
return this.indexInArray;
}
public final Object getNextParkedWorker() {
return this.nextParkedWorker;
}
public final void setNextParkedWorker(Object obj) {
this.nextParkedWorker = obj;
}
public final void executeTask(Task task) {
int taskMode = task.taskContext.getTaskMode();
idleReset(taskMode);
beforeTask(taskMode);
CoroutineScheduler.this.runSafely(task);
afterTask(taskMode);
}
public Worker() {
setDaemon(true);
this.localQueue = new WorkQueue();
this.stolenTask = new Ref.ObjectRef();
this.state = WorkerState.DORMANT;
this.nextParkedWorker = CoroutineScheduler.NOT_IN_STACK;
this.rngState = Random.Default.nextInt();
}
public final void setIndexInArray(int i) {
StringBuilder sb = new StringBuilder();
sb.append(CoroutineScheduler.this.schedulerName);
sb.append("-worker-");
sb.append(i == 0 ? "TERMINATED" : String.valueOf(i));
setName(sb.toString());
this.indexInArray = i;
}
public Worker(CoroutineScheduler coroutineScheduler, int i) {
this();
setIndexInArray(i);
}
public final boolean tryAcquireCpuPermit() {
long j;
if (this.state == WorkerState.CPU_ACQUIRED) {
return true;
}
CoroutineScheduler coroutineScheduler = CoroutineScheduler.this;
AtomicLongFieldUpdater atomicLongFieldUpdater = CoroutineScheduler.controlState$FU;
do {
j = atomicLongFieldUpdater.get(coroutineScheduler);
if (((int) ((9223367638808264704L & j) >> 42)) == 0) {
return false;
}
} while (!CoroutineScheduler.controlState$FU.compareAndSet(coroutineScheduler, j, j - 4398046511104L));
this.state = WorkerState.CPU_ACQUIRED;
return true;
}
public final boolean tryReleaseCpu(WorkerState workerState) {
WorkerState workerState2 = this.state;
boolean z = workerState2 == WorkerState.CPU_ACQUIRED;
if (z) {
CoroutineScheduler.controlState$FU.addAndGet(CoroutineScheduler.this, 4398046511104L);
}
if (workerState2 != workerState) {
this.state = workerState;
}
return z;
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
runWorker();
}
public final void runWorker() {
loop0: while (true) {
boolean z = false;
while (!CoroutineScheduler.this.isTerminated() && this.state != WorkerState.TERMINATED) {
Task findTask = findTask(this.mayHaveLocalTasks);
if (findTask != null) {
this.minDelayUntilStealableTaskNs = 0L;
executeTask(findTask);
} else {
this.mayHaveLocalTasks = false;
if (this.minDelayUntilStealableTaskNs == 0) {
tryPark();
} else if (z) {
tryReleaseCpu(WorkerState.PARKING);
Thread.interrupted();
LockSupport.parkNanos(this.minDelayUntilStealableTaskNs);
this.minDelayUntilStealableTaskNs = 0L;
} else {
z = true;
}
}
}
}
tryReleaseCpu(WorkerState.TERMINATED);
}
public final void tryPark() {
if (!inStack()) {
CoroutineScheduler.this.parkedWorkersStackPush(this);
return;
}
workerCtl$FU.set(this, -1);
while (inStack() && workerCtl$FU.get(this) == -1 && !CoroutineScheduler.this.isTerminated() && this.state != WorkerState.TERMINATED) {
tryReleaseCpu(WorkerState.PARKING);
Thread.interrupted();
park();
}
}
public final boolean inStack() {
return this.nextParkedWorker != CoroutineScheduler.NOT_IN_STACK;
}
public final void beforeTask(int i) {
if (i != 0 && tryReleaseCpu(WorkerState.BLOCKING)) {
CoroutineScheduler.this.signalCpuWork();
}
}
public final void afterTask(int i) {
if (i == 0) {
return;
}
CoroutineScheduler.controlState$FU.addAndGet(CoroutineScheduler.this, -2097152L);
if (this.state != WorkerState.TERMINATED) {
this.state = WorkerState.DORMANT;
}
}
public final int nextInt(int i) {
int i2 = this.rngState;
int i3 = i2 ^ (i2 << 13);
int i4 = i3 ^ (i3 >> 17);
int i5 = i4 ^ (i4 << 5);
this.rngState = i5;
int i6 = i - 1;
return (i6 & i) == 0 ? i5 & i6 : (i5 & Integer.MAX_VALUE) % i;
}
public final void park() {
if (this.terminationDeadline == 0) {
this.terminationDeadline = System.nanoTime() + CoroutineScheduler.this.idleWorkerKeepAliveNs;
}
LockSupport.parkNanos(CoroutineScheduler.this.idleWorkerKeepAliveNs);
if (System.nanoTime() - this.terminationDeadline >= 0) {
this.terminationDeadline = 0L;
tryTerminateWorker();
}
}
public final void tryTerminateWorker() {
CoroutineScheduler coroutineScheduler = CoroutineScheduler.this;
synchronized (coroutineScheduler.workers) {
try {
if (coroutineScheduler.isTerminated()) {
return;
}
if (((int) (CoroutineScheduler.controlState$FU.get(coroutineScheduler) & 2097151)) <= coroutineScheduler.corePoolSize) {
return;
}
if (workerCtl$FU.compareAndSet(this, -1, 1)) {
int i = this.indexInArray;
setIndexInArray(0);
coroutineScheduler.parkedWorkersStackTopUpdate(this, i, 0);
int andDecrement = (int) (CoroutineScheduler.controlState$FU.getAndDecrement(coroutineScheduler) & 2097151);
if (andDecrement != i) {
Object obj = coroutineScheduler.workers.get(andDecrement);
Intrinsics.checkNotNull(obj);
Worker worker = (Worker) obj;
coroutineScheduler.workers.setSynchronized(i, worker);
worker.setIndexInArray(i);
coroutineScheduler.parkedWorkersStackTopUpdate(worker, andDecrement, i);
}
coroutineScheduler.workers.setSynchronized(andDecrement, null);
Unit unit = Unit.INSTANCE;
this.state = WorkerState.TERMINATED;
}
} catch (Throwable th) {
throw th;
}
}
}
public final void idleReset(int i) {
this.terminationDeadline = 0L;
if (this.state == WorkerState.PARKING) {
this.state = WorkerState.BLOCKING;
}
}
public final Task findTask(boolean z) {
return tryAcquireCpuPermit() ? findAnyTask(z) : findBlockingTask();
}
public final Task findBlockingTask() {
Task pollBlocking = this.localQueue.pollBlocking();
if (pollBlocking != null) {
return pollBlocking;
}
Task task = (Task) CoroutineScheduler.this.globalBlockingQueue.removeFirstOrNull();
return task == null ? trySteal(1) : task;
}
public final Task findAnyTask(boolean z) {
Task pollGlobalQueues;
Task pollGlobalQueues2;
if (z) {
boolean z2 = nextInt(CoroutineScheduler.this.corePoolSize * 2) == 0;
if (z2 && (pollGlobalQueues2 = pollGlobalQueues()) != null) {
return pollGlobalQueues2;
}
Task poll = this.localQueue.poll();
if (poll != null) {
return poll;
}
if (!z2 && (pollGlobalQueues = pollGlobalQueues()) != null) {
return pollGlobalQueues;
}
} else {
Task pollGlobalQueues3 = pollGlobalQueues();
if (pollGlobalQueues3 != null) {
return pollGlobalQueues3;
}
}
return trySteal(3);
}
public final Task pollGlobalQueues() {
if (nextInt(2) == 0) {
Task task = (Task) CoroutineScheduler.this.globalCpuQueue.removeFirstOrNull();
return task != null ? task : (Task) CoroutineScheduler.this.globalBlockingQueue.removeFirstOrNull();
}
Task task2 = (Task) CoroutineScheduler.this.globalBlockingQueue.removeFirstOrNull();
return task2 != null ? task2 : (Task) CoroutineScheduler.this.globalCpuQueue.removeFirstOrNull();
}
/* JADX WARN: Multi-variable type inference failed */
public final Task trySteal(int i) {
int i2 = (int) (CoroutineScheduler.controlState$FU.get(CoroutineScheduler.this) & 2097151);
if (i2 < 2) {
return null;
}
int nextInt = nextInt(i2);
CoroutineScheduler coroutineScheduler = CoroutineScheduler.this;
long j = Long.MAX_VALUE;
for (int i3 = 0; i3 < i2; i3++) {
nextInt++;
if (nextInt > i2) {
nextInt = 1;
}
Worker worker = (Worker) coroutineScheduler.workers.get(nextInt);
if (worker != null && worker != this) {
long trySteal = worker.localQueue.trySteal(i, this.stolenTask);
if (trySteal == -1) {
Ref.ObjectRef objectRef = this.stolenTask;
Task task = (Task) objectRef.element;
objectRef.element = null;
return task;
}
if (trySteal > 0) {
j = Math.min(j, trySteal);
}
}
}
if (j == Long.MAX_VALUE) {
j = 0;
}
this.minDelayUntilStealableTaskNs = j;
return null;
}
}
public CoroutineScheduler(int i, int i2, long j, String str) {
this.corePoolSize = i;
this.maxPoolSize = i2;
this.idleWorkerKeepAliveNs = j;
this.schedulerName = str;
if (i < 1) {
throw new IllegalArgumentException(("Core pool size " + i + " should be at least 1").toString());
}
if (i2 < i) {
throw new IllegalArgumentException(("Max pool size " + i2 + " should be greater than or equals to core pool size " + i).toString());
}
if (i2 > 2097150) {
throw new IllegalArgumentException(("Max pool size " + i2 + " should not exceed maximal supported number of threads 2097150").toString());
}
if (j <= 0) {
throw new IllegalArgumentException(("Idle worker keep alive time " + j + " must be positive").toString());
}
this.globalCpuQueue = new GlobalQueue();
this.globalBlockingQueue = new GlobalQueue();
this.workers = new ResizableAtomicArray((i + 1) * 2);
this.controlState = i << 42;
this._isTerminated = 0;
}
public final boolean addToGlobalQueue(Task task) {
if (task.taskContext.getTaskMode() == 1) {
return this.globalBlockingQueue.addLast(task);
}
return this.globalCpuQueue.addLast(task);
}
public final void parkedWorkersStackTopUpdate(Worker worker, int i, int i2) {
AtomicLongFieldUpdater atomicLongFieldUpdater = parkedWorkersStack$FU;
while (true) {
long j = atomicLongFieldUpdater.get(this);
int i3 = (int) (2097151 & j);
long j2 = (2097152 + j) & (-2097152);
if (i3 == i) {
i3 = i2 == 0 ? parkedWorkersStackNextIndex(worker) : i2;
}
if (i3 >= 0 && parkedWorkersStack$FU.compareAndSet(this, j, j2 | i3)) {
return;
}
}
}
public final boolean parkedWorkersStackPush(Worker worker) {
long j;
int indexInArray;
if (worker.getNextParkedWorker() != NOT_IN_STACK) {
return false;
}
AtomicLongFieldUpdater atomicLongFieldUpdater = parkedWorkersStack$FU;
do {
j = atomicLongFieldUpdater.get(this);
indexInArray = worker.getIndexInArray();
worker.setNextParkedWorker(this.workers.get((int) (2097151 & j)));
} while (!parkedWorkersStack$FU.compareAndSet(this, j, ((2097152 + j) & (-2097152)) | indexInArray));
return true;
}
public final Worker parkedWorkersStackPop() {
AtomicLongFieldUpdater atomicLongFieldUpdater = parkedWorkersStack$FU;
while (true) {
long j = atomicLongFieldUpdater.get(this);
Worker worker = (Worker) this.workers.get((int) (2097151 & j));
if (worker == null) {
return null;
}
long j2 = (2097152 + j) & (-2097152);
int parkedWorkersStackNextIndex = parkedWorkersStackNextIndex(worker);
if (parkedWorkersStackNextIndex >= 0 && parkedWorkersStack$FU.compareAndSet(this, j, parkedWorkersStackNextIndex | j2)) {
worker.setNextParkedWorker(NOT_IN_STACK);
return worker;
}
}
}
public final int parkedWorkersStackNextIndex(Worker worker) {
Object nextParkedWorker = worker.getNextParkedWorker();
while (nextParkedWorker != NOT_IN_STACK) {
if (nextParkedWorker == null) {
return 0;
}
Worker worker2 = (Worker) nextParkedWorker;
int indexInArray = worker2.getIndexInArray();
if (indexInArray != 0) {
return indexInArray;
}
nextParkedWorker = worker2.getNextParkedWorker();
}
return -1;
}
public final boolean isTerminated() {
return _isTerminated$FU.get(this) != 0;
}
public static final class Companion {
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public Companion() {
}
}
@Override // java.util.concurrent.Executor
public void execute(Runnable runnable) {
dispatch$default(this, runnable, null, false, 6, null);
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() {
shutdown(WorkRequest.MIN_BACKOFF_MILLIS);
}
public final void shutdown(long j) {
int i;
Task task;
if (_isTerminated$FU.compareAndSet(this, 0, 1)) {
Worker currentWorker = currentWorker();
synchronized (this.workers) {
i = (int) (controlState$FU.get(this) & 2097151);
}
if (1 <= i) {
int i2 = 1;
while (true) {
Object obj = this.workers.get(i2);
Intrinsics.checkNotNull(obj);
Worker worker = (Worker) obj;
if (worker != currentWorker) {
while (worker.isAlive()) {
LockSupport.unpark(worker);
worker.join(j);
}
worker.localQueue.offloadAllWorkTo(this.globalBlockingQueue);
}
if (i2 == i) {
break;
} else {
i2++;
}
}
}
this.globalBlockingQueue.close();
this.globalCpuQueue.close();
while (true) {
if (currentWorker != null) {
task = currentWorker.findTask(true);
if (task != null) {
continue;
runSafely(task);
}
}
task = (Task) this.globalCpuQueue.removeFirstOrNull();
if (task == null && (task = (Task) this.globalBlockingQueue.removeFirstOrNull()) == null) {
break;
}
runSafely(task);
}
if (currentWorker != null) {
currentWorker.tryReleaseCpu(WorkerState.TERMINATED);
}
parkedWorkersStack$FU.set(this, 0L);
controlState$FU.set(this, 0L);
}
}
public static /* synthetic */ void dispatch$default(CoroutineScheduler coroutineScheduler, Runnable runnable, TaskContext taskContext, boolean z, int i, Object obj) {
if ((i & 2) != 0) {
taskContext = TasksKt.NonBlockingContext;
}
if ((i & 4) != 0) {
z = false;
}
coroutineScheduler.dispatch(runnable, taskContext, z);
}
public final void dispatch(Runnable runnable, TaskContext taskContext, boolean z) {
AbstractTimeSourceKt.getTimeSource();
Task createTask = createTask(runnable, taskContext);
boolean z2 = false;
boolean z3 = createTask.taskContext.getTaskMode() == 1;
long addAndGet = z3 ? controlState$FU.addAndGet(this, 2097152L) : 0L;
Worker currentWorker = currentWorker();
Task submitToLocalQueue = submitToLocalQueue(currentWorker, createTask, z);
if (submitToLocalQueue != null && !addToGlobalQueue(submitToLocalQueue)) {
throw new RejectedExecutionException(this.schedulerName + " was terminated");
}
if (z && currentWorker != null) {
z2 = true;
}
if (z3) {
signalBlockingWork(addAndGet, z2);
} else {
if (z2) {
return;
}
signalCpuWork();
}
}
public final Task createTask(Runnable runnable, TaskContext taskContext) {
long nanoTime = TasksKt.schedulerTimeSource.nanoTime();
if (runnable instanceof Task) {
Task task = (Task) runnable;
task.submissionTime = nanoTime;
task.taskContext = taskContext;
return task;
}
return new TaskImpl(runnable, nanoTime, taskContext);
}
public final void signalBlockingWork(long j, boolean z) {
if (z || tryUnpark() || tryCreateWorker(j)) {
return;
}
tryUnpark();
}
public final void signalCpuWork() {
if (tryUnpark() || tryCreateWorker$default(this, 0L, 1, null)) {
return;
}
tryUnpark();
}
public static /* synthetic */ boolean tryCreateWorker$default(CoroutineScheduler coroutineScheduler, long j, int i, Object obj) {
if ((i & 1) != 0) {
j = controlState$FU.get(coroutineScheduler);
}
return coroutineScheduler.tryCreateWorker(j);
}
public final boolean tryCreateWorker(long j) {
int coerceAtLeast;
coerceAtLeast = RangesKt___RangesKt.coerceAtLeast(((int) (2097151 & j)) - ((int) ((j & 4398044413952L) >> 21)), 0);
if (coerceAtLeast < this.corePoolSize) {
int createNewWorker = createNewWorker();
if (createNewWorker == 1 && this.corePoolSize > 1) {
createNewWorker();
}
if (createNewWorker > 0) {
return true;
}
}
return false;
}
public final boolean tryUnpark() {
Worker parkedWorkersStackPop;
do {
parkedWorkersStackPop = parkedWorkersStackPop();
if (parkedWorkersStackPop == null) {
return false;
}
} while (!Worker.workerCtl$FU.compareAndSet(parkedWorkersStackPop, -1, 0));
LockSupport.unpark(parkedWorkersStackPop);
return true;
}
public final Task submitToLocalQueue(Worker worker, Task task, boolean z) {
if (worker == null || worker.state == WorkerState.TERMINATED) {
return task;
}
if (task.taskContext.getTaskMode() == 0 && worker.state == WorkerState.BLOCKING) {
return task;
}
worker.mayHaveLocalTasks = true;
return worker.localQueue.add(task, z);
}
public final Worker currentWorker() {
Thread currentThread = Thread.currentThread();
Worker worker = currentThread instanceof Worker ? (Worker) currentThread : null;
if (worker == null || !Intrinsics.areEqual(CoroutineScheduler.this, this)) {
return null;
}
return worker;
}
public String toString() {
ArrayList arrayList = new ArrayList();
int currentLength = this.workers.currentLength();
int i = 0;
int i2 = 0;
int i3 = 0;
int i4 = 0;
int i5 = 0;
for (int i6 = 1; i6 < currentLength; i6++) {
Worker worker = (Worker) this.workers.get(i6);
if (worker != null) {
int size$kotlinx_coroutines_core = worker.localQueue.getSize$kotlinx_coroutines_core();
int i7 = WhenMappings.$EnumSwitchMapping$0[worker.state.ordinal()];
if (i7 == 1) {
i3++;
} else if (i7 == 2) {
i2++;
StringBuilder sb = new StringBuilder();
sb.append(size$kotlinx_coroutines_core);
sb.append('b');
arrayList.add(sb.toString());
} else if (i7 == 3) {
i++;
StringBuilder sb2 = new StringBuilder();
sb2.append(size$kotlinx_coroutines_core);
sb2.append('c');
arrayList.add(sb2.toString());
} else if (i7 == 4) {
i4++;
if (size$kotlinx_coroutines_core > 0) {
StringBuilder sb3 = new StringBuilder();
sb3.append(size$kotlinx_coroutines_core);
sb3.append('d');
arrayList.add(sb3.toString());
}
} else if (i7 == 5) {
i5++;
}
}
}
long j = controlState$FU.get(this);
return this.schedulerName + '@' + DebugStringsKt.getHexAddress(this) + "[Pool Size {core = " + this.corePoolSize + ", max = " + this.maxPoolSize + "}, Worker States {CPU = " + i + ", blocking = " + i2 + ", parked = " + i3 + ", dormant = " + i4 + ", terminated = " + i5 + "}, running workers queues = " + arrayList + ", global CPU queue size = " + this.globalCpuQueue.getSize() + ", global blocking queue size = " + this.globalBlockingQueue.getSize() + ", Control State {created workers= " + ((int) (2097151 & j)) + ", blocking tasks = " + ((int) ((4398044413952L & j) >> 21)) + ", CPUs acquired = " + (this.corePoolSize - ((int) ((9223367638808264704L & j) >> 42))) + "}]";
}
public final void runSafely(Task task) {
try {
task.run();
} finally {
try {
} finally {
}
}
}
}

View File

@@ -0,0 +1,63 @@
package kotlinx.coroutines.scheduling;
import java.util.concurrent.Executor;
import kotlin.coroutines.CoroutineContext;
import kotlin.coroutines.EmptyCoroutineContext;
import kotlin.ranges.RangesKt___RangesKt;
import kotlinx.coroutines.CoroutineDispatcher;
import kotlinx.coroutines.ExecutorCoroutineDispatcher;
import kotlinx.coroutines.internal.SystemPropsKt;
import kotlinx.coroutines.internal.SystemPropsKt__SystemProps_commonKt;
/* loaded from: classes5.dex */
public final class DefaultIoScheduler extends ExecutorCoroutineDispatcher implements Executor {
public static final DefaultIoScheduler INSTANCE = new DefaultIoScheduler();
/* renamed from: default, reason: not valid java name */
public static final CoroutineDispatcher f3084default;
@Override // kotlinx.coroutines.ExecutorCoroutineDispatcher
public Executor getExecutor() {
return this;
}
@Override // kotlinx.coroutines.CoroutineDispatcher
public String toString() {
return "Dispatchers.IO";
}
static {
int coerceAtLeast;
int systemProp$default;
UnlimitedIoScheduler unlimitedIoScheduler = UnlimitedIoScheduler.INSTANCE;
coerceAtLeast = RangesKt___RangesKt.coerceAtLeast(64, SystemPropsKt.getAVAILABLE_PROCESSORS());
systemProp$default = SystemPropsKt__SystemProps_commonKt.systemProp$default("kotlinx.coroutines.io.parallelism", coerceAtLeast, 0, 0, 12, (Object) null);
f3084default = unlimitedIoScheduler.limitedParallelism(systemProp$default);
}
@Override // java.util.concurrent.Executor
public void execute(Runnable runnable) {
mo4148dispatch(EmptyCoroutineContext.INSTANCE, runnable);
}
@Override // kotlinx.coroutines.CoroutineDispatcher
public CoroutineDispatcher limitedParallelism(int i) {
return UnlimitedIoScheduler.INSTANCE.limitedParallelism(i);
}
@Override // kotlinx.coroutines.CoroutineDispatcher
/* renamed from: dispatch */
public void mo4148dispatch(CoroutineContext coroutineContext, Runnable runnable) {
f3084default.mo4148dispatch(coroutineContext, runnable);
}
@Override // kotlinx.coroutines.CoroutineDispatcher
public void dispatchYield(CoroutineContext coroutineContext, Runnable runnable) {
f3084default.dispatchYield(coroutineContext, runnable);
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() {
throw new IllegalStateException("Cannot be invoked on Dispatchers.IO".toString());
}
}

View File

@@ -0,0 +1,29 @@
package kotlinx.coroutines.scheduling;
import kotlinx.coroutines.CoroutineDispatcher;
import kotlinx.coroutines.internal.LimitedDispatcherKt;
/* loaded from: classes5.dex */
public final class DefaultScheduler extends SchedulerCoroutineDispatcher {
public static final DefaultScheduler INSTANCE = new DefaultScheduler();
@Override // kotlinx.coroutines.CoroutineDispatcher
public String toString() {
return "Dispatchers.Default";
}
public DefaultScheduler() {
super(TasksKt.CORE_POOL_SIZE, TasksKt.MAX_POOL_SIZE, TasksKt.IDLE_WORKER_KEEP_ALIVE_NS, TasksKt.DEFAULT_SCHEDULER_NAME);
}
@Override // kotlinx.coroutines.CoroutineDispatcher
public CoroutineDispatcher limitedParallelism(int i) {
LimitedDispatcherKt.checkParallelism(i);
return i >= TasksKt.CORE_POOL_SIZE ? this : super.limitedParallelism(i);
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() {
throw new UnsupportedOperationException("Dispatchers.Default cannot be closed");
}
}

View File

@@ -0,0 +1,10 @@
package kotlinx.coroutines.scheduling;
import kotlinx.coroutines.internal.LockFreeTaskQueue;
/* loaded from: classes5.dex */
public final class GlobalQueue extends LockFreeTaskQueue {
public GlobalQueue() {
super(false);
}
}

View File

@@ -0,0 +1,11 @@
package kotlinx.coroutines.scheduling;
/* loaded from: classes5.dex */
public final class NanoTimeSource extends SchedulerTimeSource {
public static final NanoTimeSource INSTANCE = new NanoTimeSource();
@Override // kotlinx.coroutines.scheduling.SchedulerTimeSource
public long nanoTime() {
return System.nanoTime();
}
}

View File

@@ -0,0 +1,45 @@
package kotlinx.coroutines.scheduling;
import java.util.concurrent.Executor;
import kotlin.coroutines.CoroutineContext;
import kotlinx.coroutines.ExecutorCoroutineDispatcher;
/* loaded from: classes5.dex */
public abstract class SchedulerCoroutineDispatcher extends ExecutorCoroutineDispatcher {
public final int corePoolSize;
public CoroutineScheduler coroutineScheduler = createScheduler();
public final long idleWorkerKeepAliveNs;
public final int maxPoolSize;
public final String schedulerName;
@Override // kotlinx.coroutines.ExecutorCoroutineDispatcher
public Executor getExecutor() {
return this.coroutineScheduler;
}
public SchedulerCoroutineDispatcher(int i, int i2, long j, String str) {
this.corePoolSize = i;
this.maxPoolSize = i2;
this.idleWorkerKeepAliveNs = j;
this.schedulerName = str;
}
public final CoroutineScheduler createScheduler() {
return new CoroutineScheduler(this.corePoolSize, this.maxPoolSize, this.idleWorkerKeepAliveNs, this.schedulerName);
}
@Override // kotlinx.coroutines.CoroutineDispatcher
/* renamed from: dispatch */
public void mo4148dispatch(CoroutineContext coroutineContext, Runnable runnable) {
CoroutineScheduler.dispatch$default(this.coroutineScheduler, runnable, null, false, 6, null);
}
@Override // kotlinx.coroutines.CoroutineDispatcher
public void dispatchYield(CoroutineContext coroutineContext, Runnable runnable) {
CoroutineScheduler.dispatch$default(this.coroutineScheduler, runnable, null, true, 2, null);
}
public final void dispatchWithContext$kotlinx_coroutines_core(Runnable runnable, TaskContext taskContext, boolean z) {
this.coroutineScheduler.dispatch(runnable, taskContext, z);
}
}

View File

@@ -0,0 +1,6 @@
package kotlinx.coroutines.scheduling;
/* loaded from: classes5.dex */
public abstract class SchedulerTimeSource {
public abstract long nanoTime();
}

View File

@@ -0,0 +1,16 @@
package kotlinx.coroutines.scheduling;
/* loaded from: classes5.dex */
public abstract class Task implements Runnable {
public long submissionTime;
public TaskContext taskContext;
public Task(long j, TaskContext taskContext) {
this.submissionTime = j;
this.taskContext = taskContext;
}
public Task() {
this(0L, TasksKt.NonBlockingContext);
}
}

View File

@@ -0,0 +1,8 @@
package kotlinx.coroutines.scheduling;
/* loaded from: classes5.dex */
public interface TaskContext {
void afterTask();
int getTaskMode();
}

View File

@@ -0,0 +1,19 @@
package kotlinx.coroutines.scheduling;
/* loaded from: classes5.dex */
public final class TaskContextImpl implements TaskContext {
public final int taskMode;
@Override // kotlinx.coroutines.scheduling.TaskContext
public void afterTask() {
}
@Override // kotlinx.coroutines.scheduling.TaskContext
public int getTaskMode() {
return this.taskMode;
}
public TaskContextImpl(int i) {
this.taskMode = i;
}
}

View File

@@ -0,0 +1,26 @@
package kotlinx.coroutines.scheduling;
import kotlinx.coroutines.DebugStringsKt;
/* loaded from: classes5.dex */
public final class TaskImpl extends Task {
public final Runnable block;
public TaskImpl(Runnable runnable, long j, TaskContext taskContext) {
super(j, taskContext);
this.block = runnable;
}
@Override // java.lang.Runnable
public void run() {
try {
this.block.run();
} finally {
this.taskContext.afterTask();
}
}
public String toString() {
return "Task[" + DebugStringsKt.getClassSimpleName(this.block) + '@' + DebugStringsKt.getHexAddress(this.block) + ", " + this.submissionTime + ", " + this.taskContext + ']';
}
}

View File

@@ -0,0 +1,39 @@
package kotlinx.coroutines.scheduling;
import java.util.concurrent.TimeUnit;
import kotlin.ranges.RangesKt___RangesKt;
import kotlinx.coroutines.internal.SystemPropsKt;
import kotlinx.coroutines.internal.SystemPropsKt__SystemProps_commonKt;
/* loaded from: classes5.dex */
public abstract class TasksKt {
public static final TaskContext BlockingContext;
public static final int CORE_POOL_SIZE;
public static final String DEFAULT_SCHEDULER_NAME = SystemPropsKt.systemProp("kotlinx.coroutines.scheduler.default.name", "DefaultDispatcher");
public static final long IDLE_WORKER_KEEP_ALIVE_NS;
public static final int MAX_POOL_SIZE;
public static final TaskContext NonBlockingContext;
public static final long WORK_STEALING_TIME_RESOLUTION_NS;
public static SchedulerTimeSource schedulerTimeSource;
static {
long systemProp$default;
int coerceAtLeast;
int systemProp$default2;
int systemProp$default3;
long systemProp$default4;
systemProp$default = SystemPropsKt__SystemProps_commonKt.systemProp$default("kotlinx.coroutines.scheduler.resolution.ns", 100000L, 0L, 0L, 12, (Object) null);
WORK_STEALING_TIME_RESOLUTION_NS = systemProp$default;
coerceAtLeast = RangesKt___RangesKt.coerceAtLeast(SystemPropsKt.getAVAILABLE_PROCESSORS(), 2);
systemProp$default2 = SystemPropsKt__SystemProps_commonKt.systemProp$default("kotlinx.coroutines.scheduler.core.pool.size", coerceAtLeast, 1, 0, 8, (Object) null);
CORE_POOL_SIZE = systemProp$default2;
systemProp$default3 = SystemPropsKt__SystemProps_commonKt.systemProp$default("kotlinx.coroutines.scheduler.max.pool.size", 2097150, 0, 2097150, 4, (Object) null);
MAX_POOL_SIZE = systemProp$default3;
TimeUnit timeUnit = TimeUnit.SECONDS;
systemProp$default4 = SystemPropsKt__SystemProps_commonKt.systemProp$default("kotlinx.coroutines.scheduler.keep.alive.sec", 60L, 0L, 0L, 12, (Object) null);
IDLE_WORKER_KEEP_ALIVE_NS = timeUnit.toNanos(systemProp$default4);
schedulerTimeSource = NanoTimeSource.INSTANCE;
NonBlockingContext = new TaskContextImpl(0);
BlockingContext = new TaskContextImpl(1);
}
}

View File

@@ -0,0 +1,27 @@
package kotlinx.coroutines.scheduling;
import kotlin.coroutines.CoroutineContext;
import kotlinx.coroutines.CoroutineDispatcher;
import kotlinx.coroutines.internal.LimitedDispatcherKt;
/* loaded from: classes5.dex */
public final class UnlimitedIoScheduler extends CoroutineDispatcher {
public static final UnlimitedIoScheduler INSTANCE = new UnlimitedIoScheduler();
@Override // kotlinx.coroutines.CoroutineDispatcher
public void dispatchYield(CoroutineContext coroutineContext, Runnable runnable) {
DefaultScheduler.INSTANCE.dispatchWithContext$kotlinx_coroutines_core(runnable, TasksKt.BlockingContext, true);
}
@Override // kotlinx.coroutines.CoroutineDispatcher
/* renamed from: dispatch */
public void mo4148dispatch(CoroutineContext coroutineContext, Runnable runnable) {
DefaultScheduler.INSTANCE.dispatchWithContext$kotlinx_coroutines_core(runnable, TasksKt.BlockingContext, false);
}
@Override // kotlinx.coroutines.CoroutineDispatcher
public CoroutineDispatcher limitedParallelism(int i) {
LimitedDispatcherKt.checkParallelism(i);
return i >= TasksKt.MAX_POOL_SIZE ? this : super.limitedParallelism(i);
}
}

View File

@@ -0,0 +1,203 @@
package kotlinx.coroutines.scheduling;
import androidx.concurrent.futures.AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import kotlin.jvm.internal.Ref;
import kotlinx.coroutines.channels.ChannelSegment$$ExternalSyntheticBackportWithForwarding0;
/* loaded from: classes5.dex */
public final class WorkQueue {
private volatile int blockingTasksInBuffer;
public final AtomicReferenceArray buffer = new AtomicReferenceArray(128);
private volatile int consumerIndex;
private volatile Object lastScheduledTask;
private volatile int producerIndex;
public static final AtomicReferenceFieldUpdater lastScheduledTask$FU = AtomicReferenceFieldUpdater.newUpdater(WorkQueue.class, Object.class, "lastScheduledTask");
public static final AtomicIntegerFieldUpdater producerIndex$FU = AtomicIntegerFieldUpdater.newUpdater(WorkQueue.class, "producerIndex");
public static final AtomicIntegerFieldUpdater consumerIndex$FU = AtomicIntegerFieldUpdater.newUpdater(WorkQueue.class, "consumerIndex");
public static final AtomicIntegerFieldUpdater blockingTasksInBuffer$FU = AtomicIntegerFieldUpdater.newUpdater(WorkQueue.class, "blockingTasksInBuffer");
public final int getBufferSize() {
return producerIndex$FU.get(this) - consumerIndex$FU.get(this);
}
public final int getSize$kotlinx_coroutines_core() {
return lastScheduledTask$FU.get(this) != null ? getBufferSize() + 1 : getBufferSize();
}
public final Task poll() {
Task task = (Task) lastScheduledTask$FU.getAndSet(this, null);
return task == null ? pollBuffer() : task;
}
public final Task add(Task task, boolean z) {
if (z) {
return addLast(task);
}
Task task2 = (Task) lastScheduledTask$FU.getAndSet(this, task);
if (task2 == null) {
return null;
}
return addLast(task2);
}
public final void decrementIfBlocking(Task task) {
if (task == null || task.taskContext.getTaskMode() != 1) {
return;
}
blockingTasksInBuffer$FU.decrementAndGet(this);
}
public final Task addLast(Task task) {
if (getBufferSize() == 127) {
return task;
}
if (task.taskContext.getTaskMode() == 1) {
blockingTasksInBuffer$FU.incrementAndGet(this);
}
int i = producerIndex$FU.get(this) & 127;
while (this.buffer.get(i) != null) {
Thread.yield();
}
this.buffer.lazySet(i, task);
producerIndex$FU.incrementAndGet(this);
return null;
}
/* JADX WARN: Multi-variable type inference failed */
public final long trySteal(int i, Ref.ObjectRef objectRef) {
T t;
if (i == 3) {
t = pollBuffer();
} else {
t = stealWithExclusiveMode(i);
}
if (t != 0) {
objectRef.element = t;
return -1L;
}
return tryStealLastScheduled(i, objectRef);
}
public final Task stealWithExclusiveMode(int i) {
int i2 = consumerIndex$FU.get(this);
int i3 = producerIndex$FU.get(this);
boolean z = i == 1;
while (i2 != i3) {
if (z && blockingTasksInBuffer$FU.get(this) == 0) {
return null;
}
int i4 = i2 + 1;
Task tryExtractFromTheMiddle = tryExtractFromTheMiddle(i2, z);
if (tryExtractFromTheMiddle != null) {
return tryExtractFromTheMiddle;
}
i2 = i4;
}
return null;
}
public final Task pollBlocking() {
return pollWithExclusiveMode(true);
}
public final Task pollWithExclusiveMode(boolean z) {
AtomicReferenceFieldUpdater atomicReferenceFieldUpdater;
Task task;
do {
atomicReferenceFieldUpdater = lastScheduledTask$FU;
task = (Task) atomicReferenceFieldUpdater.get(this);
if (task != null) {
if ((task.taskContext.getTaskMode() == 1) == z) {
}
}
int i = consumerIndex$FU.get(this);
int i2 = producerIndex$FU.get(this);
while (i != i2) {
if (z && blockingTasksInBuffer$FU.get(this) == 0) {
return null;
}
i2--;
Task tryExtractFromTheMiddle = tryExtractFromTheMiddle(i2, z);
if (tryExtractFromTheMiddle != null) {
return tryExtractFromTheMiddle;
}
}
return null;
} while (!AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0.m(atomicReferenceFieldUpdater, this, task, null));
return task;
}
public final Task tryExtractFromTheMiddle(int i, boolean z) {
int i2 = i & 127;
Task task = (Task) this.buffer.get(i2);
if (task != null) {
if ((task.taskContext.getTaskMode() == 1) == z && ChannelSegment$$ExternalSyntheticBackportWithForwarding0.m(this.buffer, i2, task, null)) {
if (z) {
blockingTasksInBuffer$FU.decrementAndGet(this);
}
return task;
}
}
return null;
}
public final void offloadAllWorkTo(GlobalQueue globalQueue) {
Task task = (Task) lastScheduledTask$FU.getAndSet(this, null);
if (task != null) {
globalQueue.addLast(task);
}
while (pollTo(globalQueue)) {
}
}
/* JADX WARN: Type inference failed for: r1v1, types: [T, java.lang.Object, kotlinx.coroutines.scheduling.Task] */
public final long tryStealLastScheduled(int i, Ref.ObjectRef objectRef) {
AtomicReferenceFieldUpdater atomicReferenceFieldUpdater;
?? r1;
do {
atomicReferenceFieldUpdater = lastScheduledTask$FU;
r1 = (Task) atomicReferenceFieldUpdater.get(this);
if (r1 == 0) {
return -2L;
}
if (((r1.taskContext.getTaskMode() != 1 ? 2 : 1) & i) == 0) {
return -2L;
}
long nanoTime = TasksKt.schedulerTimeSource.nanoTime() - r1.submissionTime;
long j = TasksKt.WORK_STEALING_TIME_RESOLUTION_NS;
if (nanoTime < j) {
return j - nanoTime;
}
} while (!AbstractResolvableFuture$SafeAtomicHelper$$ExternalSyntheticBackportWithForwarding0.m(atomicReferenceFieldUpdater, this, r1, null));
objectRef.element = r1;
return -1L;
}
public final boolean pollTo(GlobalQueue globalQueue) {
Task pollBuffer = pollBuffer();
if (pollBuffer == null) {
return false;
}
globalQueue.addLast(pollBuffer);
return true;
}
public final Task pollBuffer() {
Task task;
while (true) {
AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = consumerIndex$FU;
int i = atomicIntegerFieldUpdater.get(this);
if (i - producerIndex$FU.get(this) == 0) {
return null;
}
int i2 = i & 127;
if (atomicIntegerFieldUpdater.compareAndSet(this, i, i + 1) && (task = (Task) this.buffer.getAndSet(i2, null)) != null) {
decrementIfBlocking(task);
return task;
}
}
}
}