diff options
author | Sven Gothel <[email protected]> | 2013-10-09 02:10:19 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-10-09 02:10:19 +0200 |
commit | 56502090ba5c2e0c266666a4ba3ddd501e9ad95f (patch) | |
tree | 59ab9e12de5be7b78f83360f0fe7009d433751a6 /src/newt/classes/jogamp | |
parent | 88291cd5e20fc8b172f1d78a683be7d2bdec807a (diff) |
NEWT Display: Issue EDTUtil.start() at runOnEDTIfAvail(..) even if on EDT, which is to be stopped.
This case appears on e.g. OSX/CALayer (offscreen) reparenting using recreation (onscreen <-> offscreen),
i.e. display destroy/create is performed on EDT.
Misc Cleanup:
- Rename EDTUtil: restart() -> start()
- Rename Display: validateEDT() -> validateEDTStopped()
- Simplify Display.setEDTUtil(..): Remove need for redundant 'newEDTUtil' local var.
- Simplify Display.runOnEDTIfAvail(..): edtUtil is never null
Diffstat (limited to 'src/newt/classes/jogamp')
4 files changed, 32 insertions, 32 deletions
diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java index 5794d4ae9..3d1037ad5 100644 --- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java +++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java @@ -77,7 +77,7 @@ public class DefaultEDTUtil implements EDTUtil { } @Override - public final boolean restart() throws IllegalStateException { + public final boolean start() throws IllegalStateException { synchronized(edtLock) { if( edt.isRunning() ) { throw new IllegalStateException("EDT still running and not subject to stop. Curr "+Thread.currentThread().getName()+", EDT "+edt.getName()+", isRunning "+edt.isRunning+", shouldStop "+edt.shouldStop); @@ -135,6 +135,10 @@ public class DefaultEDTUtil implements EDTUtil { @Override public final boolean invokeStop(boolean wait, Runnable task) { + if(DEBUG) { + System.err.println(Thread.currentThread()+": Default-EDT.invokeStop wait "+wait); + Thread.dumpStack(); + } return invokeImpl(wait, task, true); } diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java index 8f792b23c..0f47c87a0 100644 --- a/src/newt/classes/jogamp/newt/DisplayImpl.java +++ b/src/newt/classes/jogamp/newt/DisplayImpl.java @@ -170,7 +170,7 @@ public abstract class DisplayImpl extends Display { if(NewtFactory.useEDT()) { def = new DefaultEDTUtil(Thread.currentThread().getThreadGroup(), "Display-"+getFQName(), dispatchMessagesRunnable); if(DEBUG) { - System.err.println("Display.createNative("+getFQName()+") Create EDTUtil: "+def.getClass().getName()); + System.err.println("Display.createEDTUtil("+getFQName()+"): "+def.getClass().getName()); } } else { def = null; @@ -181,21 +181,18 @@ public abstract class DisplayImpl extends Display { @Override public synchronized EDTUtil setEDTUtil(final EDTUtil usrEDTUtil) { final EDTUtil oldEDTUtil = edtUtil; - final EDTUtil newEDTUtil; if( null != usrEDTUtil && usrEDTUtil == oldEDTUtil ) { if( DEBUG ) { System.err.println("Display.setEDTUtil: "+usrEDTUtil+" - keep!"); } - newEDTUtil = oldEDTUtil; - } else { - if(DEBUG) { - final String msg = ( null == usrEDTUtil ) ? "default" : "custom"; - System.err.println("Display.setEDTUtil("+msg+"): "+oldEDTUtil+" -> "+usrEDTUtil); - } - stopEDT( oldEDTUtil, null ); - newEDTUtil = ( null == usrEDTUtil ) ? createEDTUtil() : usrEDTUtil; + return oldEDTUtil; + } + if(DEBUG) { + final String msg = ( null == usrEDTUtil ) ? "default" : "custom"; + System.err.println("Display.setEDTUtil("+msg+"): "+oldEDTUtil+" -> "+usrEDTUtil); } - edtUtil = newEDTUtil; + stopEDT( oldEDTUtil, null ); + edtUtil = ( null == usrEDTUtil ) ? createEDTUtil() : usrEDTUtil; return oldEDTUtil; } @@ -224,31 +221,30 @@ public abstract class DisplayImpl extends Display { public void runOnEDTIfAvail(boolean wait, final Runnable task) { final EDTUtil _edtUtil = edtUtil; - if( null != _edtUtil && !_edtUtil.isCurrentThreadEDT() ) { - if( !_edtUtil.isRunning() ) { // start EDT if not running yet - synchronized( this ) { - if( !_edtUtil.isRunning() ) { // // volatile dbl-checked-locking OK - _edtUtil.restart(); - if( DEBUG ) { - System.err.println("Info: EDT started "+Thread.currentThread().getName()+", "+this); - Thread.dumpStack(); - } + if( !_edtUtil.isRunning() ) { // start EDT if not running yet + synchronized( this ) { + if( !_edtUtil.isRunning() ) { // // volatile dbl-checked-locking OK + if( DEBUG ) { + System.err.println("Info: EDT start "+Thread.currentThread().getName()+", "+this); + Thread.dumpStack(); } + _edtUtil.start(); } } - if( !_edtUtil.invoke(wait, task) ) { - if( DEBUG ) { - System.err.println("Warning: invoke(wait "+wait+", ..) on EDT failed .. invoke on current thread "+Thread.currentThread().getName()); - Thread.dumpStack(); - } - task.run(); + } + if( !_edtUtil.isCurrentThreadEDT() ) { + if( _edtUtil.invoke(wait, task) ) { + return; // done + } + if( DEBUG ) { + System.err.println("Warning: invoke(wait "+wait+", ..) on EDT failed .. invoke on current thread "+Thread.currentThread().getName()); + Thread.dumpStack(); } - } else { - task.run(); } + task.run(); } - public boolean validateEDT() { + public boolean validateEDTStopped() { if( 0==refCount && null == aDevice ) { final EDTUtil _edtUtil = edtUtil; if( null != _edtUtil && _edtUtil.isRunning() ) { diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java index 80c72c008..02f4be0cd 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java @@ -68,7 +68,7 @@ public class AWTEDTUtil implements EDTUtil { } @Override - public final boolean restart() throws IllegalStateException { + public final boolean start() throws IllegalStateException { synchronized(edtLock) { if( nedt.isRunning() ) { throw new IllegalStateException("EDT still running and not subject to stop. Curr "+Thread.currentThread().getName()+", NEDT "+nedt.getName()+", isRunning "+nedt.isRunning+", shouldStop "+nedt.shouldStop+", on AWT-EDT "+EventQueue.isDispatchThread()); diff --git a/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java b/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java index d46562050..6024195e3 100644 --- a/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java +++ b/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java @@ -77,7 +77,7 @@ public class SWTEDTUtil implements EDTUtil { } @Override - public final boolean restart() throws IllegalStateException { + public final boolean start() throws IllegalStateException { final boolean swtDisposed = swtDisplay.isDisposed(); synchronized(edtLock) { if( nedt.isRunning() ) { |