more work on threads
This commit is contained in:
@@ -29,8 +29,6 @@ public class VoxyClientInstance extends VoxyInstance {
|
|||||||
public VoxyClientInstance() {
|
public VoxyClientInstance() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.threadPool.setNumThreads(VoxyConfig.CONFIG.serviceThreads);
|
|
||||||
|
|
||||||
var path = FlashbackCompat.getReplayStoragePath();
|
var path = FlashbackCompat.getReplayStoragePath();
|
||||||
this.noIngestOverride = path != null;
|
this.noIngestOverride = path != null;
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package me.cortex.voxy.client.compat;
|
||||||
|
|
||||||
|
import me.cortex.voxy.common.thread3.MultiThreadPrioritySemaphore;
|
||||||
|
|
||||||
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
|
public class SemaphoreBlockImpersonator extends Semaphore {
|
||||||
|
private final MultiThreadPrioritySemaphore.Block block;
|
||||||
|
public SemaphoreBlockImpersonator(MultiThreadPrioritySemaphore.Block block) {
|
||||||
|
super(0);
|
||||||
|
this.block = block;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void release(int permits) {
|
||||||
|
this.block.release(permits);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acquire() throws InterruptedException {
|
||||||
|
this.block.acquire();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean tryAcquire() {
|
||||||
|
return this.block.tryAcquire();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int availablePermits() {
|
||||||
|
return this.block.availablePermits();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,23 +57,13 @@ public abstract class VoxyConfigScreenPages {
|
|||||||
//Runtime.getRuntime().availableProcessors(),//Note: this is threads not cores, the default value is half the core count, is fine as this should technically be the limit but CpuLayout.CORES.length is more realistic
|
//Runtime.getRuntime().availableProcessors(),//Note: this is threads not cores, the default value is half the core count, is fine as this should technically be the limit but CpuLayout.CORES.length is more realistic
|
||||||
1, v->Text.literal(Integer.toString(v))))
|
1, v->Text.literal(Integer.toString(v))))
|
||||||
.setBinding((s, v)->{
|
.setBinding((s, v)->{
|
||||||
boolean wasEnabled = VoxyCommon.getInstance() != null;
|
|
||||||
var vrsh = (IGetVoxyRenderSystem) MinecraftClient.getInstance().worldRenderer;
|
|
||||||
if (wasEnabled) {
|
|
||||||
if (vrsh != null) {
|
|
||||||
vrsh.shutdownRenderer();
|
|
||||||
}
|
|
||||||
VoxyCommon.shutdownInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
s.serviceThreads = v;
|
s.serviceThreads = v;
|
||||||
|
var instance = VoxyCommon.getInstance();
|
||||||
if (wasEnabled) {
|
if (instance != null) {
|
||||||
VoxyCommon.createInstance();
|
instance.setNumThreads(v);
|
||||||
}
|
}
|
||||||
}, s -> s.serviceThreads)
|
}, s -> s.serviceThreads)
|
||||||
.setImpact(OptionImpact.HIGH)
|
.setImpact(OptionImpact.HIGH)
|
||||||
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
|
|
||||||
.build()
|
.build()
|
||||||
).add(OptionImpl.createBuilder(boolean.class, storage)
|
).add(OptionImpl.createBuilder(boolean.class, storage)
|
||||||
.setName(Text.translatable("voxy.config.general.ingest"))
|
.setName(Text.translatable("voxy.config.general.ingest"))
|
||||||
|
|||||||
@@ -42,6 +42,23 @@ public class MultiThreadPrioritySemaphore {
|
|||||||
this.man.freeBlock(this);
|
this.man.freeBlock(this);
|
||||||
this.free0();
|
this.free0();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int availablePermits() {
|
||||||
|
return this.localSemaphore.availablePermits();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean tryAcquire() {
|
||||||
|
if (this.localSemaphore.availablePermits()==0) return false;//Quick exit
|
||||||
|
if (!this.blockSemaphore.tryAcquire()) return false;//There is definatly none
|
||||||
|
if (this.localSemaphore.tryAcquire()) {
|
||||||
|
//we acquired a proper permit
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
//We must release the other permit as we dont do processing here
|
||||||
|
this.blockSemaphore.release(1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Semaphore pooledSemaphore = new Semaphore(0);
|
private final Semaphore pooledSemaphore = new Semaphore(0);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
public class UnifiedServiceThreadPool {
|
public class UnifiedServiceThreadPool {
|
||||||
public final ServiceManager serviceManager;
|
public final ServiceManager serviceManager;
|
||||||
private final MultiThreadPrioritySemaphore groupSemaphore;
|
public final MultiThreadPrioritySemaphore groupSemaphore;
|
||||||
|
|
||||||
private final MultiThreadPrioritySemaphore.Block selfBlock;
|
private final MultiThreadPrioritySemaphore.Block selfBlock;
|
||||||
private final ThreadGroup dedicatedPool;
|
private final ThreadGroup dedicatedPool;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package me.cortex.voxy.commonImpl;
|
package me.cortex.voxy.commonImpl;
|
||||||
|
|
||||||
|
import me.cortex.voxy.client.config.VoxyConfig;
|
||||||
import me.cortex.voxy.common.Logger;
|
import me.cortex.voxy.common.Logger;
|
||||||
import me.cortex.voxy.common.config.section.SectionStorage;
|
import me.cortex.voxy.common.config.section.SectionStorage;
|
||||||
import me.cortex.voxy.common.thread.ServiceThreadPool;
|
import me.cortex.voxy.common.thread.ServiceThreadPool;
|
||||||
@@ -58,6 +59,10 @@ public abstract class VoxyInstance {
|
|||||||
this.worldCleaner.start();
|
this.worldCleaner.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNumThreads(int threads) {
|
||||||
|
this.threadPool.setNumThreads(threads);
|
||||||
|
}
|
||||||
|
|
||||||
protected ImportManager createImportManager() {
|
protected ImportManager createImportManager() {
|
||||||
return new ImportManager();
|
return new ImportManager();
|
||||||
}
|
}
|
||||||
@@ -65,6 +70,9 @@ public abstract class VoxyInstance {
|
|||||||
public ServiceManager getServiceManager() {
|
public ServiceManager getServiceManager() {
|
||||||
return this.threadPool.serviceManager;
|
return this.threadPool.serviceManager;
|
||||||
}
|
}
|
||||||
|
public UnifiedServiceThreadPool getThreadPool() {
|
||||||
|
return this.threadPool;
|
||||||
|
}
|
||||||
public VoxelIngestService getIngestService() {
|
public VoxelIngestService getIngestService() {
|
||||||
return this.ingestService;
|
return this.ingestService;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user