summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-12-28 14:03:36 +0100
committerSven Gothel <[email protected]>2012-12-28 14:03:36 +0100
commit0b43b43f889ad7fc220942b0076e2001ca3cf13f (patch)
tree55e04efeec2f363234fceb09964a1bc65bd03153
parent4cbceccb3a91bb4b9bcf9e109e5f777fa50606a3 (diff)
Refine AWTEDTExecutor.invoke(..): Allow control whether a non AWT-EDT may execute the runnable.
For some 'rare' AWT/GL lifecycle actions, it is required to only run the command on the AWT-EDT, hence adding an argument determining the restriction.
-rw-r--r--src/java/jogamp/common/awt/AWTEDTExecutor.java51
1 files changed, 36 insertions, 15 deletions
diff --git a/src/java/jogamp/common/awt/AWTEDTExecutor.java b/src/java/jogamp/common/awt/AWTEDTExecutor.java
index 67fd7e1..8d77f5c 100644
--- a/src/java/jogamp/common/awt/AWTEDTExecutor.java
+++ b/src/java/jogamp/common/awt/AWTEDTExecutor.java
@@ -63,27 +63,48 @@ public class AWTEDTExecutor implements RunnableExecutor {
}
/**
- * Executes the given runnable on the AWT EDT if current thread is not the EDT and the given tree
- * lock is not hold, otherwise execute the runnable in current thread.
+ * Executes the given runnable on the AWT-EDT and return <code>true</code>, if
+ * <ul>
+ * <li>current-thread is the AWT-EDT, <i>or</i></li>
+ * <li>the given tree-lock is not hold by current-thread (-> invoke on AWT-EDT)</li>
+ * </ul>
+ * <p>
+ * Otherwise execute the given runnable on the current-thread and return <code>true</code>, if
+ * <code>allowOnNonEDT</code> is <code>true</code>.<br/>
+ * This implies that the given tree-lock is being hold by the current-thread.
+ * </p>
+ * <p>
+ * Otherwise the runnable is not executed and <code>false</code> is returned.
+ * </p>
+ *
* @param treeLock representing the AWT-tree-lock, i.e. {@link java.awt.Component#getTreeLock()}
+ * @param allowOnNonEDT allow execution on non AWT-EDT in case current thread is not AWT-EDT and the tree-lock is being hold
* @param wait if true method waits until {@link Runnable#run()} is completed, otherwise don't wait.
* @param r the {@link Runnable} to be executed.
+ * @return <code>true</code> if the {@link Runnable} has been issued for execution, otherwise <code>false</code>
*/
- public void invoke(Object treeLock, boolean wait, Runnable r) {
- if(EventQueue.isDispatchThread() || Thread.holdsLock(treeLock)) {
+ public boolean invoke(Object treeLock, boolean allowOnNonEDT, boolean wait, Runnable r) {
+ if( EventQueue.isDispatchThread() ) {
r.run();
- } else {
- try {
- if(wait) {
- EventQueue.invokeAndWait(r);
- } else {
- EventQueue.invokeLater(r);
+ return true;
+ } else if ( !Thread.holdsLock(treeLock) ) {
+ try {
+ if(wait) {
+ EventQueue.invokeAndWait(r);
+ } else {
+ EventQueue.invokeLater(r);
+ }
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e.getTargetException());
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
}
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e.getTargetException());
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
+ return true;
+ } else if ( allowOnNonEDT ) {
+ r.run();
+ return true;
+ } else {
+ return false;
}
}
}