improve performance of some biome stuff, improve performance of new chunk format

This commit is contained in:
Bixilon 2021-11-14 20:49:36 +01:00
parent 74791305f6
commit 7249367b04
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
18 changed files with 425 additions and 169 deletions

View File

@ -1 +0,0 @@
--enable-preview

View File

@ -169,6 +169,7 @@ class Chunk(
fun buildBiomeCache() {
val cacheBiomeAccessor = connection.world.cacheBiomeAccessor ?: return
check(!biomesInitialized) { "Biome cache already initialized!" }
check(neighboursLoaded)
// val neighbours = connection.world.getChunkNeighbours(chunkPosition)
for ((sectionIndex, section) in sections!!.withIndex()) {
@ -186,8 +187,17 @@ class Chunk(
override fun getBiome(blockPosition: Vec3i): Biome? {
if (connection.world.cacheBiomeAccessor != null) {
return get(blockPosition.sectionHeight)?.biomes?.get(blockPosition.x, blockPosition.sectionHeight, blockPosition.z)
val sectionHeight = blockPosition.sectionHeight
return get(sectionHeight)?.biomes?.get(blockPosition.x, sectionHeight, blockPosition.z)
}
return biomeSource?.getBiome(blockPosition.inChunkPosition)
}
override fun getBiome(x: Int, y: Int, z: Int): Biome? {
if (connection.world.cacheBiomeAccessor != null) {
val sectionHeight = y.sectionHeight
return get(sectionHeight)?.biomes?.get(x, sectionHeight, z)
}
return biomeSource?.getBiome(x and 0x0F, y, z and 0x0F)
}
}

View File

@ -39,9 +39,13 @@ class ChunkSection(
constructor(registries: Registries) : this(RegistrySectionDataProvider<BlockState?>(registries.blockStateRegistry.unsafeCast()), RegistrySectionDataProvider(registries.biomeRegistry), SectionDataProvider(), IntArray(ProtocolDefinition.BLOCKS_PER_SECTION))
fun tick(connection: PlayConnection, chunkPosition: Vec2i, sectionHeight: Int) {
if (blockEntities.isEmpty) {
return
}
acquire()
for ((index, blockEntity) in blockEntities.withIndex()) {
blockEntity ?: continue
var blockEntity: BlockEntity?
for (index in 0 until ProtocolDefinition.BLOCKS_PER_SECTION) {
blockEntity = blockEntities[index] ?: continue
val position = Vec3i.of(chunkPosition, sectionHeight, index.indexPosition)
val blockState = blocks[index] ?: continue
blockEntity.tick(connection, blockState, position)
@ -86,8 +90,14 @@ class ChunkSection(
}
fun buildBiomeCache(chunkPosition: Vec2i, sectionHeight: Int, biomeAccessor: BiomeAccessor) {
for (blockIndex in 0 until ProtocolDefinition.BLOCKS_PER_SECTION) {
biomes[blockIndex] = biomeAccessor.getBiome(Vec3i.of(chunkPosition, sectionHeight, blockIndex.indexPosition))!!
val blockOffset = Vec3i.of(chunkPosition, sectionHeight)
val x = blockOffset.x
val y = blockOffset.y
val z = blockOffset.z
val biomes: Array<Biome?> = arrayOfNulls(ProtocolDefinition.BLOCKS_PER_SECTION)
for (index in 0 until ProtocolDefinition.BLOCKS_PER_SECTION) {
biomes[index] = biomeAccessor.getBiome(x + (index and 0x0F), y + ((index shr 8) and 0x0F), z + ((index shr 4) and 0x0F)) //!!
}
this.biomes.setData(biomes.unsafeCast())
}
}

View File

@ -149,6 +149,10 @@ class World(
return biomeAccessor.getBiome(blockPosition)
}
override fun getBiome(x: Int, y: Int, z: Int): Biome? {
return biomeAccessor.getBiome(x, y, z)
}
fun tick() {
for ((chunkPosition, chunk) in chunks.toSynchronizedMap()) {
chunk.tick(connection, chunkPosition)

View File

@ -19,5 +19,9 @@ import glm_.vec3.Vec3i
interface BiomeAccessor {
fun getBiome(blockPosition: Vec3i): Biome?
fun getBiome(blockPosition: Vec3i): Biome? {
return getBiome(blockPosition.x, blockPosition.y, blockPosition.z)
}
fun getBiome(x: Int, y: Int, z: Int): Biome?
}

View File

@ -13,22 +13,19 @@
package de.bixilon.minosoft.data.world.biome.accessor
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.registries.biomes.Biome
import de.bixilon.minosoft.data.world.World
import de.bixilon.minosoft.data.world.biome.noise.FuzzyNoiseBiomeCalculator
import de.bixilon.minosoft.data.world.biome.source.SpatialBiomeArray
import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition
import glm_.vec3.Vec3i
class NoiseBiomeAccessor(private val world: World) : BiomeAccessor {
override fun getBiome(blockPosition: Vec3i): Biome? {
val y = if (world.dimension?.supports3DBiomes == true) {
blockPosition.y
override fun getBiome(x: Int, y: Int, z: Int): Biome? {
val biomeY = if (world.dimension?.supports3DBiomes == true) {
y
} else {
0
}
/*
if (Minosoft.config.config.game.graphics.fastBiomeNoise) {
world[blockPosition.chunkPosition]?.biomeSource?.let {
if (it !is SpatialBiomeArray) {
@ -37,10 +34,12 @@ class NoiseBiomeAccessor(private val world: World) : BiomeAccessor {
val x: Int = (blockPosition.x and 0x0F) / 4
val z: Int = (blockPosition.z and 0x0F) / 4
return it.data[(y / 4) * 16 + (z * 4 + x)]
return it.data[(biomeY / 4) * 16 + (z * 4 + x)]
}
return null
}
return FuzzyNoiseBiomeCalculator.getBiome(world.hashedSeed, blockPosition.x, y, blockPosition.z, world)
*/
return FuzzyNoiseBiomeCalculator.getBiome(world.hashedSeed, x, biomeY, z, world)
}
}

View File

@ -22,4 +22,8 @@ object NullBiomeAccessor : BiomeAccessor {
override fun getBiome(blockPosition: Vec3i): Biome? {
return null
}
override fun getBiome(x: Int, y: Int, z: Int): Biome? {
return null
}
}

View File

@ -21,6 +21,10 @@ import glm_.vec3.Vec3i
class WorldBiomeAccessor(val world: World) : BiomeAccessor {
override fun getBiome(x: Int, y: Int, z: Int): Biome? {
return getBiome(Vec3i(x, y, z)) // ToDo
}
override fun getBiome(blockPosition: Vec3i): Biome? {
return world[blockPosition.chunkPosition]?.getBiome(blockPosition.inChunkPosition)
}

View File

@ -1,11 +1,9 @@
package de.bixilon.minosoft.data.world.biome.noise
import de.bixilon.minosoft.data.registries.biomes.Biome
import de.bixilon.minosoft.data.world.World
import de.bixilon.minosoft.util.MMath.square
import glm_.vec2.Vec2i
import glm_.vec3.Vec3i
object FuzzyNoiseBiomeCalculator {
@ -25,27 +23,27 @@ object FuzzyNoiseBiomeCalculator {
var s = 0
var g = Double.POSITIVE_INFINITY
fun calculateFraction(a: Int, mask: Int, first: Int, second: Double): Pair<Int, Double> {
(a and mask == 0).let {
return Pair(
if (it) first else first + 1,
if (it) second else second - 1.0
)
}
}
fun checkMask(mask: Int, value: Int): Int {
return if (s and mask == 0) {
value
} else {
value + 1
}
}
for (i in 0 until 8) {
val (u, xFraction) = calculateFraction(i, 0x04, p, d)
val (v, yFraction) = calculateFraction(i, 0x02, q, e)
val (w, zFraction) = calculateFraction(i, 0x01, r, f)
var u = p
var xFraction = d
if (i and 0x04 != 0) {
u++
xFraction -= 1.0
}
var v = q
var yFraction = e
if (i and 0x02 != 0) {
v++
yFraction -= 1.0
}
var w = r
var zFraction = f
if (i and 0x01 != 0) {
w++
zFraction -= 1.0
}
val d3 = calculateFiddle(seed, u, v, w, xFraction, yFraction, zFraction)
@ -55,11 +53,20 @@ object FuzzyNoiseBiomeCalculator {
}
}
val biomeX = checkMask(0x04, p)
val biomeY = checkMask(0x02, q)
val biomeZ = checkMask(0x01, r)
var biomeX = p
if (s and 0x04 != 0) {
biomeX++
}
var biomeY = q
if (s and 0x02 != 0) {
biomeY++
}
var biomeZ = r
if (s and 0x01 != 0) {
biomeZ++
}
return world[Vec2i(biomeX shr 2, biomeZ shr 2)]?.biomeSource?.getBiome(Vec3i(biomeX, biomeY, biomeZ))
return world[Vec2i(biomeX shr 2, biomeZ shr 2)]?.biomeSource?.getBiome(biomeX, biomeY, biomeZ)
}
private fun calculateFiddle(seed: Long, x: Int, y: Int, z: Int, xFraction: Double, yFraction: Double, zFraction: Double): Double {

View File

@ -18,5 +18,9 @@ import glm_.vec3.Vec3i
interface BiomeSource {
fun getBiome(position: Vec3i): Biome?
fun getBiome(position: Vec3i): Biome? {
return getBiome(position.x, position.y, position.z)
}
fun getBiome(x: Int, y: Int, z: Int): Biome?
}

View File

@ -18,6 +18,10 @@ import glm_.vec3.Vec3i
class DummyBiomeSource(private val biome: Biome) : BiomeSource {
override fun getBiome(x: Int, y: Int, z: Int): Biome? {
return biome
}
override fun getBiome(position: Vec3i): Biome {
return biome
}

View File

@ -15,14 +15,13 @@ package de.bixilon.minosoft.data.world.biome.source
import de.bixilon.minosoft.data.registries.biomes.Biome
import de.bixilon.minosoft.util.MMath
import glm_.vec3.Vec3i
class SpatialBiomeArray(val data: Array<Biome>) : BiomeSource {
override fun getBiome(position: Vec3i): Biome {
val index = (MMath.clamp(position.y, 0, Y_BIT_MASK)) shl X_SECTION_COUNT + X_SECTION_COUNT or
((position.z and X_BIT_MASK) shl X_SECTION_COUNT) or
(position.x and X_BIT_MASK)
override fun getBiome(x: Int, y: Int, z: Int): Biome? {
val index = (MMath.clamp(y, 0, Y_BIT_MASK)) shl X_SECTION_COUNT + X_SECTION_COUNT or
((z and X_BIT_MASK) shl X_SECTION_COUNT) or
(x and X_BIT_MASK)
return this.data[index]
}

View File

@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.world.biome.source
import de.bixilon.minosoft.data.registries.biomes.Biome
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import glm_.vec3.Vec3i
class XZBiomeArray(private val biomes: Array<Biome>) : BiomeSource {
@ -23,7 +22,7 @@ class XZBiomeArray(private val biomes: Array<Biome>) : BiomeSource {
check(biomes.size == ProtocolDefinition.SECTION_WIDTH_X * ProtocolDefinition.SECTION_WIDTH_Z) { "Biome array size does not match the xz block count!" }
}
override fun getBiome(position: Vec3i): Biome {
return biomes[(position.x and 0x0F) or ((position.z and 0x0F) shl 4)]
override fun getBiome(x: Int, y: Int, z: Int): Biome {
return biomes[(x and 0x0F) or ((z and 0x0F) shl 4)]
}
}

View File

@ -24,6 +24,8 @@ open class SectionDataProvider<T>(
protected val lock = SemaphoreLock() // lock while reading (blocks writing)
var count: Int = 0
private set
val isEmpty: Boolean
get() = count == 0
init {
recalculateCount()

View File

@ -258,6 +258,14 @@ object VecUtil {
val Vec3i.center: Vec3d
get() = Vec3d(x + 0.5, y + 0.5, z + 0.5)
fun Vec3i.Companion.of(chunkPosition: Vec2i, sectionHeight: Int): Vec3i {
return Vec3i(
chunkPosition.x * ProtocolDefinition.SECTION_WIDTH_X,
sectionHeight * ProtocolDefinition.SECTION_HEIGHT_Y,
chunkPosition.y * ProtocolDefinition.SECTION_WIDTH_Z
) // ToDo: Confirm
}
fun Vec3i.Companion.of(chunkPosition: Vec2i, sectionHeight: Int, inChunkSectionPosition: Vec3i): Vec3i {
return Vec3i(
chunkPosition.x * ProtocolDefinition.SECTION_WIDTH_X + inChunkSectionPosition.x,

View File

@ -25,6 +25,7 @@ import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.data.text.TextFormattable
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.collections.SemaphoreMap
import de.bixilon.minosoft.util.collections.SynchronizedMap
import de.bixilon.minosoft.util.enum.AliasableEnum
import de.bixilon.minosoft.util.json.JSONSerializer
@ -104,11 +105,17 @@ object KUtil {
}
fun <K, V> Map<K, V>.toSynchronizedMap(): SynchronizedMap<K, V> {
return if (this is SynchronizedMap<*, *>) {
return if (this is SemaphoreMap<*, *>) {
lock.acquire()
val map: SynchronizedMap<K, V> = SynchronizedMap(this.toMutableMap()).unsafeCast()
lock.release()
map
} else if (this is SynchronizedMap<*, *>) {
val map: SynchronizedMap<K, V>
synchronized(this.lock) {
map = SynchronizedMap(this.toMutableMap()).unsafeCast()
}
map
} else {
synchronizedCopy { SynchronizedMap(this.toMutableMap()) }
}

View File

@ -0,0 +1,223 @@
/*
* Minosoft
* Copyright (C) 2021 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.collections
import de.bixilon.minosoft.util.KUtil.toSynchronizedList
import de.bixilon.minosoft.util.KUtil.toSynchronizedSet
import de.bixilon.minosoft.util.SemaphoreLock
import java.util.function.BiConsumer
import java.util.function.BiFunction
import java.util.function.Function
class SemaphoreMap<K, V>(
private val original: MutableMap<K, V>,
) : MutableMap<K, V> {
val lock = SemaphoreLock()
override val size: Int
get() {
lock.acquire()
val returnValue = original.size
lock.release()
return returnValue
}
override fun containsKey(key: K): Boolean {
lock.acquire()
val returnValue = original.containsKey(key)
lock.release()
return returnValue
}
override fun containsValue(value: V): Boolean {
lock.acquire()
val returnValue = original.containsValue(value)
lock.release()
return returnValue
}
override fun get(key: K): V? {
lock.acquire()
val returnValue = original[key]
lock.release()
return returnValue
}
override fun isEmpty(): Boolean {
lock.acquire()
val returnValue = original.isEmpty()
lock.release()
return returnValue
}
override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
get() {
lock.acquire()
val returnValue = original.entries.toSynchronizedSet()
lock.release()
return returnValue
}
override val keys: MutableSet<K>
get() {
lock.acquire()
val returnValue = original.keys.toSynchronizedSet()
lock.release()
return returnValue
}
override val values: MutableCollection<V>
get() {
lock.acquire()
val returnValue = original.values.toSynchronizedList()
lock.release()
return returnValue
}
override fun clear() {
lock.lock()
original.clear()
lock.unlock()
}
override fun put(key: K, value: V): V? {
lock.lock()
val returnValue = original.put(key, value)
lock.unlock()
return returnValue
}
override fun putAll(from: Map<out K, V>) {
lock.lock()
val returnValue = original.putAll(from)
lock.unlock()
return returnValue
}
override fun remove(key: K): V? {
lock.lock()
val returnValue = original.remove(key)
lock.unlock()
return returnValue
}
override fun hashCode(): Int {
lock.acquire()
val returnValue = original.hashCode()
lock.release()
return returnValue
}
override fun toString(): String {
lock.acquire()
val returnValue = original.toString()
lock.release()
return returnValue
}
override fun putIfAbsent(key: K, value: V): V? {
lock.lock()
val returnValue = original.putIfAbsent(key, value)
lock.unlock()
return returnValue
}
override fun forEach(action: BiConsumer<in K, in V>) {
lock.acquire()
val returnValue = original.forEach(action)
lock.release()
return returnValue
}
override fun getOrDefault(key: K, defaultValue: V): V {
lock.acquire()
val returnValue = original.getOrDefault(key, defaultValue)
lock.release()
return returnValue
}
fun getOrPut(key: K, defaultValue: () -> V): V {
lock.lock()
var value = original[key]
val returnValue = if (value == null) {
value = defaultValue()
original[key] = value
value
} else {
value
}
lock.unlock()
return returnValue
}
override fun remove(key: K, value: V): Boolean {
lock.lock()
val returnValue = original.remove(key, value)
lock.unlock()
return returnValue
}
override fun equals(other: Any?): Boolean {
lock.acquire()
val returnValue = original == other
lock.release()
return returnValue
}
override fun replaceAll(function: BiFunction<in K, in V, out V>) {
lock.lock()
val returnValue = original.replaceAll(function)
lock.unlock()
return returnValue
}
override fun compute(key: K, remappingFunction: BiFunction<in K, in V?, out V?>): V? {
lock.acquire()
val returnValue = original.compute(key, remappingFunction)
lock.release()
return returnValue
}
override fun computeIfAbsent(key: K, mappingFunction: Function<in K, out V>): V {
lock.acquire()
val returnValue = original.computeIfAbsent(key, mappingFunction)
lock.release()
return returnValue
}
override fun computeIfPresent(key: K, remappingFunction: BiFunction<in K, in V, out V?>): V? {
lock.acquire()
val returnValue = original.computeIfPresent(key, remappingFunction)
lock.release()
return returnValue
}
override fun replace(key: K, value: V): V? {
lock.lock()
val returnValue = original.replace(key, value)
lock.unlock()
return returnValue
}
override fun merge(key: K, value: V, remappingFunction: BiFunction<in V, in V, out V?>): V? {
lock.lock()
val returnValue = original.merge(key, value, remappingFunction)
lock.unlock()
return returnValue
}
override fun replace(key: K, oldValue: V, newValue: V): Boolean {
lock.lock()
val returnValue = original.replace(key, oldValue, newValue)
lock.unlock()
return returnValue
}
}

View File

@ -15,7 +15,6 @@ package de.bixilon.minosoft.util.collections
import de.bixilon.minosoft.util.KUtil.toSynchronizedList
import de.bixilon.minosoft.util.KUtil.toSynchronizedSet
import de.bixilon.minosoft.util.SemaphoreLock
import java.util.function.BiConsumer
import java.util.function.BiFunction
import java.util.function.Function
@ -23,201 +22,171 @@ import java.util.function.Function
class SynchronizedMap<K, V>(
private val original: MutableMap<K, V>,
) : MutableMap<K, V> {
internal val lock = SemaphoreLock()
internal val lock = Object()
override val size: Int
get() {
lock.acquire()
val returnValue = original.size
lock.release()
return returnValue
}
get() = synchronized(lock) { original.size }
override fun containsKey(key: K): Boolean {
lock.acquire()
val returnValue = original.containsKey(key)
lock.release()
return returnValue
synchronized(lock) {
return original.containsKey(key)
}
}
override fun containsValue(value: V): Boolean {
lock.acquire()
val returnValue = original.containsValue(value)
lock.release()
return returnValue
synchronized(lock) {
return original.containsValue(value)
}
}
override fun get(key: K): V? {
lock.acquire()
val returnValue = original[key]
lock.release()
return returnValue
synchronized(lock) {
return original[key]
}
}
override fun isEmpty(): Boolean {
lock.acquire()
val returnValue = original.isEmpty()
lock.release()
return returnValue
synchronized(lock) {
return original.isEmpty()
}
}
override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
get() {
lock.acquire()
val returnValue = original.entries.toSynchronizedSet()
lock.release()
return returnValue
synchronized(lock) {
return original.entries.toSynchronizedSet()
}
}
override val keys: MutableSet<K>
get() {
lock.acquire()
val returnValue = original.keys.toSynchronizedSet()
lock.release()
return returnValue
synchronized(lock) {
return original.keys.toSynchronizedSet()
}
}
override val values: MutableCollection<V>
get() {
lock.acquire()
val returnValue = original.values.toSynchronizedList()
lock.release()
return returnValue
synchronized(lock) {
return original.values.toSynchronizedList()
}
}
override fun clear() {
lock.lock()
synchronized(lock) {
original.clear()
lock.unlock()
}
}
override fun put(key: K, value: V): V? {
lock.lock()
val returnValue = original.put(key, value)
lock.unlock()
return returnValue
synchronized(lock) {
return original.put(key, value)
}
}
override fun putAll(from: Map<out K, V>) {
lock.lock()
val returnValue = original.putAll(from)
lock.unlock()
return returnValue
synchronized(lock) {
return original.putAll(from)
}
}
override fun remove(key: K): V? {
lock.lock()
val returnValue = original.remove(key)
lock.unlock()
return returnValue
synchronized(lock) {
return original.remove(key)
}
}
override fun hashCode(): Int {
lock.acquire()
val returnValue = original.hashCode()
lock.release()
return returnValue
synchronized(lock) {
return original.hashCode()
}
}
override fun toString(): String {
lock.acquire()
val returnValue = original.toString()
lock.release()
return returnValue
synchronized(lock) {
return original.toString()
}
}
override fun putIfAbsent(key: K, value: V): V? {
lock.lock()
val returnValue = original.putIfAbsent(key, value)
lock.unlock()
return returnValue
synchronized(lock) {
return original.putIfAbsent(key, value)
}
}
override fun forEach(action: BiConsumer<in K, in V>) {
lock.acquire()
val returnValue = original.forEach(action)
lock.release()
return returnValue
synchronized(lock) {
return original.forEach(action)
}
}
override fun getOrDefault(key: K, defaultValue: V): V {
lock.acquire()
val returnValue = original.getOrDefault(key, defaultValue)
lock.release()
return returnValue
synchronized(lock) {
return original.getOrDefault(key, defaultValue)
}
}
fun getOrPut(key: K, defaultValue: () -> V): V {
lock.lock()
var value = original[key]
val returnValue = if (value == null) {
synchronized(lock) {
var value = get(key)
return if (value == null) {
value = defaultValue()
original[key] = value
put(key, value)
value
} else {
value
}
lock.unlock()
return returnValue
}
}
override fun remove(key: K, value: V): Boolean {
lock.lock()
val returnValue = original.remove(key, value)
lock.unlock()
return returnValue
synchronized(lock) {
return original.remove(key, value)
}
}
override fun equals(other: Any?): Boolean {
lock.acquire()
val returnValue = original == other
lock.release()
return returnValue
synchronized(lock) {
return original == other
}
}
override fun replaceAll(function: BiFunction<in K, in V, out V>) {
lock.lock()
val returnValue = original.replaceAll(function)
lock.unlock()
return returnValue
synchronized(lock) {
return original.replaceAll(function)
}
}
override fun compute(key: K, remappingFunction: BiFunction<in K, in V?, out V?>): V? {
lock.acquire()
val returnValue = original.compute(key, remappingFunction)
lock.release()
return returnValue
synchronized(lock) {
return original.compute(key, remappingFunction)
}
}
override fun computeIfAbsent(key: K, mappingFunction: Function<in K, out V>): V {
lock.acquire()
val returnValue = original.computeIfAbsent(key, mappingFunction)
lock.release()
return returnValue
synchronized(lock) {
return original.computeIfAbsent(key, mappingFunction)
}
}
override fun computeIfPresent(key: K, remappingFunction: BiFunction<in K, in V, out V?>): V? {
lock.acquire()
val returnValue = original.computeIfPresent(key, remappingFunction)
lock.release()
return returnValue
synchronized(lock) {
return original.computeIfPresent(key, remappingFunction)
}
}
override fun replace(key: K, value: V): V? {
lock.lock()
val returnValue = original.replace(key, value)
lock.unlock()
return returnValue
synchronized(lock) {
return original.replace(key, value)
}
}
override fun merge(key: K, value: V, remappingFunction: BiFunction<in V, in V, out V?>): V? {
lock.lock()
val returnValue = original.merge(key, value, remappingFunction)
lock.unlock()
return returnValue
synchronized(lock) {
return original.merge(key, value, remappingFunction)
}
}
override fun replace(key: K, oldValue: V, newValue: V): Boolean {
lock.lock()
val returnValue = original.replace(key, oldValue, newValue)
lock.unlock()
return returnValue
synchronized(lock) {
return original.replace(key, oldValue, newValue)
}
}
}