mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-02-16 02:20:44 +00:00
decrease locking for mantle generation
This commit is contained in:
@@ -24,6 +24,10 @@ public class AtomicBooleanArray implements Serializable {
|
|||||||
AA.setVolatile(array, index, newValue);
|
AA.setVolatile(array, index, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean getAndSet(int index, boolean newValue) {
|
||||||
|
return (boolean) AA.getAndSet(array, index, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
public final boolean compareAndSet(int index, boolean expectedValue, boolean newValue) {
|
public final boolean compareAndSet(int index, boolean expectedValue, boolean newValue) {
|
||||||
return (boolean) AA.compareAndSet(array, index, expectedValue, newValue);
|
return (boolean) AA.compareAndSet(array, index, expectedValue, newValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,11 @@ interface MatterGenerator {
|
|||||||
return@radius
|
return@radius
|
||||||
|
|
||||||
for (c in pair.a) {
|
for (c in pair.a) {
|
||||||
|
if (mc.isFlagged(c.flag))
|
||||||
|
continue
|
||||||
|
|
||||||
launch(multicore) {
|
launch(multicore) {
|
||||||
mc.raiseFlagSuspend(MantleFlag.PLANNED, c.flag) {
|
mc.raiseFlagSuspend(c.flag) {
|
||||||
c.generateLayer(writer, x, z, context)
|
c.generateLayer(writer, x, z, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,19 +49,15 @@ abstract class FlaggedChunk() {
|
|||||||
flags.set(flag.ordinal(), value)
|
flags.set(flag.ordinal(), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun raiseFlagSuspend(guard: MantleFlag?, flag: MantleFlag, task: suspend () -> Unit) {
|
suspend fun raiseFlagSuspend(flag: MantleFlag, task: suspend () -> Unit) {
|
||||||
if (isClosed()) throw IllegalStateException("Chunk is closed!")
|
if (isClosed()) throw IllegalStateException("Chunk is closed!")
|
||||||
if (guard != null && isFlagged(guard)) return
|
if (isFlagged(flag)) return
|
||||||
|
|
||||||
locks[flag.ordinal()].withLock {
|
locks[flag.ordinal()].withLock {
|
||||||
if (flags.compareAndSet(flag.ordinal(), false, true)) {
|
if (isFlagged(flag)) return
|
||||||
try {
|
task()
|
||||||
task()
|
if (flags.getAndSet(flag.ordinal(), true))
|
||||||
} catch (e: Throwable) {
|
throw IllegalStateException("Flag ${flag.name()} was already set after task ran!")
|
||||||
flags.set(flag.ordinal(), false)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user