aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-06-25 07:02:48 +0200
committerSven Gothel <[email protected]>2013-06-25 07:02:48 +0200
commita584e5dd4b40afec3cc04e1ce4abe3eb2f86e04c (patch)
treed9b2e5660baf0b129718d2d98e7e6b826eaa85fc /src
parent415f5c29ffae7cf5a26737da38e31cb84b652539 (diff)
NEWT: EDTUtil.invokeStop(..) gets 'wait' argument, allowing non-blocking shutdown. DisplayImpl.shutdownAll(): Don't block.
Diffstat (limited to 'src')
-rw-r--r--src/newt/classes/com/jogamp/newt/util/EDTUtil.java14
-rw-r--r--src/newt/classes/jogamp/newt/DefaultEDTUtil.java4
-rw-r--r--src/newt/classes/jogamp/newt/DisplayImpl.java18
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java4
-rw-r--r--src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java4
5 files changed, 30 insertions, 14 deletions
diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
index 0183da592..0df815609 100644
--- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
+++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
@@ -70,7 +70,7 @@ public interface EDTUtil {
* is expected.
*
* @see #invoke(boolean, java.lang.Runnable)
- * @see #invokeStop(java.lang.Runnable)
+ * @see #invokeStop(boolean, java.lang.Runnable)
*/
public void reset();
@@ -113,7 +113,12 @@ public interface EDTUtil {
/**
* Append the final task to the EDT task queue,
- * signals EDT to stop and wait until stopped.<br/>
+ * signals EDT to stop.
+ * <p>
+ * If <code>wait</code> is <code>true</code> methods
+ * blocks until EDT is stopped.
+ * </p>
+ * <p>
* <code>task</code> maybe <code>null</code><br/>
* Due to the nature of this method:
* <ul>
@@ -122,8 +127,9 @@ public interface EDTUtil {
* <li>Can be issued from within EDT, ie from within an enqueued task.</li>
* <li>{@link #reset()} may follow immediately, ie creating a new EDT</li>
* </ul>
+ * </p>
*/
- public void invokeStop(Runnable finalTask);
+ public void invokeStop(boolean wait, Runnable finalTask);
/**
* Shall start the thread if not running, <code>task</code> maybe null for this purpose.<br>
@@ -143,7 +149,7 @@ public interface EDTUtil {
/**
* Wait until EDT task is stopped.<br>
- * No <code>stop</code> action is performed, {@link #invokeStop(java.lang.Runnable)} should be used before.
+ * No <code>stop</code> action is performed, {@link #invokeStop(boolean, java.lang.Runnable)} should be used before.
*/
public void waitUntilStopped();
}
diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
index 651522799..c080e8380 100644
--- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
@@ -126,8 +126,8 @@ public class DefaultEDTUtil implements EDTUtil {
}
@Override
- public final void invokeStop(Runnable task) {
- invokeImpl(true, task, true);
+ public final void invokeStop(boolean wait, Runnable task) {
+ invokeImpl(wait, task, true);
}
@Override
diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java
index 3edb532db..0d1dcf5ab 100644
--- a/src/newt/classes/jogamp/newt/DisplayImpl.java
+++ b/src/newt/classes/jogamp/newt/DisplayImpl.java
@@ -207,7 +207,7 @@ public abstract class DisplayImpl extends Display {
private void removeEDT(final Runnable task) {
if(null!=edtUtil) {
- edtUtil.invokeStop(task);
+ edtUtil.invokeStop(true, task);
// ready for restart ..
edtUtil.waitUntilStopped();
edtUtil.reset();
@@ -261,7 +261,7 @@ public abstract class DisplayImpl extends Display {
}
}
- /** Maybe utilized at a shutdown hook, impl. does not synchronize, however the EDT removal blocks. */
+ /** May be utilized at a shutdown hook, impl. does not block. */
/* pp */ static final void shutdownAll() {
final int dCount = displayList.size();
if(DEBUG) {
@@ -275,13 +275,23 @@ public abstract class DisplayImpl extends Display {
if(DEBUG) {
System.err.println("Display.shutdownAll["+(i+1)+"/"+dCount+"]: "+d);
}
- d.removeEDT( new Runnable() {
+ final Runnable closeNativeTask = new Runnable() {
public void run() {
if ( null != d.getGraphicsDevice() ) {
d.closeNativeImpl();
}
}
- } );
+ };
+ final EDTUtil edtUtil = d.getEDTUtil();
+ if(null != edtUtil) {
+ final long coopSleep = edtUtil.getPollPeriod() * 2;
+ edtUtil.invokeStop(false, closeNativeTask); // don't block
+ try {
+ Thread.sleep( coopSleep < 50 ? coopSleep : 50 );
+ } catch (InterruptedException e) { }
+ } else {
+ closeNativeTask.run();
+ }
d.aDevice = null;
d.refCount=0;
}
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
index fc9bbb848..0cc5ddb3e 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
@@ -114,8 +114,8 @@ public class AWTEDTUtil implements EDTUtil {
}
@Override
- public final void invokeStop(Runnable task) {
- invokeImpl(true, task, true);
+ public final void invokeStop(boolean wait, Runnable task) {
+ invokeImpl(wait, task, true);
}
@Override
diff --git a/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java b/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java
index 2008b5ea4..77049a010 100644
--- a/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java
@@ -124,8 +124,8 @@ public class SWTEDTUtil implements EDTUtil {
}
@Override
- public final void invokeStop(Runnable task) {
- invokeImpl(true, task, true);
+ public final void invokeStop(boolean wait, Runnable task) {
+ invokeImpl(wait, task, true);
}
@Override