Skip to content

Commit

Permalink
JobSystemThreadPool: add the setNumThreads() method
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jul 8, 2024
1 parent a542e0b commit 8d10ceb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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);
}
12 changes: 12 additions & 0 deletions src/main/native/glue/JobSystemThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<JobSystemThreadPool *> (systemVa);
pSystem->SetNumThreads(numThreads);
}

0 comments on commit 8d10ceb

Please sign in to comment.