283 lines
13 KiB
Java
283 lines
13 KiB
Java
package com.google.common.util.concurrent;
|
|
|
|
import com.airbnb.deeplinkdispatch.UrlTreeKt;
|
|
import com.google.common.base.Preconditions;
|
|
import java.util.ArrayDeque;
|
|
import java.util.Deque;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.RejectedExecutionException;
|
|
import java.util.logging.Logger;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes2.dex */
|
|
public final class SequentialExecutor implements Executor {
|
|
private static final Logger log = Logger.getLogger(SequentialExecutor.class.getName());
|
|
private final Executor executor;
|
|
private final Deque<Runnable> queue = new ArrayDeque();
|
|
private WorkerRunningState workerRunningState = WorkerRunningState.IDLE;
|
|
private long workerRunCount = 0;
|
|
private final QueueWorker worker = new QueueWorker();
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes2.dex */
|
|
public enum WorkerRunningState {
|
|
IDLE,
|
|
QUEUING,
|
|
QUEUED,
|
|
RUNNING
|
|
}
|
|
|
|
static /* synthetic */ long access$308(SequentialExecutor sequentialExecutor) {
|
|
long j = sequentialExecutor.workerRunCount;
|
|
sequentialExecutor.workerRunCount = 1 + j;
|
|
return j;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public SequentialExecutor(Executor executor) {
|
|
this.executor = (Executor) Preconditions.checkNotNull(executor);
|
|
}
|
|
|
|
@Override // java.util.concurrent.Executor
|
|
public final void execute(Runnable runnable) {
|
|
Preconditions.checkNotNull(runnable);
|
|
synchronized (this.queue) {
|
|
if (this.workerRunningState != WorkerRunningState.RUNNING && this.workerRunningState != WorkerRunningState.QUEUED) {
|
|
long j = this.workerRunCount;
|
|
Runnable runnable2 = new Runnable(this, runnable) { // from class: com.google.common.util.concurrent.SequentialExecutor.1
|
|
final Runnable val$task;
|
|
|
|
{
|
|
this.val$task = runnable;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.val$task.run();
|
|
}
|
|
|
|
public String toString() {
|
|
return this.val$task.toString();
|
|
}
|
|
};
|
|
this.queue.add(runnable2);
|
|
this.workerRunningState = WorkerRunningState.QUEUING;
|
|
try {
|
|
this.executor.execute(this.worker);
|
|
if (this.workerRunningState != WorkerRunningState.QUEUING) {
|
|
return;
|
|
}
|
|
synchronized (this.queue) {
|
|
if (this.workerRunCount == j && this.workerRunningState == WorkerRunningState.QUEUING) {
|
|
this.workerRunningState = WorkerRunningState.QUEUED;
|
|
}
|
|
}
|
|
return;
|
|
} catch (Error | RuntimeException e) {
|
|
synchronized (this.queue) {
|
|
boolean z = (this.workerRunningState == WorkerRunningState.IDLE || this.workerRunningState == WorkerRunningState.QUEUING) && this.queue.removeLastOccurrence(runnable2);
|
|
if (!(e instanceof RejectedExecutionException) || z) {
|
|
throw e;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
this.queue.add(runnable);
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes2.dex */
|
|
final class QueueWorker implements Runnable {
|
|
Runnable task;
|
|
final SequentialExecutor this$0;
|
|
|
|
private QueueWorker(SequentialExecutor sequentialExecutor) {
|
|
this.this$0 = sequentialExecutor;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
try {
|
|
workOnQueue();
|
|
} catch (Error e) {
|
|
synchronized (this.this$0.queue) {
|
|
this.this$0.workerRunningState = WorkerRunningState.IDLE;
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:10:0x0054, code lost:
|
|
|
|
r0 = r0 | java.lang.Thread.interrupted();
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:12:0x0056, code lost:
|
|
|
|
r9.task.run();
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:16:0x005e, code lost:
|
|
|
|
r3 = move-exception;
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:17:0x005f, code lost:
|
|
|
|
r4 = com.google.common.util.concurrent.SequentialExecutor.log;
|
|
r5 = java.util.logging.Level.SEVERE;
|
|
r6 = java.lang.String.valueOf(r9.task);
|
|
r8 = new java.lang.StringBuilder(java.lang.String.valueOf(r6).length() + 35);
|
|
r8.append("Exception while executing runnable ");
|
|
r8.append(r6);
|
|
r4.log(r5, r8.toString(), (java.lang.Throwable) r3);
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:19:0x005c, code lost:
|
|
|
|
r1 = move-exception;
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:20:0x008d, code lost:
|
|
|
|
r9.task = null;
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:21:0x008f, code lost:
|
|
|
|
throw r1;
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:24:0x003d, code lost:
|
|
|
|
r9.this$0.workerRunningState = com.google.common.util.concurrent.SequentialExecutor.WorkerRunningState.IDLE;
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:28:0x004e, code lost:
|
|
|
|
return;
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:29:?, code lost:
|
|
|
|
return;
|
|
*/
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
private void workOnQueue() {
|
|
/*
|
|
r9 = this;
|
|
r0 = 0
|
|
r1 = r0
|
|
L2:
|
|
com.google.common.util.concurrent.SequentialExecutor r2 = r9.this$0 // Catch: java.lang.Throwable -> L93
|
|
java.util.Deque r2 = com.google.common.util.concurrent.SequentialExecutor.access$100(r2) // Catch: java.lang.Throwable -> L93
|
|
monitor-enter(r2) // Catch: java.lang.Throwable -> L93
|
|
if (r1 != 0) goto L2d
|
|
com.google.common.util.concurrent.SequentialExecutor r1 = r9.this$0 // Catch: java.lang.Throwable -> L90
|
|
com.google.common.util.concurrent.SequentialExecutor$WorkerRunningState r1 = com.google.common.util.concurrent.SequentialExecutor.access$200(r1) // Catch: java.lang.Throwable -> L90
|
|
com.google.common.util.concurrent.SequentialExecutor$WorkerRunningState r3 = com.google.common.util.concurrent.SequentialExecutor.WorkerRunningState.RUNNING // Catch: java.lang.Throwable -> L90
|
|
if (r1 != r3) goto L20
|
|
monitor-exit(r2)
|
|
if (r0 == 0) goto L1f
|
|
java.lang.Thread r0 = java.lang.Thread.currentThread()
|
|
r0.interrupt()
|
|
L1f:
|
|
return
|
|
L20:
|
|
com.google.common.util.concurrent.SequentialExecutor r1 = r9.this$0 // Catch: java.lang.Throwable -> L90
|
|
com.google.common.util.concurrent.SequentialExecutor.access$308(r1) // Catch: java.lang.Throwable -> L90
|
|
com.google.common.util.concurrent.SequentialExecutor r1 = r9.this$0 // Catch: java.lang.Throwable -> L90
|
|
com.google.common.util.concurrent.SequentialExecutor$WorkerRunningState r3 = com.google.common.util.concurrent.SequentialExecutor.WorkerRunningState.RUNNING // Catch: java.lang.Throwable -> L90
|
|
com.google.common.util.concurrent.SequentialExecutor.access$202(r1, r3) // Catch: java.lang.Throwable -> L90
|
|
r1 = 1
|
|
L2d:
|
|
com.google.common.util.concurrent.SequentialExecutor r3 = r9.this$0 // Catch: java.lang.Throwable -> L90
|
|
java.util.Deque r3 = com.google.common.util.concurrent.SequentialExecutor.access$100(r3) // Catch: java.lang.Throwable -> L90
|
|
java.lang.Object r3 = r3.poll() // Catch: java.lang.Throwable -> L90
|
|
java.lang.Runnable r3 = (java.lang.Runnable) r3 // Catch: java.lang.Throwable -> L90
|
|
r9.task = r3 // Catch: java.lang.Throwable -> L90
|
|
if (r3 != 0) goto L4f
|
|
com.google.common.util.concurrent.SequentialExecutor r1 = r9.this$0 // Catch: java.lang.Throwable -> L90
|
|
com.google.common.util.concurrent.SequentialExecutor$WorkerRunningState r3 = com.google.common.util.concurrent.SequentialExecutor.WorkerRunningState.IDLE // Catch: java.lang.Throwable -> L90
|
|
com.google.common.util.concurrent.SequentialExecutor.access$202(r1, r3) // Catch: java.lang.Throwable -> L90
|
|
monitor-exit(r2)
|
|
if (r0 == 0) goto L4e
|
|
java.lang.Thread r0 = java.lang.Thread.currentThread()
|
|
r0.interrupt()
|
|
L4e:
|
|
return
|
|
L4f:
|
|
monitor-exit(r2)
|
|
boolean r2 = java.lang.Thread.interrupted() // Catch: java.lang.Throwable -> L93
|
|
r0 = r0 | r2
|
|
r2 = 0
|
|
java.lang.Runnable r3 = r9.task // Catch: java.lang.Throwable -> L5c java.lang.RuntimeException -> L5e
|
|
r3.run() // Catch: java.lang.Throwable -> L5c java.lang.RuntimeException -> L5e
|
|
goto L89
|
|
L5c:
|
|
r1 = move-exception
|
|
goto L8d
|
|
L5e:
|
|
r3 = move-exception
|
|
java.util.logging.Logger r4 = com.google.common.util.concurrent.SequentialExecutor.access$400() // Catch: java.lang.Throwable -> L5c
|
|
java.util.logging.Level r5 = java.util.logging.Level.SEVERE // Catch: java.lang.Throwable -> L5c
|
|
java.lang.Runnable r6 = r9.task // Catch: java.lang.Throwable -> L5c
|
|
java.lang.String r6 = java.lang.String.valueOf(r6) // Catch: java.lang.Throwable -> L5c
|
|
java.lang.String r7 = java.lang.String.valueOf(r6) // Catch: java.lang.Throwable -> L5c
|
|
int r7 = r7.length() // Catch: java.lang.Throwable -> L5c
|
|
java.lang.StringBuilder r8 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L5c
|
|
int r7 = r7 + 35
|
|
r8.<init>(r7) // Catch: java.lang.Throwable -> L5c
|
|
java.lang.String r7 = "Exception while executing runnable "
|
|
r8.append(r7) // Catch: java.lang.Throwable -> L5c
|
|
r8.append(r6) // Catch: java.lang.Throwable -> L5c
|
|
java.lang.String r6 = r8.toString() // Catch: java.lang.Throwable -> L5c
|
|
r4.log(r5, r6, r3) // Catch: java.lang.Throwable -> L5c
|
|
L89:
|
|
r9.task = r2 // Catch: java.lang.Throwable -> L93
|
|
goto L2
|
|
L8d:
|
|
r9.task = r2 // Catch: java.lang.Throwable -> L93
|
|
throw r1 // Catch: java.lang.Throwable -> L93
|
|
L90:
|
|
r1 = move-exception
|
|
monitor-exit(r2)
|
|
throw r1 // Catch: java.lang.Throwable -> L93
|
|
L93:
|
|
r1 = move-exception
|
|
if (r0 == 0) goto L9d
|
|
java.lang.Thread r0 = java.lang.Thread.currentThread()
|
|
r0.interrupt()
|
|
L9d:
|
|
throw r1
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.google.common.util.concurrent.SequentialExecutor.QueueWorker.workOnQueue():void");
|
|
}
|
|
|
|
public final String toString() {
|
|
Runnable runnable = this.task;
|
|
if (runnable == null) {
|
|
String valueOf = String.valueOf(this.this$0.workerRunningState);
|
|
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 32);
|
|
sb.append("SequentialExecutorWorker{state=");
|
|
sb.append(valueOf);
|
|
sb.append(UrlTreeKt.componentParamSuffix);
|
|
return sb.toString();
|
|
}
|
|
String valueOf2 = String.valueOf(runnable);
|
|
StringBuilder sb2 = new StringBuilder(String.valueOf(valueOf2).length() + 34);
|
|
sb2.append("SequentialExecutorWorker{running=");
|
|
sb2.append(valueOf2);
|
|
sb2.append(UrlTreeKt.componentParamSuffix);
|
|
return sb2.toString();
|
|
}
|
|
}
|
|
|
|
public final String toString() {
|
|
int identityHashCode = System.identityHashCode(this);
|
|
String valueOf = String.valueOf(this.executor);
|
|
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 32);
|
|
sb.append("SequentialExecutor@");
|
|
sb.append(identityHashCode);
|
|
sb.append(UrlTreeKt.componentParamPrefix);
|
|
sb.append(valueOf);
|
|
sb.append(UrlTreeKt.componentParamSuffix);
|
|
return sb.toString();
|
|
}
|
|
}
|