mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 22:47:41 +02:00
Remove explicit fences
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
7a371fe616
commit
467decbb20
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user