Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
Synchronise on the internal chunk section earlier to avoid what seems…
Browse files Browse the repository at this point in the history
… to be concurrency issues with sychronisation..?
  • Loading branch information
dordsor21 committed Sep 2, 2021
1 parent 7c6e619 commit ae35e53
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,30 +440,29 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
copy.storeSection(layer, copyArr);
}

ChunkSection newSection;
ChunkSection existingSection = sections[layer];
if (existingSection == null) {
newSection = BukkitAdapter_1_15_2.newChunkSection(layer, setArr, fastmode, adapter);
if (BukkitAdapter_1_15_2.setSectionAtomic(sections, null, newSection, layer)) {
updateGet(nmsChunk, sections, newSection, setArr, layer);
continue;
} else {
existingSection = sections[layer];
if (existingSection == null) {
LOGGER.error("Skipping invalid null section. chunk:" + chunkX + ","
+ chunkZ + " layer: " + layer);
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size.
synchronized (super.sections[layer]) {
ChunkSection newSection;
ChunkSection existingSection = sections[layer];
if (existingSection == null) {
newSection = BukkitAdapter_1_15_2.newChunkSection(layer, setArr, fastmode, adapter);
if (BukkitAdapter_1_15_2.setSectionAtomic(sections, null, newSection, layer)) {
updateGet(nmsChunk, sections, newSection, setArr, layer);
continue;
} else {
existingSection = sections[layer];
if (existingSection == null) {
LOGGER.error("Skipping invalid null section. chunk:" + chunkX + ","
+ chunkZ + " layer: " + layer);
continue;
}
}
}
}
BukkitAdapter_1_15_2.fieldTickingBlockCount.set(existingSection, (short) 0);

//ensure that the server doesn't try to tick the chunksection while we're editing it.
DelegateLock lock = BukkitAdapter_1_15_2.applyLock(existingSection);
BukkitAdapter_1_15_2.fieldTickingBlockCount.set(existingSection, (short) 0);

// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size.
synchronized (super.sections[layer]) {
//ensure that the server doesn't try to tick the chunksection while we're editing it.
DelegateLock lock = BukkitAdapter_1_15_2.applyLock(existingSection);
synchronized (lock) {
lock.untilFree();
try {
Expand Down Expand Up @@ -915,7 +914,7 @@ public boolean hasSection(int layer) {
}

@Override
public boolean trim(boolean aggressive) {
public synchronized boolean trim(boolean aggressive) {
skyLight = new NibbleArray[16];
blockLight = new NibbleArray[16];
if (aggressive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,30 +456,29 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
copy.storeSection(layer, copyArr);
}

ChunkSection newSection;
ChunkSection existingSection = sections[layer];
if (existingSection == null) {
newSection = BukkitAdapter_1_16_5.newChunkSection(layer, setArr, fastmode, adapter);
if (BukkitAdapter_1_16_5.setSectionAtomic(sections, null, newSection, layer)) {
updateGet(nmsChunk, sections, newSection, setArr, layer);
continue;
} else {
existingSection = sections[layer];
if (existingSection == null) {
LOGGER.error("Skipping invalid null section. chunk:" + chunkX + ","
+ chunkZ + " layer: " + layer);
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size.
synchronized (super.sections[layer]) {
ChunkSection newSection;
ChunkSection existingSection = sections[layer];
if (existingSection == null) {
newSection = BukkitAdapter_1_16_5.newChunkSection(layer, setArr, fastmode, adapter);
if (BukkitAdapter_1_16_5.setSectionAtomic(sections, null, newSection, layer)) {
updateGet(nmsChunk, sections, newSection, setArr, layer);
continue;
} else {
existingSection = sections[layer];
if (existingSection == null) {
LOGGER.error("Skipping invalid null section. chunk:" + chunkX + ","
+ chunkZ + " layer: " + layer);
continue;
}
}
}
}
BukkitAdapter_1_16_5.fieldTickingBlockCount.set(existingSection, (short) 0);

//ensure that the server doesn't try to tick the chunksection while we're editing it.
DelegateLock lock = BukkitAdapter_1_16_5.applyLock(existingSection);
BukkitAdapter_1_16_5.fieldTickingBlockCount.set(existingSection, (short) 0);

// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size.
synchronized (super.sections[layer]) {
//ensure that the server doesn't try to tick the chunksection while we're editing it.
DelegateLock lock = BukkitAdapter_1_16_5.applyLock(existingSection);
synchronized (lock) {
lock.untilFree();
try {
Expand Down Expand Up @@ -952,7 +951,7 @@ public boolean hasSection(int layer) {
}

@Override
public boolean trim(boolean aggressive) {
public synchronized boolean trim(boolean aggressive) {
skyLight = new NibbleArray[16];
blockLight = new NibbleArray[16];
if (aggressive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,30 +458,29 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
copy.storeSection(layer, copyArr);
}

ChunkSection newSection;
ChunkSection existingSection = sections[layer];
if (existingSection == null) {
newSection = BukkitAdapter_1_17.newChunkSection(layerNo, setArr, fastmode, adapter);
if (BukkitAdapter_1_17.setSectionAtomic(sections, null, newSection, layer)) {
updateGet(nmsChunk, sections, newSection, setArr, layer);
continue;
} else {
existingSection = sections[layer];
if (existingSection == null) {
LOGGER.error("Skipping invalid null section. chunk:" + chunkX + ","
+ chunkZ + " layer: " + layer);
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size.
synchronized (super.sections[layer]) {
ChunkSection newSection;
ChunkSection existingSection = sections[layer];
if (existingSection == null) {
newSection = BukkitAdapter_1_17.newChunkSection(layerNo, setArr, fastmode, adapter);
if (BukkitAdapter_1_17.setSectionAtomic(sections, null, newSection, layer)) {
updateGet(nmsChunk, sections, newSection, setArr, layer);
continue;
} else {
existingSection = sections[layer];
if (existingSection == null) {
LOGGER.error("Skipping invalid null section. chunk:" + chunkX + ","
+ chunkZ + " layer: " + layer);
continue;
}
}
}
}
BukkitAdapter_1_17.fieldTickingBlockCount.set(existingSection, (short) 0);

//ensure that the server doesn't try to tick the chunksection while we're editing it.
DelegateSemaphore lock = BukkitAdapter_1_17.applyLock(existingSection);
BukkitAdapter_1_17.fieldTickingBlockCount.set(existingSection, (short) 0);

// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size.
synchronized (super.sections[layer]) {
//ensure that the server doesn't try to tick the chunksection while we're editing it.
DelegateSemaphore lock = BukkitAdapter_1_17.applyLock(existingSection);
synchronized (lock) {
// lock.acquire();
try {
Expand Down Expand Up @@ -954,7 +953,7 @@ public boolean hasSection(int layer) {
}

@Override
public boolean trim(boolean aggressive) {
public synchronized boolean trim(boolean aggressive) {
skyLight = new NibbleArray[getSectionCount()];
blockLight = new NibbleArray[getSectionCount()];
if (aggressive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,30 +461,30 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
copy.storeSection(layer, copyArr);
}

ChunkSection newSection;
ChunkSection existingSection = sections[layer];
if (existingSection == null) {
newSection = BukkitAdapter_1_17_1.newChunkSection(layerNo, setArr, fastmode, adapter);
if (BukkitAdapter_1_17_1.setSectionAtomic(sections, null, newSection, layer)) {
updateGet(nmsChunk, sections, newSection, setArr, layer);
continue;
} else {
existingSection = sections[layer];
if (existingSection == null) {
LOGGER.error("Skipping invalid null section. chunk:" + chunkX + ","
+ chunkZ + " layer: " + layer);
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size.
synchronized (super.sections[layer]) {
ChunkSection newSection;
ChunkSection existingSection = sections[layer];
if (existingSection == null) {
newSection = BukkitAdapter_1_17_1.newChunkSection(layerNo, setArr, fastmode, adapter);
if (BukkitAdapter_1_17_1.setSectionAtomic(sections, null, newSection, layer)) {
updateGet(nmsChunk, sections, newSection, setArr, layer);
continue;
} else {
existingSection = sections[layer];
if (existingSection == null) {
LOGGER.error("Skipping invalid null section. chunk:" + chunkX + ","
+ chunkZ + " layer: " + layer);
continue;
}
}
}
}
BukkitAdapter_1_17_1.fieldTickingBlockCount.set(existingSection, (short) 0);
BukkitAdapter_1_17_1.fieldTickingBlockCount.set(existingSection, (short) 0);

//ensure that the server doesn't try to tick the chunksection while we're editing it.
DelegateSemaphore lock = BukkitAdapter_1_17_1.applyLock(existingSection);
//ensure that the server doesn't try to tick the chunksection while we're editing it.
DelegateSemaphore lock = BukkitAdapter_1_17_1.applyLock(existingSection);

// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size.
synchronized (super.sections[layer]) {
synchronized (lock) {
// lock.acquire();
try {
Expand Down Expand Up @@ -963,7 +963,7 @@ public boolean hasSection(int layer) {
}

@Override
public boolean trim(boolean aggressive) {
public synchronized boolean trim(boolean aggressive) {
skyLight = new NibbleArray[getSectionCount()];
blockLight = new NibbleArray[getSectionCount()];
if (aggressive) {
Expand Down

0 comments on commit ae35e53

Please sign in to comment.