Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dordsor21 committed Sep 14, 2024
1 parent 63606d7 commit 3a3648f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,17 @@ public synchronized <T extends Future<T>> T call(IQueueExtent<? extends IChunk>
TextComponent.of("Could not get chunk at " + chunkX + "," + chunkZ + " whilst low memory: " + e.getMessage()));
}
}
final int finalCopyKey = copyKey;
// Run immediately if possible
if (chunk != null) {
return internalCall(set, finalizer, chunk, nmsWorld);
return internalCall(set, finalizer, finalCopyKey, chunk, nmsWorld);
}
// Submit via the STQE as that will help handle excessive queuing by waiting for the submission count to fall below the
// target size
nmsChunkFuture.thenApply(nmsChunk -> owner.submitTaskUnchecked(() -> (T) internalCall(
set,
finalizer,
finalCopyKey,
nmsChunk,
nmsWorld
)));
Expand All @@ -467,7 +469,13 @@ public synchronized <T extends Future<T>> T call(IQueueExtent<? extends IChunk>
return (T) (Future) CompletableFuture.completedFuture(null);
}

private <T extends Future<T>> T internalCall(IChunkSet set, Runnable finalizer, LevelChunk nmsChunk, ServerLevel nmsWorld) {
private <T extends Future<T>> T internalCall(
IChunkSet set,
Runnable finalizer,
int copyKey,
LevelChunk nmsChunk,
ServerLevel nmsWorld
) {
try {
PaperweightGetBlocks_Copy copy = createCopy ? new PaperweightGetBlocks_Copy(nmsChunk) : null;
if (createCopy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@

import com.fastasyncworldedit.core.extent.filter.block.FilterBlock;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;

public class CountFilter extends ForkedFilter<CountFilter> {

private int total;
private static final VarHandle TOTAL_VAR;

static {
try {
TOTAL_VAR = MethodHandles.privateLookupIn(CountFilter.class, MethodHandles.lookup()).findVarHandle(
CountFilter.class,
"total",
int.class
);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}

private int total = 0;

public CountFilter() {
super(null);
Expand All @@ -21,16 +38,16 @@ public CountFilter init() {

@Override
public void join(CountFilter filter) {
this.total += filter.getTotal();
TOTAL_VAR.getAndAdd(this, (int) filter.getTotal());
}

@Override
public final void applyBlock(FilterBlock block) {
total++;
TOTAL_VAR.getAndAdd(this, 1);
}

public int getTotal() {
return total;
return (int) TOTAL_VAR.get(this);
}

}

0 comments on commit 3a3648f

Please sign in to comment.