threadmanager dispatch work
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
austin 2025-05-24 19:02:15 -04:00
parent b64c5090a6
commit a617456fc5
5 changed files with 44 additions and 5 deletions

View File

@ -1958,6 +1958,7 @@ LOD emitter service
LOD component that destroys far-away physics
visually LOD far away models support
Profiler work
Thread manager dispatching futures service

View File

@ -119,6 +119,10 @@ public class Main {
//init global variables
Globals.initGlobals();
//
//init profiler
Globals.profiler.start();
//init scripting engine
if(EngineState.EngineFlags.RUN_SCRIPTS){
Globals.engineState.threadManager.start(new LoadingThread(LoadingThreadType.SCRIPT_ENGINE));

View File

@ -29,11 +29,6 @@ public class Profiler {
* Creates the profiler
*/
public Profiler(){
try(MemoryStack stack = MemoryStack.stackPush()){
PointerBuffer allocBuffer = stack.mallocPointer(1);
Remotery.rmt_CreateGlobalInstance(allocBuffer);
pointer = allocBuffer.get();
}
}
/**
@ -91,6 +86,11 @@ public class Profiler {
*/
public void start(){
Profiler.PROFILE = true;
try(MemoryStack stack = MemoryStack.stackPush()){
PointerBuffer allocBuffer = stack.mallocPointer(1);
Remotery.rmt_CreateGlobalInstance(allocBuffer);
pointer = allocBuffer.get();
}
}
/**

View File

@ -45,4 +45,9 @@ public class ThreadCounts {
*/
public static final int SERVER_TERRAIN_GENERATION_THREADS = 2;
/**
* Default thread count for the thread manager
*/
public static final int DEFAULT_SERVICE_THREADS = 1;
}

View File

@ -3,8 +3,10 @@ package electrosphere.engine.threads;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
@ -47,6 +49,11 @@ public class ThreadManager {
*/
private static List<ExecutorService> executors = new LinkedList<ExecutorService>();
/**
* The default executor service
*/
private ExecutorService defaultService;
/**
* Initializes the thread manager
@ -56,6 +63,7 @@ public class ThreadManager {
activeThreads = new LinkedList<LabeledThread>();
loadingThreads = new LinkedList<LoadingThread>();
shouldKeepRunning = true;
this.defaultService = this.requestFixedThreadPool(ThreadCounts.DEFAULT_SERVICE_THREADS);
}
/**
@ -267,4 +275,25 @@ public class ThreadManager {
return rVal;
}
/**
* Dispatches a runnable to the default thread service
* @param runnable The runnable
*/
public void dispatch(Runnable runnable){
threadLock.lock();
this.defaultService.submit(runnable);
threadLock.unlock();
}
/**
* Dispatches a runnable to the default thread service
* @param runnable The runnable
*/
public <T> Future<T> dispatch(Callable<T> runnable){
threadLock.lock();
Future<T> rVal = this.defaultService.submit(runnable);
threadLock.unlock();
return rVal;
}
}