diff options
author | Sven Gothel <[email protected]> | 2012-11-30 15:02:07 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-11-30 15:02:07 +0100 |
commit | 9ddbfb35882aa4c361d161ab8aca91ed670a97c8 (patch) | |
tree | 870319d2056e3b4ea657222c3d5991f787948e3f /src/newt/classes/com/jogamp | |
parent | 0bb202f2883e1eb82256140f13310046f7b13c62 (diff) |
Simplify NEWT EDTUtil invoke: To start EDT Runnable maybe null - start EDT even if on EDT thread.
DEBUG: Name EDTUtil impl, e.g. Default, AWT and SWT
Diffstat (limited to 'src/newt/classes/com/jogamp')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/Display.java | 6 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java | 34 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/util/EDTUtil.java | 2 |
3 files changed, 19 insertions, 23 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java index e97dec88d..4c263a195 100644 --- a/src/newt/classes/com/jogamp/newt/Display.java +++ b/src/newt/classes/com/jogamp/newt/Display.java @@ -165,11 +165,11 @@ public abstract class Display { * <code>null</code> is returned and no change is being made. * </p> * <p> - * Note that <code>newEDTUtil</code> will not be started if not done so already, - * to do so you may issue {@link EDTUtil#invoke(boolean, Runnable) invoke} + * Note that <code>newEDTUtil</code> will not be started by this method. + * To do so you may issue {@link EDTUtil#invoke(boolean, Runnable) invoke} * on the new EDTUtil: * <pre> - * newEDTUtil.invoke(true, new Runnable() { public void run() { } } ); + * newEDTUtil.invoke(true, null); * </pre> * </p> */ diff --git a/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java b/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java index 42e1c9be5..2203d744a 100644 --- a/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java +++ b/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java @@ -27,8 +27,6 @@ */ package com.jogamp.newt.swt; -import java.awt.EventQueue; - import javax.media.nativewindow.NativeWindowException; import jogamp.newt.Debug; @@ -83,7 +81,7 @@ public class SWTEDTUtil implements EDTUtil { synchronized(edtLock) { waitUntilStopped(); if(DEBUG) { - System.err.println(Thread.currentThread()+": EDT reset - edt: "+nedt); + System.err.println(Thread.currentThread()+": SWT-EDT reset - edt: "+nedt); } this.nedt = new NewtEventDispatchThread(threadGroup, name); this.nedt.setDaemon(true); // don't stop JVM from shutdown .. @@ -92,13 +90,13 @@ public class SWTEDTUtil implements EDTUtil { private final void startImpl() { if(nedt.isAlive()) { - throw new RuntimeException("EDT Thread.isAlive(): true, isRunning: "+nedt.isRunning()+", edt: "+nedt); + throw new RuntimeException("SWT-EDT Thread.isAlive(): true, isRunning: "+nedt.isRunning()+", edt: "+nedt); } start_iter++; nedt.setName(name+start_iter); nedt.shouldStop = false; if(DEBUG) { - System.err.println(Thread.currentThread()+": EDT START - edt: "+nedt); + System.err.println(Thread.currentThread()+": SWT-EDT START - edt: "+nedt); // Thread.dumpStack(); } nedt.start(); @@ -136,9 +134,6 @@ public class SWTEDTUtil implements EDTUtil { } private void invokeImpl(boolean wait, Runnable task, boolean stop) { - if(task == null) { - throw new RuntimeException("Null Runnable"); - } Throwable throwable = null; RunnableTask rTask = null; Object rTaskLock = new Object(); @@ -147,7 +142,7 @@ public class SWTEDTUtil implements EDTUtil { if( nedt.shouldStop ) { // drop task .. if(DEBUG) { - System.err.println("Warning: EDT about (1) to stop, won't enqueue new task: "+nedt); + System.err.println(Thread.currentThread()+": Warning: SWT-EDT about (1) to stop, won't enqueue new task: "+nedt); Thread.dumpStack(); } return; @@ -157,20 +152,21 @@ public class SWTEDTUtil implements EDTUtil { if(stop) { nedt.shouldStop = true; if(DEBUG) { - System.err.println(Thread.currentThread()+": EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - "+nedt); + System.err.println(Thread.currentThread()+": SWT-EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - "+nedt); // Thread.dumpStack(); } + } else if( !nedt.isRunning() ) { + // start if should not stop && not started yet + startImpl(); } - if( isCurrentThreadEDT() ) { + if( null == task ) { + wait = false; + } else if( isCurrentThreadEDT() ) { task.run(); wait = false; // running in same thread (EDT) -> no wait } else if( swtDisplay.isDisposed() ) { wait = false; // drop task, SWT disposed } else { - // start if should not stop && not started yet - if( !stop && !nedt.isRunning() ) { - startImpl(); - } rTask = new RunnableTask(task, wait ? rTaskLock : null, true /* always catch and report Exceptions, don't disturb EDT */); @@ -255,7 +251,7 @@ public class SWTEDTUtil implements EDTUtil { @Override final public void run() { if(DEBUG) { - System.err.println(getName()+": EDT run() START "+ getName()); + System.err.println(getName()+": SWT-EDT run() START "+ getName()); } RuntimeException error = null; try { @@ -289,11 +285,11 @@ public class SWTEDTUtil implements EDTUtil { if(t instanceof RuntimeException) { error = (RuntimeException) t; } else { - error = new RuntimeException("Within EDT", t); + error = new RuntimeException("Within SWT-EDT", t); } } finally { if(DEBUG) { - System.err.println(getName()+": EDT run() END "+ getName()+", "+error); + System.err.println(getName()+": SWT-EDT run() END "+ getName()+", "+error); } synchronized(edtLock) { isRunning = !shouldStop; @@ -302,7 +298,7 @@ public class SWTEDTUtil implements EDTUtil { } } if(DEBUG) { - System.err.println(getName()+": EDT run() EXIT "+ getName()+", exception: "+error); + System.err.println(getName()+": SWT-EDT run() EXIT "+ getName()+", exception: "+error); } if(null!=error) { throw error; diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java index 7e19d9de5..293e13592 100644 --- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java +++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java @@ -125,7 +125,7 @@ public interface EDTUtil { public void invokeStop(Runnable finalTask); /** - * Shall start the thread if not running.<br> + * Shall start the thread if not running, <code>task</code> maybe null for this purpose.<br> * Append task to the EDT task queue.<br> * Wait until execution is finished if <code>wait == true</code>.<br> * Can be issued from within EDT, ie from within an enqueued task.<br> |