mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 09:26:11 -04:00
fix deadlock and freeze
This commit is contained in:
parent
a3edf41a55
commit
43eb1ff4d1
@ -226,7 +226,7 @@ class SectionLight(
|
||||
update = true
|
||||
val blocks = section.blocks
|
||||
|
||||
blocks.lock?.acquire()
|
||||
section.chunk.lock.lock()
|
||||
val min = blocks.minPosition
|
||||
val max = blocks.maxPosition
|
||||
|
||||
@ -243,7 +243,7 @@ class SectionLight(
|
||||
}
|
||||
}
|
||||
}
|
||||
blocks.lock?.release()
|
||||
section.chunk.lock.unlock()
|
||||
section.chunk.light.sky.recalculate(section.sectionHeight)
|
||||
}
|
||||
|
||||
|
68
src/main/java/de/bixilon/minosoft/util/DebugLock.kt
Normal file
68
src/main/java/de/bixilon/minosoft/util/DebugLock.kt
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.util
|
||||
|
||||
import de.bixilon.kutil.concurrent.lock.Lock
|
||||
import de.bixilon.kutil.concurrent.lock.NobodyIsReadingException
|
||||
import de.bixilon.kutil.concurrent.lock.NobodyIsWritingException
|
||||
|
||||
|
||||
@Deprecated("kutil 1.25")
|
||||
class DebugLock : Lock {
|
||||
private val lock = Object()
|
||||
override var readers = 0
|
||||
private set
|
||||
override var locked = false
|
||||
private set
|
||||
|
||||
override fun acquire() {
|
||||
synchronized(lock) {
|
||||
while (locked) {
|
||||
lock.wait()
|
||||
}
|
||||
readers++
|
||||
// Exception("acquire").printStackTrace()
|
||||
lock.notifyAll()
|
||||
}
|
||||
}
|
||||
|
||||
override fun release() {
|
||||
synchronized(lock) {
|
||||
if (readers <= 0) throw NobodyIsReadingException()
|
||||
readers--
|
||||
// Exception("release").printStackTrace()
|
||||
lock.notifyAll()
|
||||
}
|
||||
}
|
||||
|
||||
override fun lock() {
|
||||
synchronized(lock) {
|
||||
while (locked || readers > 0) {
|
||||
lock.wait()
|
||||
}
|
||||
locked = true
|
||||
Exception("lock").printStackTrace()
|
||||
lock.notifyAll()
|
||||
}
|
||||
}
|
||||
|
||||
override fun unlock() {
|
||||
synchronized(lock) {
|
||||
if (!locked) throw NobodyIsWritingException()
|
||||
locked = false
|
||||
Exception("unlock").printStackTrace()
|
||||
lock.notifyAll()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user