Skip to content

Commit

Permalink
fix: use concurrent data structure in some places
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Dec 17, 2024
1 parent e3f7434 commit 9366329
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.allaymc.server.world.chunk;

import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.PlatformDependent;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -39,7 +39,6 @@ public class AllayChunk implements Chunk {

protected final StampedLock blockLock;
protected final StampedLock heightAndBiomeLock;
// No need to use concurrent-safe set as addChunkLoader() & removeChunkLoader() are only used in AllayChunkService which is single-thread
protected final Set<ChunkLoader> chunkLoaders;
protected final Queue<ChunkPacketEntry> chunkPacketQueue;

Expand Down Expand Up @@ -67,7 +66,7 @@ private static void checkXYZ(int x, int y, int z) {
this.unsafeChunk = unsafeChunk;
this.blockLock = new StampedLock();
this.heightAndBiomeLock = new StampedLock();
this.chunkLoaders = new ObjectOpenHashSet<>();
this.chunkLoaders = Sets.newConcurrentHashSet();
this.chunkPacketQueue = PlatformDependent.newMpscQueue();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.allaymc.server.world.service;

import io.netty.util.internal.PlatformDependent;
import lombok.RequiredArgsConstructor;
import org.allaymc.api.block.data.BlockFace;
import org.allaymc.api.block.dto.BlockStateWithPos;
Expand All @@ -11,7 +12,10 @@
import org.allaymc.api.world.service.BlockUpdateService;
import org.joml.Vector3ic;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand All @@ -23,7 +27,7 @@ public class AllayBlockUpdateService implements BlockUpdateService {

protected final Dimension dimension;
protected final Map<Vector3ic, Long> scheduledUpdates = new ConcurrentHashMap<>();
protected final Queue<NeighborUpdate> neighborUpdates = new LinkedList<>();
protected final Queue<NeighborUpdate> neighborUpdates = PlatformDependent.newMpscQueue();

public void tick(long tick) {
tickScheduledUpdates(tick);
Expand Down

0 comments on commit 9366329

Please sign in to comment.