diff --git a/src/main/java/com/github/stephengold/joltjni/JobSystemThreadPool.java b/src/main/java/com/github/stephengold/joltjni/JobSystemThreadPool.java index d963089a..4d45892a 100644 --- a/src/main/java/com/github/stephengold/joltjni/JobSystemThreadPool.java +++ b/src/main/java/com/github/stephengold/joltjni/JobSystemThreadPool.java @@ -60,6 +60,19 @@ public JobSystemThreadPool(int maxJobs, int maxBarriers, int numThreads) { setVirtualAddress(systemVa, true); } // ************************************************************************* + // new methods exposed + + /** + * Alter the number of worker threads. This is one less than the maximum + * number of jobs that can execute concurrently. + * + * @param numThreads the desired number of threads (≥0) + */ + public void setNumThreads(int numThreads) { + long systemVa = va(); + setNumThreads(systemVa, numThreads); + } + // ************************************************************************* // JobSystem methods /** @@ -82,4 +95,6 @@ native private static long createJobSystem( int maxJobs, int maxBarriers, int numThreads); native private static void free(long systemVa); + + native private static void setNumThreads(long systemVa, int numThreads); } diff --git a/src/main/native/glue/JobSystemThreadPool.cpp b/src/main/native/glue/JobSystemThreadPool.cpp index 465a9128..e679c04e 100644 --- a/src/main/native/glue/JobSystemThreadPool.cpp +++ b/src/main/native/glue/JobSystemThreadPool.cpp @@ -54,3 +54,15 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_JobSystemThreadPool_f delete pSystem; #endif } + +/* + * Class: com_github_stephengold_joltjni_JobSystemThreadPool + * Method: setNumThreads + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_JobSystemThreadPool_setNumThreads + (JNIEnv *, jclass, jlong systemVa, jint numThreads) { + JobSystemThreadPool * const pSystem + = reinterpret_cast (systemVa); + pSystem->SetNumThreads(numThreads); +}