diff options
author | Michael Bien <[email protected]> | 2010-05-30 04:01:57 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-05-30 04:01:57 +0200 |
commit | c8ae2569a4d90e79b9af83acdd50c1be2ecab9f0 (patch) | |
tree | 165b4871a3aa89adbb0e29e866c829d2b8dbe2ba /src | |
parent | 0bcc9dd8f36dabfef118f3546a08f7d5666714ef (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')
-rw-r--r-- | src/com/jogamp/opencl/CLProgram.java | 23 |
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()); |