Fix deadlock in servicemanager + use sodiums thread pool for our own use

This commit is contained in:
mcrcortex
2025-10-25 18:57:40 +10:00
parent 6ffa90f064
commit d2a5b1e607
3 changed files with 42 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
package me.cortex.voxy.client.mixin.sodium;
import me.cortex.voxy.client.compat.SemaphoreBlockImpersonator;
import me.cortex.voxy.common.thread3.MultiThreadPrioritySemaphore;
import me.cortex.voxy.commonImpl.VoxyCommon;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.concurrent.Semaphore;
@Mixin(targets={"net.caffeinemc.mods.sodium.client.render.chunk.compile.executor.ChunkJobQueue"},remap = false)
public class MixinChunkJobQueue {
@Unique private MultiThreadPrioritySemaphore.Block voxy$semaphoreBlock;
@Redirect(method = "<init>", at = @At(value = "NEW", target = "(I)Ljava/util/concurrent/Semaphore;"))
private Semaphore voxy$injectUnifiedPool(int permits) {
var instance = VoxyCommon.getInstance();
if (instance != null) {
this.voxy$semaphoreBlock = instance.getThreadPool().groupSemaphore.createBlock();
return new SemaphoreBlockImpersonator(this.voxy$semaphoreBlock);
}
return new Semaphore(permits);
}
@Inject(method = "shutdown", at = @At("RETURN"))
private void voxy$injectAtShutdown(CallbackInfoReturnable ci) {
if (this.voxy$semaphoreBlock != null) {
this.voxy$semaphoreBlock.free();
}
}
}

View File

@@ -60,7 +60,7 @@ public class ServiceManager {
public boolean runAJob() {//Executes a single job on the current thread public boolean runAJob() {//Executes a single job on the current thread
while (true) { while (true) {
if (this.services.length == 0) return false; if (this.services.length == 0 || this.totalJobs.get() == 0) return false;
if (this.runAJob0()) return true; if (this.runAJob0()) return true;
try { try {
Thread.sleep(10); Thread.sleep(10);
@@ -169,6 +169,9 @@ public class ServiceManager {
} }
void remJobs(int remaining) { void remJobs(int remaining) {
//TODO:FIXME: THIS NEEDS TO BUBBLE UP TO THE jobRelease thing
// AFAK! if this is zero inside the runAJob loop, it must return
if (this.totalJobs.addAndGet(-remaining)<0) { if (this.totalJobs.addAndGet(-remaining)<0) {
throw new IllegalStateException("total jobs <0"); throw new IllegalStateException("total jobs <0");
} }

View File

@@ -29,6 +29,7 @@
"minecraft.MixinWorldRenderer", "minecraft.MixinWorldRenderer",
"nvidium.MixinRenderPipeline", "nvidium.MixinRenderPipeline",
"sodium.AccessorChunkTracker", "sodium.AccessorChunkTracker",
"sodium.MixinChunkJobQueue",
"sodium.MixinDefaultChunkRenderer", "sodium.MixinDefaultChunkRenderer",
"sodium.MixinRenderSectionManager", "sodium.MixinRenderSectionManager",
"sodium.MixinSodiumOptionsGUI" "sodium.MixinSodiumOptionsGUI"