From aa4b8c9abbf9529fdbb3c4982895c01f2698451f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 2 Dec 2012 04:09:41 +0100 Subject: NEWT EDTUtil: Simplify running state (default is running @ setEDTUtil()); Simplify DefaultEDTUtil impl. and fix concurrency leak w/ 'shouldStop' --- src/newt/classes/com/jogamp/newt/Display.java | 12 +-- .../classes/com/jogamp/newt/swt/SWTEDTUtil.java | 5 +- src/newt/classes/com/jogamp/newt/util/EDTUtil.java | 3 +- src/newt/classes/jogamp/newt/DefaultEDTUtil.java | 99 +++++++++++----------- src/newt/classes/jogamp/newt/DisplayImpl.java | 33 ++++---- .../classes/jogamp/newt/driver/awt/AWTEDTUtil.java | 5 +- .../junit/newt/TestDisplayLifecycle01NEWT.java | 4 +- 7 files changed, 81 insertions(+), 80 deletions(-) diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java index 4c263a195..993aa33eb 100644 --- a/src/newt/classes/com/jogamp/newt/Display.java +++ b/src/newt/classes/com/jogamp/newt/Display.java @@ -158,19 +158,15 @@ public abstract class Display { *

*

* If a previous one exists and it differs from the new one, - * it's being stopped, wait-until-idle and reset to allow restart. + * it's being stopped, wait-until-idle and reset to allow a restart at a later time. *

*

* If newEDTUtil is not null and equals the previous one, - * null is returned and no change is being made. + * no change is being made. *

*

- * Note that newEDTUtil will not be started by this method. - * To do so you may issue {@link EDTUtil#invoke(boolean, Runnable) invoke} - * on the new EDTUtil: - *

-     *          newEDTUtil.invoke(true, null);
-     * 
+ * Note that newEDTUtil will be started by this method, + * if it is not running yet. *

*/ public abstract EDTUtil setEDTUtil(EDTUtil newEDTUtil); diff --git a/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java b/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java index 2203d744a..1c20fe524 100644 --- a/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java +++ b/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java @@ -150,7 +150,10 @@ public class SWTEDTUtil implements EDTUtil { // System.err.println(Thread.currentThread()+" XXX stop: "+stop+", tasks: "+edt.tasks.size()+", task: "+task); // Thread.dumpStack(); if(stop) { - nedt.shouldStop = true; + 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(); diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java index 293e13592..0183da592 100644 --- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java +++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java @@ -113,7 +113,8 @@ public interface EDTUtil { /** * Append the final task to the EDT task queue, - * signals EDT to stop and wait until stopped.
+ * signals EDT to stop and wait until stopped.
+ * task maybe null
* Due to the nature of this method: *