Skip to content

Commit 1879333

Browse files
committed
fix: don't lock for chunk packets/section write on main thread
1 parent 7160792 commit 1879333

File tree

1 file changed

+10
-0
lines changed
  • worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter

1 file changed

+10
-0
lines changed

worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fastasyncworldedit.bukkit.FaweBukkitWorld;
44
import com.fastasyncworldedit.core.FAWEPlatformAdapterImpl;
5+
import com.fastasyncworldedit.core.Fawe;
56
import com.fastasyncworldedit.core.math.IntPair;
67
import com.fastasyncworldedit.core.queue.IChunkGet;
78
import com.fastasyncworldedit.core.util.MathMan;
@@ -124,6 +125,9 @@ protected static <LevelChunkSection> boolean setSectionAtomic(
124125
if (layer < 0 || layer >= sections.length) {
125126
return false;
126127
}
128+
if (Fawe.isMainThread()) {
129+
return ReflectionUtils.compareAndSet(sections, expected, value, layer);
130+
}
127131
StampLockHolder holder = new StampLockHolder();
128132
ConcurrentHashMap<IntPair, ChunkSendLock> chunks = FaweBukkitWorld.getWorldSendingChunksMap(worldName);
129133
chunks.compute(pair, (k, lock) -> {
@@ -171,6 +175,9 @@ protected static <LevelChunkSection> boolean setSectionAtomic(
171175
* @since 2.12.0
172176
*/
173177
protected static void beginChunkPacketSend(String worldName, IntPair pair, StampLockHolder stampedLock) {
178+
if (Fawe.isMainThread()) {
179+
return;
180+
}
174181
ConcurrentHashMap<IntPair, ChunkSendLock> chunks = FaweBukkitWorld.getWorldSendingChunksMap(worldName);
175182
chunks.compute(pair, (k, lock) -> {
176183
if (lock == null) {
@@ -192,6 +199,9 @@ protected static void beginChunkPacketSend(String worldName, IntPair pair, Stamp
192199
* @since 2.12.0
193200
*/
194201
protected static void endChunkPacketSend(String worldName, IntPair pair, StampLockHolder lockHolder) {
202+
if (Fawe.isMainThread()) {
203+
return;
204+
}
195205
ConcurrentHashMap<IntPair, ChunkSendLock> chunks = FaweBukkitWorld.getWorldSendingChunksMap(worldName);
196206
chunks.computeIfPresent(pair, (k, lock) -> {
197207
if (lock.lock != lockHolder.chunkLock.lock) {

0 commit comments

Comments
 (0)