diff options
author | Michael Bien <[email protected]> | 2010-01-14 17:38:34 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-01-14 17:38:34 +0100 |
commit | 9e650242da44a939e6a4c1e3c06d77c2e668a3e0 (patch) | |
tree | b0272560299430beb79915c9f701994bc40a10d5 /src/com/mbien/opencl/QueueBarrier.java | |
parent | 9343c3ef5829f74207a8d220cb3b082211b910f2 (diff) |
cleaned up NioDirectOnly list, added clSetKernelArg to list.
added experimental QueueBarrier for easy synchronization between multiple concurrent CLCommandQueues.
refactored CLCommandQueue, added putTask().
added another concurrency JUnit test.
Diffstat (limited to 'src/com/mbien/opencl/QueueBarrier.java')
-rw-r--r-- | src/com/mbien/opencl/QueueBarrier.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/QueueBarrier.java b/src/com/mbien/opencl/QueueBarrier.java new file mode 100644 index 00000000..247ede7a --- /dev/null +++ b/src/com/mbien/opencl/QueueBarrier.java @@ -0,0 +1,48 @@ +package com.mbien.opencl; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * + * @author Michael Bien + */ +public class QueueBarrier { + + private final CountDownLatch latch; + + public QueueBarrier(int queueCount) { + this.latch = new CountDownLatch(queueCount); + } + + /** + * Blocks the current Thread until the given events on the CLCommandQueue occurred. + * This method may be invoked concurrently without synchronization on the QueueBarrier object + * as long each Thread passes a distinct CLCommandQueue as parameter to this method. + */ + public QueueBarrier waitFor(CLCommandQueue queue, CLEventList events) { + queue.putWaitForEvents(events); + latch.countDown(); + return this; + } + + /** + * Blocks until all Threads which called {@link #waitFor} + * continue excecution. + * This method blocks only once, all subsequent calls are ignored. + */ + public QueueBarrier await() throws InterruptedException { + latch.await(); + return this; + } + /** + * @see {@link #await()} + * @param timeout the maximum time to wait + * @param unit the time unit of the {@code timeout} argument + */ + public QueueBarrier await(long timeout, TimeUnit unit) throws InterruptedException { + latch.await(timeout, unit); + return this; + } + +} |