From 204089d53d72f7d66c487511c97998b060b14b34 Mon Sep 17 00:00:00 2001 From: themode Date: Sun, 2 Jan 2022 05:43:21 +0100 Subject: [PATCH] acquire/release --- .../server/network/packet/server/CachedPacket.java | 8 ++++---- .../minestom/server/network/packet/server/LazyPacket.java | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/minestom/server/network/packet/server/CachedPacket.java b/src/main/java/net/minestom/server/network/packet/server/CachedPacket.java index 750340b33..0714a0509 100644 --- a/src/main/java/net/minestom/server/network/packet/server/CachedPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/CachedPacket.java @@ -43,12 +43,12 @@ public final class CachedPacket implements SendablePacket { } public void invalidate() { - PACKET.setOpaque(this, null); + PACKET.setRelease(this, null); } public @NotNull ServerPacket packet() { @SuppressWarnings("unchecked") - SoftReference ref = (SoftReference) PACKET.getOpaque(this); + SoftReference ref = (SoftReference) PACKET.getAcquire(this); FramedPacket cache; if (ref != null && (cache = ref.get()) != null) return cache.packet(); // Avoid potential packet allocation @@ -64,11 +64,11 @@ public final class CachedPacket implements SendablePacket { if (!PacketUtils.CACHED_PACKET) return null; @SuppressWarnings("unchecked") - SoftReference ref = (SoftReference) PACKET.getOpaque(this); + SoftReference ref = (SoftReference) PACKET.getAcquire(this); FramedPacket cache; if (ref == null || (cache = ref.get()) == null) { cache = PacketUtils.allocateTrimmedPacket(packetSupplier.get()); - PACKET.setOpaque(this, new SoftReference<>(cache)); + PACKET.setRelease(this, new SoftReference<>(cache)); } return cache; } diff --git a/src/main/java/net/minestom/server/network/packet/server/LazyPacket.java b/src/main/java/net/minestom/server/network/packet/server/LazyPacket.java index d5b07c4ed..6a5672944 100644 --- a/src/main/java/net/minestom/server/network/packet/server/LazyPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/LazyPacket.java @@ -33,13 +33,13 @@ public final class LazyPacket implements SendablePacket { } public @NotNull ServerPacket packet() { - ServerPacket packet = (ServerPacket) PACKET.getOpaque(this); + ServerPacket packet = (ServerPacket) PACKET.getAcquire(this); if (packet == null) { synchronized (this) { - packet = this.packet; + packet = (ServerPacket) PACKET.getAcquire(this); if (packet == null) { packet = packetSupplier.get(); - PACKET.setOpaque(this, packet); + PACKET.setRelease(this, packet); } } }