summaryrefslogtreecommitdiffstats
path: root/src/com/jogamp
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-05-30 04:01:57 +0200
committerMichael Bien <[email protected]>2010-05-30 04:01:57 +0200
commitc8ae2569a4d90e79b9af83acdd50c1be2ecab9f0 (patch)
tree165b4871a3aa89adbb0e29e866c829d2b8dbe2ba /src/com/jogamp
parent0bcc9dd8f36dabfef118f3546a08f7d5666714ef (diff)
improved concurrent load test (disabled by default) and confirmed that cl programs can't be built concurrently.
CLProgram uses ReentrantLock to put synchronous and asynchronous calls to clBuildProgram(...) in a squence.
Diffstat (limited to 'src/com/jogamp')
-rw-r--r--src/com/jogamp/opencl/CLProgram.java23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/com/jogamp/opencl/CLProgram.java b/src/com/jogamp/opencl/CLProgram.java
index b6c1d7a2..7ccc3bc8 100644
--- a/src/com/jogamp/opencl/CLProgram.java
+++ b/src/com/jogamp/opencl/CLProgram.java
@@ -15,6 +15,7 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.Map;
+import java.util.concurrent.locks.ReentrantLock;
import static com.jogamp.opencl.CLException.*;
import static com.jogamp.opencl.CL.*;
@@ -30,7 +31,7 @@ import static com.jogamp.common.nio.Buffers.*;
*/
public class CLProgram extends CLObject implements CLResource {
-// private final static Object buildLock = new Object();
+ private final static ReentrantLock buildLock = new ReentrantLock();
private final Set<CLKernel> kernels;
private Map<CLDevice, Status> buildStatusMap;
@@ -317,6 +318,7 @@ public class CLProgram extends CLObject implements CLResource {
if(listener != null) {
callback = new BuildProgramCallback() {
public void buildFinished(long cl_program) {
+ buildLock.unlock();
listener.buildFinished(CLProgram.this);
}
};
@@ -324,10 +326,21 @@ public class CLProgram extends CLObject implements CLResource {
// Build the program
int ret = 0;
- // building programs is not threadsafe
-// synchronized(buildLock) {
- ret = cl.clBuildProgram(ID, count, deviceIDs, options, callback);
-// }
+
+ // spec: building programs is not threadsafe, we are locking the API call to
+ // make sure only one thread calls it at a time until it completes (asynchronous or synchronously).
+ {
+ buildLock.lock();
+ boolean exception = true;
+ try{
+ ret = cl.clBuildProgram(ID, count, deviceIDs, options, callback);
+ exception = false;
+ }finally{
+ if(callback == null || exception) {
+ buildLock.unlock();
+ }
+ }
+ }
if(ret != CL_SUCCESS) {
throw newException(ret, "\n"+getBuildLog());