diff options
-rw-r--r-- | make/scripts/tests.sh | 6 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/util/EDTUtil.java | 15 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/DefaultEDTUtil.java | 11 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/DisplayImpl.java | 2 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java | 25 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java | 53 |
6 files changed, 70 insertions, 42 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index c4520c8e7..dbc795992 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -152,7 +152,7 @@ function jrun() { #D_ARGS="-Djogl.debug.GLProfile" #D_ARGS="-Dnativewindow.debug.NativeWindow -Dnewt.debug.Window -Dnewt.debug.Screen -Dnewt.debug.Display" #D_ARGS="-Djogl.debug.GLCanvas -Dnewt.debug.Window -Dnewt.debug.Display -Dnewt.debug.EDT -Djogl.debug.Animator" - #D_ARGS="-Dnewt.debug.Display -Dnewt.debug.EDT" + D_ARGS="-Dnewt.debug.Display -Dnewt.debug.EDT" #D_ARGS="-Dnewt.debug.EDT -Dnewt.debug.Window -Djogl.debug.GLContext" #D_ARGS="-Dnativewindow.debug.X11Util.XErrorStackDump -Dnativewindow.debug.X11Util.TraceDisplayLifecycle -Dnativewindow.debug.X11Util" #D_ARGS="-Dnativewindow.debug.X11Util -Djogl.debug.GLContext -Djogl.debug.GLDrawable -Dnewt.debug=all" @@ -461,7 +461,7 @@ function testawtswt() { # #testswt com.jogamp.opengl.test.junit.jogl.swt.TestSWTEclipseGLCanvas01GLn $* #testswt com.jogamp.opengl.test.junit.jogl.swt.TestSWTJOGLGLCanvas01GLn $* -#testswt com.jogamp.opengl.test.junit.jogl.swt.TestNewtCanvasSWTGLn $* +testswt com.jogamp.opengl.test.junit.jogl.swt.TestNewtCanvasSWTGLn $* # # awtswt (testawtswt) @@ -515,7 +515,7 @@ function testawtswt() { # # NEWT Parenting (w/ NEWT, AWT or SWT) # -testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT $* +#testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting02NEWT $* #testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocusTraversal01AWT $* #testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01cSwingAWT $* diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java index 0df815609..75848785c 100644 --- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java +++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java @@ -65,14 +65,18 @@ public interface EDTUtil { public void setPollPeriod(long ms); /** - * Create a new EDT. One should invoke <code>reset()</code><br> - * after <code>invokeStop(..)</code> in case another start via <code>invoke(..)</code> - * is expected. + * Resets the stopped EDT, i.e. prepares it for a restart via + * the next <code>invoke(..)</code> call. + * <p> + * One must stop the EDT first via {@link #invokeStop(boolean, Runnable)} + * and wait until it's stopped via {@link #waitUntilStopped()}. + * </p> * * @see #invoke(boolean, java.lang.Runnable) * @see #invokeStop(boolean, java.lang.Runnable) + * @throws IllegalStateException if stop has not been issued, or EDT is still running (caller thread not being EDT or NEDT). */ - public void reset(); + public void reset() throws IllegalStateException; /** * Returns true if the current thread is the event dispatch thread (EDT). @@ -150,6 +154,9 @@ public interface EDTUtil { /** * Wait until EDT task is stopped.<br> * No <code>stop</code> action is performed, {@link #invokeStop(boolean, java.lang.Runnable)} should be used before. + * <p> + * If caller thread is EDT or NEDT, this call will not block. + * </p> */ public void waitUntilStopped(); } diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java index f8ee31a06..ecd94c278 100644 --- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java +++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java @@ -76,9 +76,14 @@ public class DefaultEDTUtil implements EDTUtil { } @Override - public final void reset() { - synchronized(edtLock) { - waitUntilStopped(); + public final void reset() throws IllegalStateException { + synchronized(edtLock) { + if( isRunning() ) { + if( !edt.shouldStop ) { + throw new IllegalStateException("EDT stop not issued."); + } + throw new IllegalStateException("EDT still running"); + } if(DEBUG) { if(edt.tasks.size()>0) { System.err.println(Thread.currentThread()+": Default-EDT reset, remaining tasks: "+edt.tasks.size()+" - "+edt); diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java index 09ea05e88..884ddac57 100644 --- a/src/newt/classes/jogamp/newt/DisplayImpl.java +++ b/src/newt/classes/jogamp/newt/DisplayImpl.java @@ -208,7 +208,7 @@ public abstract class DisplayImpl extends Display { } private void removeEDT(final Runnable task) { - if(null!=edtUtil) { + if(null!=edtUtil) { edtUtil.invokeStop(true, task); // ready for restart .. edtUtil.waitUntilStopped(); diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java index 0cc5ddb3e..abd47d17e 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java @@ -68,9 +68,18 @@ public class AWTEDTUtil implements EDTUtil { } @Override - final public void reset() { - synchronized(edtLock) { - waitUntilStopped(); + public final void reset() throws IllegalStateException { + synchronized(edtLock) { + final Thread curT = Thread.currentThread(); + final boolean onAWTEDT = EventQueue.isDispatchThread(); + if( nedt.isRunning() ) { + if( !nedt.shouldStop ) { + throw new IllegalStateException("EDT stop not issued."); + } + if( nedt != curT && !onAWTEDT ) { + throw new IllegalStateException("EDT still running: Curr "+curT.getName()+", NEDT "+nedt.getName()+", on AWT-EDT "+onAWTEDT); + } + } if(DEBUG) { System.err.println(Thread.currentThread()+": AWT-EDT reset - edt: "+nedt); } @@ -110,7 +119,7 @@ public class AWTEDTUtil implements EDTUtil { @Override final public boolean isRunning() { - return nedt.isRunning() ; // AWT is always running + return nedt.isRunning() ; } @Override @@ -203,7 +212,7 @@ public class AWTEDTUtil implements EDTUtil { @Override final public void waitUntilStopped() { synchronized(edtLock) { - if(nedt.isRunning() && nedt != Thread.currentThread() && !EventQueue.isDispatchThread()) { + if( nedt.isRunning() && nedt != Thread.currentThread() && !EventQueue.isDispatchThread() ) { while(nedt.isRunning()) { try { edtLock.wait(); @@ -278,10 +287,8 @@ public class AWTEDTUtil implements EDTUtil { System.err.println(getName()+": AWT-EDT run() END "+ getName()+", "+error); } synchronized(edtLock) { - isRunning = !shouldStop; - if(!isRunning) { - edtLock.notifyAll(); - } + isRunning = false; + edtLock.notifyAll(); } if(DEBUG) { System.err.println(getName()+": AWT-EDT run() EXIT "+ getName()+", exception: "+error); diff --git a/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java b/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java index 77049a010..a8e03c510 100644 --- a/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java +++ b/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java @@ -77,9 +77,19 @@ public class SWTEDTUtil implements EDTUtil { } @Override - public void reset() { - synchronized(edtLock) { - waitUntilStopped(); + public final void reset() throws IllegalStateException { + synchronized(edtLock) { + final Thread curT = Thread.currentThread(); + final Thread swtT = !swtDisplay.isDisposed() ? swtDisplay.getThread() : null; + final boolean onSWTEDT = swtT == curT; + if( nedt.isRunning() ) { + if( !nedt.shouldStop ) { + throw new IllegalStateException("EDT stop not issued."); + } + if( nedt != curT && !onSWTEDT ) { + throw new IllegalStateException("EDT still running: Curr "+curT.getName()+", NEDT "+nedt.getName()+", SWT-EDT "+swtT.getName()); + } + } if(DEBUG) { System.err.println(Thread.currentThread()+": SWT-EDT reset - edt: "+nedt); } @@ -104,7 +114,7 @@ public class SWTEDTUtil implements EDTUtil { @Override public boolean isCurrentThreadEDT() { - return swtDisplay.getThread() == Thread.currentThread(); + return !swtDisplay.isDisposed() && swtDisplay.getThread() == Thread.currentThread(); } @Override @@ -115,12 +125,12 @@ public class SWTEDTUtil implements EDTUtil { @Override public final boolean isCurrentThreadEDTorNEDT() { final Thread ct = Thread.currentThread(); - return ct == swtDisplay.getThread() || ct == nedt ; + return ( !swtDisplay.isDisposed() && ct == swtDisplay.getThread() ) || ct == nedt ; } @Override public boolean isRunning() { - return nedt.isRunning() ; // SWT is always running + return nedt.isRunning() ; } @Override @@ -142,33 +152,32 @@ public class SWTEDTUtil implements EDTUtil { if( nedt.shouldStop ) { // drop task .. if(DEBUG) { - System.err.println(Thread.currentThread()+": Warning: SWT-EDT about (1) to stop, won't enqueue new task: "+nedt); - Thread.dumpStack(); + System.err.println(Thread.currentThread()+": Warning: SWT-EDT about (1) to stop, won't enqueue new task: "+nedt+", isRunning "+nedt.isRunning()); + // Thread.dumpStack(); } return; } // System.err.println(Thread.currentThread()+" XXX stop: "+stop+", tasks: "+edt.tasks.size()+", task: "+task); // Thread.dumpStack(); if(stop) { + if(DEBUG) { + System.err.println(Thread.currentThread()+": SWT-EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - "+nedt+", isRunning "+nedt.isRunning()); + } synchronized(nedt.sync) { nedt.shouldStop = true; nedt.sync.notifyAll(); // stop immediate if waiting (poll freq) } - if(DEBUG) { - System.err.println(Thread.currentThread()+": SWT-EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - "+nedt); - // Thread.dumpStack(); - } - } else if( !nedt.isRunning() ) { + } else if( !nedt.isRunning() && !swtDisplay.isDisposed() ) { // start if should not stop && not started yet startImpl(); } if( null == task ) { wait = false; + } else if( swtDisplay.isDisposed() ) { + wait = false; // drop task, SWT disposed } 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 { rTask = new RunnableTask(task, wait ? rTaskLock : null, @@ -203,7 +212,7 @@ public class SWTEDTUtil implements EDTUtil { _nedt = nedt; } final Thread ct = Thread.currentThread(); - if(!_nedt.isRunning() || _nedt == ct || swtDisplay.getThread() == ct) { + if( !_nedt.isRunning() || _nedt == ct || swtDisplay.isDisposed() || swtDisplay.getThread() == ct ) { return; } try { @@ -216,8 +225,10 @@ public class SWTEDTUtil implements EDTUtil { @Override final public void waitUntilStopped() { synchronized(edtLock) { - final Thread ct = Thread.currentThread(); - if(nedt.isRunning() && nedt != ct && swtDisplay.getThread() != ct) { + final Thread curT = Thread.currentThread(); + final Thread swtT = !swtDisplay.isDisposed() ? swtDisplay.getThread() : null; + final boolean onSWTEDT = swtT == curT; + if( nedt.isRunning() && nedt != curT && !onSWTEDT ) { while(nedt.isRunning()) { try { edtLock.wait(); @@ -296,10 +307,8 @@ public class SWTEDTUtil implements EDTUtil { System.err.println(getName()+": SWT-EDT run() END "+ getName()+", "+error); } synchronized(edtLock) { - isRunning = !shouldStop; - if(!isRunning) { - edtLock.notifyAll(); - } + isRunning = false; + edtLock.notifyAll(); } if(DEBUG) { System.err.println(getName()+": SWT-EDT run() EXIT "+ getName()+", exception: "+error); |