Revert "Replace all atomic usage"

This reverts commit a6c204e444.
This commit is contained in:
tarsin committed 2023-02-22 16:10:13 +08:00
1 parent f51e585d8d
commit 8b9985a7dc
1 file changed
+10 -10
@@ -42,7 +42,6 @@ import com.hippo.unifile.UniFile
import com.hippo.util.ExceptionUtils
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.launchNonCancellable
import kotlinx.atomicfu.atomic
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -58,6 +57,7 @@ import kotlinx.coroutines.sync.withPermit
import moe.tarsin.coroutines.runSuspendCatching
import okhttp3.executeAsync
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicInteger
class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineScope {
override val coroutineContext = Dispatchers.IO + Job()
@@ -69,8 +69,8 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
val mSpiderDen: SpiderDen = SpiderDen(galleryInfo)
val mPagePercentMap = ConcurrentHashMap<Int, Float>()
private val mPageStateLock = Any()
private val mDownloadedPages = atomic(0)
private val mFinishedPages = atomic(0)
private val mDownloadedPages = AtomicInteger(0)
private val mFinishedPages = AtomicInteger(0)
private val mPageErrorMap = ConcurrentHashMap<Int, String>()
private val mSpiderListeners: MutableList<OnSpiderListener> = ArrayList()
@@ -115,8 +115,8 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
mSpiderListeners.forEach {
it.onPageSuccess(
index,
mFinishedPages.value,
mDownloadedPages.value,
mFinishedPages.get(),
mDownloadedPages.get(),
mPageStateArray.size
)
}
@@ -129,8 +129,8 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
it.onPageFailure(
index,
error,
mFinishedPages.value,
mDownloadedPages.value,
mFinishedPages.get(),
mDownloadedPages.get(),
mPageStateArray.size
)
}
@@ -141,8 +141,8 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
synchronized(mSpiderListeners) {
mSpiderListeners.forEach {
it.onFinish(
mFinishedPages.value,
mDownloadedPages.value,
mFinishedPages.get(),
mDownloadedPages.get(),
mPageStateArray.size
)
}
@@ -471,7 +471,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
} else if (state == STATE_FINISHED) {
notifyPageSuccess(index)
}
if (mDownloadedPages.value == size) notifyAllPageDownloaded()
if (mDownloadedPages.get() == size) notifyAllPageDownloaded()
}
@IntDef(MODE_READ, MODE_DOWNLOAD)