diff options
author | Michael Bien <[email protected]> | 2010-01-15 16:49:17 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-01-15 16:49:17 +0100 |
commit | 5193eb3c98bfa14ca8eb5767452c8e97f9f495c6 (patch) | |
tree | 7b4d6d29a0218a62ea76e9ae63c2a629a3b7c7a5 /src/com/mbien/opencl/QueueBarrier.java | |
parent | 64f212c105fd0f23e8116307b64ee4b87928823d (diff) |
improved QueueBarrier added constructor to restrict barriers to certain queues.
temporary added getGLObjectType to CLGLContext.
Diffstat (limited to 'src/com/mbien/opencl/QueueBarrier.java')
-rw-r--r-- | src/com/mbien/opencl/QueueBarrier.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/QueueBarrier.java b/src/com/mbien/opencl/QueueBarrier.java index 247ede7a..d3a5ab2e 100644 --- a/src/com/mbien/opencl/QueueBarrier.java +++ b/src/com/mbien/opencl/QueueBarrier.java @@ -1,5 +1,8 @@ package com.mbien.opencl; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -10,9 +13,34 @@ import java.util.concurrent.TimeUnit; public class QueueBarrier { private final CountDownLatch latch; + private final Set<CLCommandQueue> queues; public QueueBarrier(int queueCount) { this.latch = new CountDownLatch(queueCount); + this.queues = null; + } + + public QueueBarrier(CLCommandQueue... allowedQueues) { + this.latch = new CountDownLatch(allowedQueues.length); + + HashSet<CLCommandQueue> set = new HashSet<CLCommandQueue>(allowedQueues.length); + for (CLCommandQueue queue : allowedQueues) { + set.add(queue); + } + this.queues = Collections.unmodifiableSet(set); + } + + /** + * Blocks the current Thread until all commands on the CLCommandQueue finished excecution. + * 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) { + checkQueue(queue); + + queue.putBarrier(); + latch.countDown(); + return this; } /** @@ -21,6 +49,8 @@ public class QueueBarrier { * as long each Thread passes a distinct CLCommandQueue as parameter to this method. */ public QueueBarrier waitFor(CLCommandQueue queue, CLEventList events) { + checkQueue(queue); + queue.putWaitForEvents(events); latch.countDown(); return this; @@ -35,6 +65,7 @@ public class QueueBarrier { latch.await(); return this; } + /** * @see {@link #await()} * @param timeout the maximum time to wait @@ -45,4 +76,10 @@ public class QueueBarrier { return this; } + private final void checkQueue(CLCommandQueue queue) throws IllegalArgumentException { + if (queues != null && !queues.contains(queue)) { + throw new IllegalArgumentException(queue + " is not in the allowedQueues Set: " + queues); + } + } + } |