Adjust some synchronisation

This commit is contained in:
dordsor21 2021-09-02 18:06:36 +01:00
parent 09c4655be7
commit 79f4be3941
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
2 changed files with 17 additions and 15 deletions

View File

@ -31,29 +31,31 @@ public abstract class CharBlocks implements IBlocks {
}; };
protected final Section empty = new Section() { protected final Section empty = new Section() {
@Override @Override
public synchronized char[] get(CharBlocks blocks, int layer) { public char[] get(CharBlocks blocks, int layer) {
// Defaults to aggressive as it should only be avoided where we know we've reset a chunk during an edit // Defaults to aggressive as it should only be avoided where we know we've reset a chunk during an edit
return get(blocks, layer, true); return get(blocks, layer, true);
} }
@Override @Override
public synchronized char[] get(CharBlocks blocks, int layer, boolean aggressive) { public char[] get(CharBlocks blocks, int layer, boolean aggressive) {
char[] arr = blocks.blocks[layer]; synchronized (this) {
if (arr == null) { char[] arr = blocks.blocks[layer];
arr = blocks.blocks[layer] = blocks.update(layer, null, aggressive);
if (arr == null) { if (arr == null) {
throw new IllegalStateException("Array cannot be null: " + blocks.getClass()); arr = blocks.blocks[layer] = blocks.update(layer, null, aggressive);
if (arr == null) {
throw new IllegalStateException("Array cannot be null: " + blocks.getClass());
}
} else {
blocks.blocks[layer] = blocks.update(layer, arr, aggressive);
if (blocks.blocks[layer] == null) {
throw new IllegalStateException("Array cannot be null (update): " + blocks.getClass());
}
} }
} else { if (blocks.blocks[layer] != null) {
blocks.blocks[layer] = blocks.update(layer, arr, aggressive); blocks.sections[layer] = FULL;
if (blocks.blocks[layer] == null) {
throw new IllegalStateException("Array cannot be null (update): " + blocks.getClass());
} }
return arr;
} }
if (blocks.blocks[layer] != null) {
blocks.sections[layer] = FULL;
}
return arr;
} }
@Override @Override

View File

@ -24,7 +24,7 @@ public abstract class CharGetBlocks extends CharBlocks implements IChunkGet {
} }
@Override @Override
public boolean trim(boolean aggressive) { public synchronized boolean trim(boolean aggressive) {
for (int i = 0; i < sectionCount; i++) { for (int i = 0; i < sectionCount; i++) {
sections[i] = empty; sections[i] = empty;
blocks[i] = null; blocks[i] = null;