mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
fix deadlock bugs when DefaultThreadPool
is running low on threads
This commit is contained in:
parent
e54064046b
commit
02bd482b46
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -14,7 +14,7 @@
|
||||
package de.bixilon.minosoft.gui.eros.util
|
||||
|
||||
import afester.javafx.svg.SvgLoader
|
||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||
import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker
|
||||
import de.bixilon.kutil.exception.ExceptionUtil.catchAll
|
||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||
import de.bixilon.kutil.shutdown.ShutdownManager
|
||||
@ -36,8 +36,10 @@ class JavaFXInitializer internal constructor() : Application() {
|
||||
|
||||
JavaFXUtil.JAVA_FX_THREAD = Thread.currentThread()
|
||||
JavaFXUtil.HOST_SERVICES = hostServices
|
||||
LATCH.inc(); DefaultThreadPool += { JavaFXUtil.MINOSOFT_LOGO = Image(Minosoft.MINOSOFT_ASSETS_MANAGER["minosoft:textures/icons/window_icon.png".toResourceLocation()]);LATCH.dec() }
|
||||
LATCH.inc(); DefaultThreadPool += { catchAll { JavaFXUtil.BIXILON_LOGO = SvgLoader().loadSvg(Minosoft.MINOSOFT_ASSETS_MANAGER["minosoft:textures/icons/bixilon_logo.svg".toResourceLocation()]) }; LATCH.dec() }
|
||||
val worker = UnconditionalWorker()
|
||||
worker += { JavaFXUtil.MINOSOFT_LOGO = Image(Minosoft.MINOSOFT_ASSETS_MANAGER["minosoft:textures/icons/window_icon.png".toResourceLocation()]) }
|
||||
worker += { catchAll { JavaFXUtil.BIXILON_LOGO = SvgLoader().loadSvg(Minosoft.MINOSOFT_ASSETS_MANAGER["minosoft:textures/icons/bixilon_logo.svg".toResourceLocation()]) } }
|
||||
worker.work(LATCH)
|
||||
|
||||
|
||||
Log.log(LogMessageType.JAVAFX, LogLevels.VERBOSE) { "Initialized JavaFX Toolkit!" }
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -18,7 +18,7 @@ import de.bixilon.kutil.cast.CastUtil.nullCast
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.collections.CollectionUtil.synchronizedMapOf
|
||||
import de.bixilon.kutil.collections.map.SynchronizedMap
|
||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||
import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker
|
||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||
import de.bixilon.kutil.reflection.KotlinReflection.kClass
|
||||
import de.bixilon.kutil.reflection.ReflectionUtil.realName
|
||||
@ -87,13 +87,11 @@ object PacketTypeRegistry {
|
||||
val c2sClassMap: SynchronizedMap<Class<out C2SPacket>, C2SPacketType> = synchronizedMapOf()
|
||||
val c2sStateMap: SynchronizedMap<ProtocolStates, MutableMap<String, C2SPacketType>> = synchronizedMapOf()
|
||||
|
||||
val innerLatch = CountUpAndDownLatch(1, latch)
|
||||
val worker = UnconditionalWorker()
|
||||
for (info in ClassPath.from(classLoader).getTopLevelClassesRecursive(PacketsRoot::class.java.packageName)) {
|
||||
innerLatch.inc()
|
||||
DefaultThreadPool += { loadClass(s2cClassMap, s2cStateMap, c2sClassMap, c2sStateMap, info); innerLatch.dec() }
|
||||
worker += { loadClass(s2cClassMap, s2cStateMap, c2sClassMap, c2sStateMap, info) }
|
||||
}
|
||||
innerLatch.dec()
|
||||
innerLatch.await()
|
||||
worker.work(latch)
|
||||
this.S2C_CLASS_MAP = s2cClassMap
|
||||
this.S2C_STATE_MAP = s2cStateMap
|
||||
this.C2S_CLASS_MAP = c2sClassMap
|
||||
|
@ -15,7 +15,7 @@ package de.bixilon.minosoft.util
|
||||
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.collections.primitive.Clearable
|
||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||
import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker
|
||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||
import de.bixilon.kutil.reflection.generic.GenericUtil
|
||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
@ -74,10 +74,11 @@ object RegistriesUtil {
|
||||
}
|
||||
|
||||
fun Registries.postInit(latch: CountUpAndDownLatch) {
|
||||
val worker = UnconditionalWorker()
|
||||
for (field in types.values) {
|
||||
latch.inc()
|
||||
DefaultThreadPool += { field.get(this).unsafeCast<Registry<*>>().postInit(this); latch.dec() }
|
||||
worker += { field.get(this).unsafeCast<Registry<*>>().postInit(this) }
|
||||
}
|
||||
worker.work(latch)
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user