Fix deadlock in servicemanager + use sodiums thread pool for our own use
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class ServiceManager {
|
||||
|
||||
public boolean runAJob() {//Executes a single job on the current thread
|
||||
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;
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
@@ -169,6 +169,9 @@ public class ServiceManager {
|
||||
}
|
||||
|
||||
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) {
|
||||
throw new IllegalStateException("total jobs <0");
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"minecraft.MixinWorldRenderer",
|
||||
"nvidium.MixinRenderPipeline",
|
||||
"sodium.AccessorChunkTracker",
|
||||
"sodium.MixinChunkJobQueue",
|
||||
"sodium.MixinDefaultChunkRenderer",
|
||||
"sodium.MixinRenderSectionManager",
|
||||
"sodium.MixinSodiumOptionsGUI"
|
||||
|
||||
Reference in New Issue
Block a user