From 6891798be02768f14889c4d04314988e2ed1ea6d Mon Sep 17 00:00:00 2001 From: barneypitt <barney@frontofficedeveloper.com> Date: Tue, 3 Mar 2015 19:08:32 +0000 Subject: [PATCH] Tweaks to improve interface for progress/cancel --- .../src/java/com/amd/aparapi/Kernel.java | 15 ++++++++++++++- .../amd/aparapi/internal/kernel/KernelRunner.java | 12 ++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/com.amd.aparapi/src/java/com/amd/aparapi/Kernel.java b/com.amd.aparapi/src/java/com/amd/aparapi/Kernel.java index eeb2ef7f..708005cc 100644 --- a/com.amd.aparapi/src/java/com/amd/aparapi/Kernel.java +++ b/com.amd.aparapi/src/java/com/amd/aparapi/Kernel.java @@ -970,6 +970,9 @@ public abstract class Kernel implements Cloneable { * @see #execute(String, Range, int) */ public void cancelMultiPass() { + if (kernelRunner == null) { + return; + } kernelRunner.cancelMultiPass(); } @@ -982,11 +985,21 @@ public abstract class Kernel implements Cloneable { */ public int getCurrentPass() { if (kernelRunner == null) { - return KernelRunner.PASS_ID_PREPARING_EXECUTION; + return KernelRunner.PASS_ID_COMPLETED_EXECUTION; } return kernelRunner.getCurrentPass(); } + /** + * @see KernelRunner#isExecuting() + */ + public boolean isExecuting() { + if (kernelRunner == null) { + return false; + } + return kernelRunner.isExecuting(); + } + /** * When using a Java Thread Pool Aparapi uses clone to copy the initial instance to each thread. * diff --git a/com.amd.aparapi/src/java/com/amd/aparapi/internal/kernel/KernelRunner.java b/com.amd.aparapi/src/java/com/amd/aparapi/internal/kernel/KernelRunner.java index ddf94ea2..c2b69e44 100644 --- a/com.amd.aparapi/src/java/com/amd/aparapi/internal/kernel/KernelRunner.java +++ b/com.amd.aparapi/src/java/com/amd/aparapi/internal/kernel/KernelRunner.java @@ -1382,8 +1382,9 @@ public class KernelRunner extends KernelRunnerJNI{ /** * Returns the index of the current pass, or one of two special constants with negative values to indicate special progress states. Those constants are - * {@link #PASS_ID_PREPARING_EXECUTION} to indicate that the Kernel has not yet started executing, or {@link #PASS_ID_COMPLETED_EXECUTION} to indicate that - * execution is complete (possibly due to early termination via {@link #cancelMultiPass()}). + * {@link #PASS_ID_PREPARING_EXECUTION} to indicate that the Kernel has started executing but not reached the initial pass, or + * {@link #PASS_ID_COMPLETED_EXECUTION} to indicate that execution is complete (possibly due to early termination via {@link #cancelMultiPass()}), i.e. the Kernel + * is idle. {@link #PASS_ID_COMPLETED_EXECUTION} is also returned before the first execution has been invoked. * * <p>This can be used, for instance, to update a visual progress bar. * @@ -1404,6 +1405,13 @@ public class KernelRunner extends KernelRunnerJNI{ } } + /** + * True while any of the {@code execute()} methods are in progress. + */ + public boolean isExecuting() { + return executing; + } + protected int getCurrentPassRemote() { return outBufferRemoteInt.get(0); } -- GitLab