mirror of
https://github.com/mamoe/mirai.git
synced 2024-12-28 09:30:10 +08:00
Revert "[console] Enable atomicfu compiler", due to incorrect behavior of atomicfu. See #2329
This reverts commit 440122d4f9
.
This commit is contained in:
parent
4b794feecb
commit
65e49283a2
@ -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`)
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user