From 4c08ffdff2afea9b889a5a481c5110e772f794cc Mon Sep 17 00:00:00 2001 From: Ruffled <105522716+RuffledPlume@users.noreply.github.com> Date: Thu, 19 Mar 2026 10:02:34 +0000 Subject: [PATCH 1/2] ConcurrentPool should process clientCallbacks if waiting on the client --- .../java/rs117/hd/renderer/zone/ZoneRenderer.java | 6 +++--- .../rs117/hd/utils/collections/ConcurrentPool.java | 2 ++ src/main/java/rs117/hd/utils/jobs/JobHandle.java | 2 +- src/main/java/rs117/hd/utils/jobs/JobSystem.java | 12 +++++++++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/rs117/hd/renderer/zone/ZoneRenderer.java b/src/main/java/rs117/hd/renderer/zone/ZoneRenderer.java index 4d6f168933..b88bc33bf4 100644 --- a/src/main/java/rs117/hd/renderer/zone/ZoneRenderer.java +++ b/src/main/java/rs117/hd/renderer/zone/ZoneRenderer.java @@ -322,7 +322,7 @@ private void preSceneDrawTopLevel( Scene scene, float cameraX, float cameraY, float cameraZ, float cameraPitch, float cameraYaw ) { - jobSystem.processPendingClientCallbacks(); + JobSystem.processPendingClientCallbacks(); scene.setDrawDistance(plugin.getDrawDistance()); @@ -605,7 +605,7 @@ private void preSceneDrawTopLevel( @Override public void postSceneDraw(Scene scene) { - jobSystem.processPendingClientCallbacks(); + JobSystem.processPendingClientCallbacks(); WorldViewContext ctx = sceneManager.getContext(scene); if (ctx == null || !sceneManager.isRoot(ctx) && ctx.isLoading) @@ -1062,7 +1062,7 @@ public void draw(int overlayColor) { plugin.drawUi(overlayColor); frameTimer.end(Timer.DRAW_SUBMIT); - jobSystem.processPendingClientCallbacks(); + JobSystem.processPendingClientCallbacks(); frameTimer.end(Timer.DRAW_FRAME); frameTimer.end(Timer.RENDER_FRAME); diff --git a/src/main/java/rs117/hd/utils/collections/ConcurrentPool.java b/src/main/java/rs117/hd/utils/collections/ConcurrentPool.java index 5175492ba1..7adfe1023d 100644 --- a/src/main/java/rs117/hd/utils/collections/ConcurrentPool.java +++ b/src/main/java/rs117/hd/utils/collections/ConcurrentPool.java @@ -6,6 +6,7 @@ import javax.annotation.Nonnull; import rs117.hd.utils.Destructible; import rs117.hd.utils.DestructibleHandler; +import rs117.hd.utils.jobs.JobSystem; public final class ConcurrentPool { private final ConcurrentLinkedQueue pool = new ConcurrentLinkedQueue<>(); @@ -42,6 +43,7 @@ public T acquireBlocking(int timeoutNanos) { while ((obj = pool.poll()) == null) { if (!parkedThreads.contains(currentThread)) parkedThreads.add(currentThread); + JobSystem.processPendingClientCallbacks(); LockSupport.parkNanos(1000); if (System.nanoTime() > deadline) return null; diff --git a/src/main/java/rs117/hd/utils/jobs/JobHandle.java b/src/main/java/rs117/hd/utils/jobs/JobHandle.java index 9d38fb5740..238136f8c1 100644 --- a/src/main/java/rs117/hd/utils/jobs/JobHandle.java +++ b/src/main/java/rs117/hd/utils/jobs/JobHandle.java @@ -255,7 +255,7 @@ boolean await(int timeoutNanos) throws InterruptedException { long start = System.currentTimeMillis(); int seconds = 0; while (!tryAcquireSharedNanos(0, TimeUnit.MILLISECONDS.toNanos(1))) { - JOB_SYSTEM.processPendingClientCallbacks(); + JobSystem.processPendingClientCallbacks(); Thread.yield(); long elapsed = System.currentTimeMillis() - start; int newSeconds = (int) (elapsed / 1000); diff --git a/src/main/java/rs117/hd/utils/jobs/JobSystem.java b/src/main/java/rs117/hd/utils/jobs/JobSystem.java index 8c2fa91303..4a858b6b20 100644 --- a/src/main/java/rs117/hd/utils/jobs/JobSystem.java +++ b/src/main/java/rs117/hd/utils/jobs/JobSystem.java @@ -20,6 +20,7 @@ @Slf4j @Singleton public final class JobSystem { + private static JobSystem INSTANCE; public static final boolean VALIDATE = false; @Inject @@ -53,6 +54,7 @@ public final class JobSystem { Semaphore workerSemaphore; public void startUp(CpuUsageLimit cpuUsageLimit) { + INSTANCE = this; workerCount = max(1, ceil((PROCESSOR_COUNT - 1) * cpuUsageLimit.threadRatio)); workers = new Worker[workerCount]; workerSemaphore = new Semaphore(workerCount); @@ -141,6 +143,7 @@ public void shutDown() { log.debug("All workers shutdown successfully"); threadToWorker.clear(); + clientCallbacks.clear(); workers = null; } @@ -239,13 +242,16 @@ void invokeClientCallback(Runnable callback) throws InterruptedException { } } - public void processPendingClientCallbacks() { - int size = clientCallbacks.size(); + public static void processPendingClientCallbacks() { + if(INSTANCE == null || !INSTANCE.client.isClientThread()) + return; + + int size = INSTANCE.clientCallbacks.size(); if (size == 0) return; ClientCallbackJob pair; - while (size-- > 0 && (pair = clientCallbacks.poll()) != null) { + while (size-- > 0 && (pair = INSTANCE.clientCallbacks.poll()) != null) { try { pair.callback.run(); } catch (Throwable ex) { From 756d1ac91b29e999adfb8fc4be6852372512bdcf Mon Sep 17 00:00:00 2001 From: Hooder Date: Sat, 21 Mar 2026 13:48:55 +0100 Subject: [PATCH 2/2] Formatting --- src/main/java/rs117/hd/utils/jobs/JobSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/rs117/hd/utils/jobs/JobSystem.java b/src/main/java/rs117/hd/utils/jobs/JobSystem.java index 4a858b6b20..273da15baa 100644 --- a/src/main/java/rs117/hd/utils/jobs/JobSystem.java +++ b/src/main/java/rs117/hd/utils/jobs/JobSystem.java @@ -243,7 +243,7 @@ void invokeClientCallback(Runnable callback) throws InterruptedException { } public static void processPendingClientCallbacks() { - if(INSTANCE == null || !INSTANCE.client.isClientThread()) + if (INSTANCE == null || !INSTANCE.client.isClientThread()) return; int size = INSTANCE.clientCallbacks.size();