Revert "[console] Enable atomicfu compiler", due to incorrect behavior of atomicfu. See #2329

This reverts commit 440122d4f9.
This commit is contained in:
Him188 2022-11-27 20:03:23 +00:00
parent 4b794feecb
commit 65e49283a2
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
2 changed files with 4 additions and 6 deletions

View File

@ -21,7 +21,6 @@ plugins {
`maven-publish`
id("me.him188.kotlin-jvm-blocking-bridge")
id("me.him188.kotlin-dynamic-delegation")
id("kotlinx-atomicfu")
}
version = Versions.console
@ -46,6 +45,7 @@ dependencies {
compileAndTestRuntime(project(":mirai-core-utils"))
compileAndTestRuntime(`kotlin-stdlib-jdk8`)
compileAndTestRuntime(`kotlinx-atomicfu`)
compileAndTestRuntime(`kotlinx-coroutines-core`)
compileAndTestRuntime(`kotlinx-serialization-core`)
compileAndTestRuntime(`kotlinx-serialization-json`)

View File

@ -10,6 +10,7 @@
package net.mamoe.mirai.console.util
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.loop
import kotlinx.coroutines.*
import net.mamoe.mirai.console.internal.util.runIgnoreException
import net.mamoe.mirai.utils.currentTimeMillis
@ -37,8 +38,7 @@ internal class TimedTask(
val job: Job = scope.launch(coroutineContext) {
// `delay` always checks for cancellation
while (true) {
val last = lastChangedTime.value
lastChangedTime.loop { last ->
val current = currentTimeMillis()
if (last == UNCHANGED) {
runIgnoreException<CancellationException> {
@ -46,7 +46,7 @@ internal class TimedTask(
} ?: return@launch
} else {
if (current - last > intervalMillis) {
if (!casLastChangedToUnchanged(last)) continue
if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop
action()
}
runIgnoreException<CancellationException> {
@ -55,8 +55,6 @@ internal class TimedTask(
}
}
}
private fun casLastChangedToUnchanged(last: Long) = lastChangedTime.compareAndSet(last, UNCHANGED)
}
internal fun CoroutineScope.launchTimedTask(