From 527b95a1f08559d72f191b8d8745d9cdc8ab6e1b Mon Sep 17 00:00:00 2001
From: TheMeinerLP
Date: Tue, 10 Oct 2023 17:39:40 +0200
Subject: [PATCH] [#2448] Remove from recycle method lock calls and revert code
to previous behavior.
---
.../queue/implementation/chunk/ChunkHolder.java | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/ChunkHolder.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/ChunkHolder.java
index ec556d845e..a6fe7f227c 100644
--- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/ChunkHolder.java
+++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk/ChunkHolder.java
@@ -44,7 +44,7 @@ public static ChunkHolder newInstance() {
return POOL.poll();
}
- private final Lock calledLock = new ReentrantLock();
+ private final ReentrantLock calledLock = new ReentrantLock();
private volatile IChunkGet chunkExisting; // The existing chunk (e.g. a clipboard, or the world, before changes)
private volatile IChunkSet chunkSet; // The blocks to be set to the chunkExisting
@@ -68,7 +68,6 @@ public void init(IBlockDelegate delegate) {
@Override
public synchronized void recycle() {
- calledLock.lock();
delegate = NULL;
if (chunkSet != null) {
chunkSet.recycle();
@@ -77,7 +76,6 @@ public synchronized void recycle() {
chunkExisting = null;
extent = null;
POOL.offer(this);
- calledLock.unlock();
}
public long initAge() {
@@ -92,10 +90,10 @@ public synchronized IBlockDelegate getDelegate() {
* If the chunk is currently being "called", this method will block until completed.
*/
private void checkAndWaitOnCalledLock() {
- if (!calledLock.tryLock()) {
+ if (!calledLock.isLocked()) {
calledLock.lock();
+ calledLock.unlock();
}
- calledLock.unlock();
}
@Override
@@ -1055,9 +1053,7 @@ public synchronized T call() {
try {
IChunkSet copy = chunkSet.createCopy();
chunkSet = null;
- return this.call(copy, () -> {
- // Do nothing
- });
+ return this.call(copy, calledLock::unlock);
} catch (Throwable t) {
calledLock.unlock();
throw t;
@@ -1082,7 +1078,6 @@ public synchronized T call(IChunkSet set, Runnable finalize) {
} else {
finalizer = finalize;
}
- calledLock.unlock();
return get.call(set, finalizer);
}
return null;