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.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.lang.invoke.VarHandle;
import java.util.function.Supplier; import java.util.function.Supplier;
/** /**
@ -14,21 +13,18 @@ import java.util.function.Supplier;
@ApiStatus.Internal @ApiStatus.Internal
public final class LazyPacket implements SendablePacket { public final class LazyPacket implements SendablePacket {
private final Supplier<ServerPacket> packetSupplier; private final Supplier<ServerPacket> packetSupplier;
private ServerPacket packet; private volatile ServerPacket packet;
public LazyPacket(@NotNull Supplier<@NotNull ServerPacket> packetSupplier) { public LazyPacket(@NotNull Supplier<@NotNull ServerPacket> packetSupplier) {
this.packetSupplier = packetSupplier; this.packetSupplier = packetSupplier;
} }
public @NotNull ServerPacket packet() { public @NotNull ServerPacket packet() {
VarHandle.acquireFence();
ServerPacket packet = this.packet; ServerPacket packet = this.packet;
if (packet == null) { if (packet == null) {
synchronized (this) { synchronized (this) {
packet = this.packet; packet = this.packet;
if (packet == null) { if (packet == null) this.packet = packet = packetSupplier.get();
this.packet = packet = packetSupplier.get();
}
} }
} }
return packet; 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.NBTCompoundLike;
import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound; import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound;
import java.lang.invoke.VarHandle;
import java.util.Arrays; import java.util.Arrays;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
@ -153,7 +152,7 @@ final class TagHandlerImpl implements TagHandler {
private static final class Entry<T> { private static final class Entry<T> {
final Tag<T> tag; final Tag<T> tag;
final T value; // TagHandler type for path-able tags final T value; // TagHandler type for path-able tags
private NBT nbt; volatile NBT nbt;
Entry(Tag<T> tag, T value) { Entry(Tag<T> tag, T value) {
this.tag = tag; this.tag = tag;
@ -161,12 +160,8 @@ final class TagHandlerImpl implements TagHandler {
} }
NBT updatedNbt() { NBT updatedNbt() {
VarHandle.acquireFence();
NBT nbt = this.nbt; NBT nbt = this.nbt;
if (nbt == null) { if (nbt == null) this.nbt = nbt = tag.writeFunction.apply(value);
this.nbt = nbt = tag.writeFunction.apply(value);
VarHandle.releaseFence();
}
return nbt; return nbt;
} }
} }