summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util/FunctionTask.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-02-14 01:48:54 +0100
committerSven Gothel <[email protected]>2013-02-14 01:48:54 +0100
commit1604f2341e496b380fbb3cf8d1e0134d947d8536 (patch)
tree68c63167e5a35e69ffc5afd7d0bc9a09a8c2137d /src/java/com/jogamp/common/util/FunctionTask.java
parentb387d012103a02eb7d5eb919306583295ef09a38 (diff)
Fix FunctionTask's run()/eval(..) return value assignment: Ensure it's done before syncObject.notifyAll() ; Make methods final
Fixes commit b387d012103a02eb7d5eb919306583295ef09a38.
Diffstat (limited to 'src/java/com/jogamp/common/util/FunctionTask.java')
-rw-r--r--src/java/com/jogamp/common/util/FunctionTask.java38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/java/com/jogamp/common/util/FunctionTask.java b/src/java/com/jogamp/common/util/FunctionTask.java
index 8a1ef44..35720a0 100644
--- a/src/java/com/jogamp/common/util/FunctionTask.java
+++ b/src/java/com/jogamp/common/util/FunctionTask.java
@@ -86,23 +86,23 @@ public class FunctionTask<R,A> extends TaskBase implements Function<R,A> {
}
/** Return the user action */
- public Function<R,A> getRunnable() {
+ public final Function<R,A> getRunnable() {
return runnable;
}
/**
* Sets the arguments for {@link #run()}.
- * They will be cleared afterwards.
+ * They will be cleared after calling {@link #run()} or {@link #eval(Object...)}.
*/
- public void setArgs(A... args) {
+ public final void setArgs(A... args) {
this.args = args;
}
/**
* Retrieves the cached result of {@link #run()}
- * and clears it afterwards.
+ * and is cleared within this method.
*/
- public R getResult() {
+ public final R getResult() {
final R res = result;
result = null;
return res;
@@ -119,18 +119,14 @@ public class FunctionTask<R,A> extends TaskBase implements Function<R,A> {
* </p>
*/
@Override
- public void run() {
- result = eval(args);
- args = null;
- }
-
- @Override
- public R eval(A... args) {
- R res = null;
+ public final void run() {
+ final A[] args = this.args;
+ this.args = null;
+ this.result = null;
tStarted = System.currentTimeMillis();
if(null == syncObject) {
try {
- res = runnable.eval(args);
+ this.result = runnable.eval(args);
} catch (Throwable t) {
runnableException = t;
if(!catchExceptions) {
@@ -142,7 +138,7 @@ public class FunctionTask<R,A> extends TaskBase implements Function<R,A> {
} else {
synchronized (syncObject) {
try {
- res = runnable.eval(args);
+ this.result = runnable.eval(args);
} catch (Throwable t) {
runnableException = t;
if(!catchExceptions) {
@@ -153,8 +149,16 @@ public class FunctionTask<R,A> extends TaskBase implements Function<R,A> {
syncObject.notifyAll();
}
}
- }
+ }
+ }
+
+ @Override
+ public final R eval(A... args) {
+ this.args = args;
+ run();
+ final R res = result;
+ result = null;
return res;
- }
+ }
}