Skip to content

Commit

Permalink
[IntellectualSites#2448] Remove from recycle method lock calls and re…
Browse files Browse the repository at this point in the history
…vert code to previous behavior.
  • Loading branch information
TheMeinerLP committed Oct 10, 2023
1 parent 186d24b commit 527b95a
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -68,7 +68,6 @@ public void init(IBlockDelegate delegate) {

@Override
public synchronized void recycle() {
calledLock.lock();
delegate = NULL;
if (chunkSet != null) {
chunkSet.recycle();
Expand All @@ -77,7 +76,6 @@ public synchronized void recycle() {
chunkExisting = null;
extent = null;
POOL.offer(this);
calledLock.unlock();
}

public long initAge() {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -1082,7 +1078,6 @@ public synchronized T call(IChunkSet set, Runnable finalize) {
} else {
finalizer = finalize;
}
calledLock.unlock();
return get.call(set, finalizer);
}
return null;
Expand Down

0 comments on commit 527b95a

Please sign in to comment.