Remove explicit fences

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-04-03 04:09:11 +02:00
parent 7a371fe616
commit 467decbb20
2 changed files with 4 additions and 13 deletions

View File

@ -3,7 +3,6 @@ package net.minestom.server.network.packet.server;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.lang.invoke.VarHandle;
import java.util.function.Supplier;
/**
@ -14,21 +13,18 @@ import java.util.function.Supplier;
@ApiStatus.Internal
public final class LazyPacket implements SendablePacket {
private final Supplier<ServerPacket> packetSupplier;
private ServerPacket packet;
private volatile ServerPacket packet;
public LazyPacket(@NotNull Supplier<@NotNull ServerPacket> packetSupplier) {
this.packetSupplier = packetSupplier;
}
public @NotNull ServerPacket packet() {
VarHandle.acquireFence();
ServerPacket packet = this.packet;
if (packet == null) {
synchronized (this) {
packet = this.packet;
if (packet == null) {
this.packet = packet = packetSupplier.get();
}
if (packet == null) this.packet = packet = packetSupplier.get();
}
}
return packet;

View File

@ -9,7 +9,6 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTCompoundLike;
import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound;
import java.lang.invoke.VarHandle;
import java.util.Arrays;
import java.util.function.UnaryOperator;
@ -153,7 +152,7 @@ final class TagHandlerImpl implements TagHandler {
private static final class Entry<T> {
final Tag<T> tag;
final T value; // TagHandler type for path-able tags
private NBT nbt;
volatile NBT nbt;
Entry(Tag<T> tag, T value) {
this.tag = tag;
@ -161,12 +160,8 @@ final class TagHandlerImpl implements TagHandler {
}
NBT updatedNbt() {
VarHandle.acquireFence();
NBT nbt = this.nbt;
if (nbt == null) {
this.nbt = nbt = tag.writeFunction.apply(value);
VarHandle.releaseFence();
}
if (nbt == null) this.nbt = nbt = tag.writeFunction.apply(value);
return nbt;
}
}