Introduce new SpiderQueenWorker stub

This commit is contained in:
tarsin committed 2023-02-04 20:31:56 +08:00
1 parent 675e98fa1a
commit ef3d3e6443
2 files changed
+21

No files matched your search

@@ -68,6 +68,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import eu.kanade.tachiyomi.ui.reader.loader.PageLoader;
import kotlinx.coroutines.CoroutineScopeKt;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
@@ -131,6 +132,8 @@ public final class SpiderQueen implements Runnable {
private volatile Thread mQueenThread;
private ThreadPoolExecutor mWorkerPoolExecutor;
private int mWorkerCount;
private SpiderQueenWorker mWorkerScope;
private volatile int[] mPageStateArray;
// For download, when it go to mPageStateArray.size(), done
private volatile int mDownloadPage = -1;
@@ -149,6 +152,8 @@ public final class SpiderQueen implements Runnable {
mDecodeIndexArray[i] = -1;
}
mWorkerScope = new SpiderQueenWorker();
mWorkerPoolExecutor = new ThreadPoolExecutor(mWorkerMaxCount, mWorkerMaxCount,
0, TimeUnit.SECONDS, new LinkedBlockingDeque<>(),
new PriorityThreadFactory(SpiderWorker.class.getSimpleName(), Process.THREAD_PRIORITY_BACKGROUND));
@@ -377,6 +382,9 @@ public final class SpiderQueen implements Runnable {
synchronized (mWorkerLock) {
mWorkerLock.notifyAll();
}
CoroutineScopeKt.cancel(mWorkerScope, null);
mWorkerScope = null;
}
public int size() {
@@ -0,0 +1,13 @@
package com.hippo.ehviewer.spider
import com.hippo.ehviewer.Settings
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlin.coroutines.CoroutineContext
class SpiderQueenWorker : CoroutineScope {
private val maxParallelismSize = Settings.getMultiThreadDownload().coerceIn(1, 10)
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO.limitedParallelism(maxParallelismSize) + SupervisorJob()
}