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);
|
||||
}
|
||||
|
||||
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) {
|
||||
return (boolean) AA.compareAndSet(array, index, expectedValue, newValue);
|
||||
}
|
||||
|
||||
@@ -34,8 +34,11 @@ interface MatterGenerator {
|
||||
return@radius
|
||||
|
||||
for (c in pair.a) {
|
||||
if (mc.isFlagged(c.flag))
|
||||
continue
|
||||
|
||||
launch(multicore) {
|
||||
mc.raiseFlagSuspend(MantleFlag.PLANNED, c.flag) {
|
||||
mc.raiseFlagSuspend(c.flag) {
|
||||
c.generateLayer(writer, x, z, context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,19 +49,15 @@ abstract class FlaggedChunk() {
|
||||
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 (guard != null && isFlagged(guard)) return
|
||||
if (isFlagged(flag)) return
|
||||
|
||||
locks[flag.ordinal()].withLock {
|
||||
if (flags.compareAndSet(flag.ordinal(), false, true)) {
|
||||
try {
|
||||
if (isFlagged(flag)) return
|
||||
task()
|
||||
} catch (e: Throwable) {
|
||||
flags.set(flag.ordinal(), false)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
if (flags.getAndSet(flag.ordinal(), true))
|
||||
throw IllegalStateException("Flag ${flag.name()} was already set after task ran!")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user