29package com.jogamp.opencl.util;
31import com.jogamp.opencl.CLCommandQueue;
32import com.jogamp.opencl.CLEventList;
33import java.util.Collections;
34import java.util.HashSet;
36import java.util.concurrent.CountDownLatch;
37import java.util.concurrent.TimeUnit;
46 private CountDownLatch latch;
47 private final Set<CLCommandQueue> queues;
48 private final int count;
57 throw new IllegalArgumentException(
"queueCount was 0");
59 this.latch =
new CountDownLatch(queueCount);
61 this.count = queueCount;
68 if(allowedQueues.length == 0) {
69 throw new IllegalArgumentException(
"allowedQueues was empty");
71 this.latch =
new CountDownLatch(allowedQueues.length);
72 this.count = allowedQueues.length;
74 final HashSet<CLCommandQueue>
set =
new HashSet<CLCommandQueue>(allowedQueues.length);
78 this.queues = Collections.unmodifiableSet(
set);
118 rebuildBarrierIfBroken();
127 public boolean await(
final long timeout,
final TimeUnit unit)
throws InterruptedException {
128 final boolean ret = latch.await(timeout, unit);
129 rebuildBarrierIfBroken();
138 while(latch.getCount() > 0) {
143 latch =
new CountDownLatch(count);
147 private void rebuildBarrierIfBroken() {
148 synchronized (
this) {
149 if (latch.getCount() == 0) {
150 latch =
new CountDownLatch(count);
160 return latch.getCount();
163 private void checkQueue(
final CLCommandQueue queue)
throws IllegalArgumentException {
164 if (queues !=
null && !queues.contains(queue)) {
165 throw new IllegalArgumentException(queue +
" is not in the allowedQueues Set: " + queues);
The command queue is used to queue a set of operations for a specific CLDevice.
CLCommandQueue putBarrier()
Calls {@native clEnqueueBarrier}.
CLCommandQueue putWaitForEvents(final CLEventList list, final boolean blockingWait)
Calls {@native clWaitForEvents} if blockingWait equals true otherwise {@native clEnqueueWaitForEvents...
Fixed size list for storing CLEvents.
An utility for synchronizing multiple concurrent CLCommandQueues.
MultiQueueBarrier await()
Blocks until all Threads which called waitFor continue execution.
MultiQueueBarrier(final int queueCount)
Creates a new MultiQueueBarrier with the given queueCount.
boolean await(final long timeout, final TimeUnit unit)
MultiQueueBarrier waitFor(final CLCommandQueue queue, final CLEventList events)
Blocks the current Thread until the given events on the CLCommandQueue occurred.
MultiQueueBarrier waitFor(final CLCommandQueue queue)
Blocks the current Thread until all commands on the CLCommandQueue finished excecution.
long getCount()
Returns the current number of events which must occure before this barrier unblocks the waiting threa...
void resetBarrier()
Resets this barrier and unblocks all waiting threads.
MultiQueueBarrier(final CLCommandQueue... allowedQueues)
Creates a new MultiQueueBarrier for the given queues.