Initial commit
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
package com.bumptech.glide.load.engine.executor;
|
||||
|
||||
import android.os.Process;
|
||||
import android.os.StrictMode;
|
||||
import android.util.Log;
|
||||
import com.tencent.open.SocialConstants;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class GlideExecutor implements ExecutorService {
|
||||
private static final long b = TimeUnit.SECONDS.toMillis(10);
|
||||
private static volatile int c;
|
||||
private final ExecutorService a;
|
||||
|
||||
private static final class DefaultThreadFactory implements ThreadFactory {
|
||||
private final String a;
|
||||
final UncaughtThrowableStrategy b;
|
||||
final boolean c;
|
||||
private int d;
|
||||
|
||||
DefaultThreadFactory(String str, UncaughtThrowableStrategy uncaughtThrowableStrategy, boolean z) {
|
||||
this.a = str;
|
||||
this.b = uncaughtThrowableStrategy;
|
||||
this.c = z;
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ThreadFactory
|
||||
public synchronized Thread newThread(Runnable runnable) {
|
||||
Thread thread;
|
||||
thread = new Thread(runnable, "glide-" + this.a + "-thread-" + this.d) { // from class: com.bumptech.glide.load.engine.executor.GlideExecutor.DefaultThreadFactory.1
|
||||
@Override // java.lang.Thread, java.lang.Runnable
|
||||
public void run() {
|
||||
Process.setThreadPriority(9);
|
||||
if (DefaultThreadFactory.this.c) {
|
||||
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectNetwork().penaltyDeath().build());
|
||||
}
|
||||
try {
|
||||
super.run();
|
||||
} catch (Throwable th) {
|
||||
DefaultThreadFactory.this.b.a(th);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.d = this.d + 1;
|
||||
return thread;
|
||||
}
|
||||
}
|
||||
|
||||
public interface UncaughtThrowableStrategy {
|
||||
public static final UncaughtThrowableStrategy a;
|
||||
public static final UncaughtThrowableStrategy b;
|
||||
|
||||
static {
|
||||
new UncaughtThrowableStrategy() { // from class: com.bumptech.glide.load.engine.executor.GlideExecutor.UncaughtThrowableStrategy.1
|
||||
@Override // com.bumptech.glide.load.engine.executor.GlideExecutor.UncaughtThrowableStrategy
|
||||
public void a(Throwable th) {
|
||||
}
|
||||
};
|
||||
a = new UncaughtThrowableStrategy() { // from class: com.bumptech.glide.load.engine.executor.GlideExecutor.UncaughtThrowableStrategy.2
|
||||
@Override // com.bumptech.glide.load.engine.executor.GlideExecutor.UncaughtThrowableStrategy
|
||||
public void a(Throwable th) {
|
||||
if (th == null || !Log.isLoggable("GlideExecutor", 6)) {
|
||||
return;
|
||||
}
|
||||
Log.e("GlideExecutor", "Request threw uncaught throwable", th);
|
||||
}
|
||||
};
|
||||
new UncaughtThrowableStrategy() { // from class: com.bumptech.glide.load.engine.executor.GlideExecutor.UncaughtThrowableStrategy.3
|
||||
@Override // com.bumptech.glide.load.engine.executor.GlideExecutor.UncaughtThrowableStrategy
|
||||
public void a(Throwable th) {
|
||||
if (th != null) {
|
||||
throw new RuntimeException("Request threw uncaught throwable", th);
|
||||
}
|
||||
}
|
||||
};
|
||||
b = a;
|
||||
}
|
||||
|
||||
void a(Throwable th);
|
||||
}
|
||||
|
||||
GlideExecutor(ExecutorService executorService) {
|
||||
this.a = executorService;
|
||||
}
|
||||
|
||||
public static GlideExecutor a(int i, String str, UncaughtThrowableStrategy uncaughtThrowableStrategy) {
|
||||
return new GlideExecutor(new ThreadPoolExecutor(i, i, 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new DefaultThreadFactory(str, uncaughtThrowableStrategy, true)));
|
||||
}
|
||||
|
||||
public static GlideExecutor b(int i, String str, UncaughtThrowableStrategy uncaughtThrowableStrategy) {
|
||||
return new GlideExecutor(new ThreadPoolExecutor(i, i, 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new DefaultThreadFactory(str, uncaughtThrowableStrategy, false)));
|
||||
}
|
||||
|
||||
public static GlideExecutor c() {
|
||||
return a(1, "disk-cache", UncaughtThrowableStrategy.b);
|
||||
}
|
||||
|
||||
public static GlideExecutor d() {
|
||||
return b(a(), SocialConstants.PARAM_SOURCE, UncaughtThrowableStrategy.b);
|
||||
}
|
||||
|
||||
public static GlideExecutor e() {
|
||||
return new GlideExecutor(new ThreadPoolExecutor(0, Integer.MAX_VALUE, b, TimeUnit.MILLISECONDS, new SynchronousQueue(), new DefaultThreadFactory("source-unlimited", UncaughtThrowableStrategy.b, false)));
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public boolean awaitTermination(long j, TimeUnit timeUnit) throws InterruptedException {
|
||||
return this.a.awaitTermination(j, timeUnit);
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.Executor
|
||||
public void execute(Runnable runnable) {
|
||||
this.a.execute(runnable);
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> collection) throws InterruptedException {
|
||||
return this.a.invokeAll(collection);
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public <T> T invokeAny(Collection<? extends Callable<T>> collection) throws InterruptedException, ExecutionException {
|
||||
return (T) this.a.invokeAny(collection);
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public boolean isShutdown() {
|
||||
return this.a.isShutdown();
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public boolean isTerminated() {
|
||||
return this.a.isTerminated();
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public void shutdown() {
|
||||
this.a.shutdown();
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public List<Runnable> shutdownNow() {
|
||||
return this.a.shutdownNow();
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public Future<?> submit(Runnable runnable) {
|
||||
return this.a.submit(runnable);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.a.toString();
|
||||
}
|
||||
|
||||
public static GlideExecutor a(int i, UncaughtThrowableStrategy uncaughtThrowableStrategy) {
|
||||
return new GlideExecutor(new ThreadPoolExecutor(0, i, b, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new DefaultThreadFactory("animation", uncaughtThrowableStrategy, true)));
|
||||
}
|
||||
|
||||
public static GlideExecutor b() {
|
||||
return a(a() >= 4 ? 2 : 1, UncaughtThrowableStrategy.b);
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> collection, long j, TimeUnit timeUnit) throws InterruptedException {
|
||||
return this.a.invokeAll(collection, j, timeUnit);
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public <T> T invokeAny(Collection<? extends Callable<T>> collection, long j, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
return (T) this.a.invokeAny(collection, j, timeUnit);
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public <T> Future<T> submit(Runnable runnable, T t) {
|
||||
return this.a.submit(runnable, t);
|
||||
}
|
||||
|
||||
public static int a() {
|
||||
if (c == 0) {
|
||||
c = Math.min(4, RuntimeCompat.a());
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ExecutorService
|
||||
public <T> Future<T> submit(Callable<T> callable) {
|
||||
return this.a.submit(callable);
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
package com.bumptech.glide.load.engine.executor;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.StrictMode;
|
||||
import android.util.Log;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class RuntimeCompat {
|
||||
static int a() {
|
||||
int availableProcessors = Runtime.getRuntime().availableProcessors();
|
||||
return Build.VERSION.SDK_INT < 17 ? Math.max(b(), availableProcessors) : availableProcessors;
|
||||
}
|
||||
|
||||
private static int b() {
|
||||
File[] fileArr;
|
||||
StrictMode.ThreadPolicy allowThreadDiskReads = StrictMode.allowThreadDiskReads();
|
||||
try {
|
||||
File file = new File("/sys/devices/system/cpu/");
|
||||
final Pattern compile = Pattern.compile("cpu[0-9]+");
|
||||
fileArr = file.listFiles(new FilenameFilter() { // from class: com.bumptech.glide.load.engine.executor.RuntimeCompat.1
|
||||
@Override // java.io.FilenameFilter
|
||||
public boolean accept(File file2, String str) {
|
||||
return compile.matcher(str).matches();
|
||||
}
|
||||
});
|
||||
} catch (Throwable th) {
|
||||
try {
|
||||
if (Log.isLoggable("GlideRuntimeCompat", 6)) {
|
||||
Log.e("GlideRuntimeCompat", "Failed to calculate accurate cpu count", th);
|
||||
}
|
||||
StrictMode.setThreadPolicy(allowThreadDiskReads);
|
||||
fileArr = null;
|
||||
} finally {
|
||||
StrictMode.setThreadPolicy(allowThreadDiskReads);
|
||||
}
|
||||
}
|
||||
return Math.max(1, fileArr != null ? fileArr.length : 0);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user