From a584e5dd4b40afec3cc04e1ce4abe3eb2f86e04c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 25 Jun 2013 07:02:48 +0200 Subject: NEWT: EDTUtil.invokeStop(..) gets 'wait' argument, allowing non-blocking shutdown. DisplayImpl.shutdownAll(): Don't block. --- src/newt/classes/jogamp/newt/DefaultEDTUtil.java | 4 ++-- src/newt/classes/jogamp/newt/DisplayImpl.java | 18 ++++++++++++++---- .../classes/jogamp/newt/driver/awt/AWTEDTUtil.java | 4 ++-- src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java | 4 ++-- 4 files changed, 20 insertions(+), 10 deletions(-) (limited to 'src/newt/classes/jogamp') 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 -- cgit v1.2.3