From 3ed491213f8f7f05d7b9866b50d764370d8ff5f6 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 25 Mar 2012 03:29:53 +0200 Subject: Enhance and generalize AWT Threading* implementation; Minor changes .. Threading*: - add invoke(..) generalizing the Therading decision GLCanvas: - remove 'manual' Threading decision, simply call Threading.invoke(..) - use anonymous Runnable instances - remove drawable lock, drawable is volatile instead GLJPanel: - remove 'manual' Threading decision, simply call Threading.invoke(..) - use anonymous Runnable instances - DEBUG: Use getThreadName() prefix GLContextImpl: - Remove GLWorkerThread idle command on makeCurrent(), no holding of context in worker thread while idle. - DEBUG: Use getThreadName() prefix X11GLXContext: - DEBUG: Use getThreadName() prefix TODO: Validate whether it's OK for GLCanvas and GLJPanel to set Threading.Mode.MT as the default mode! --- .../classes/jogamp/newt/driver/awt/AWTEDTUtil.java | 68 +++------------------- 1 file changed, 8 insertions(+), 60 deletions(-) (limited to 'src/newt') diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java index 6d0b102c7..942651187 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java @@ -28,27 +28,15 @@ package jogamp.newt.driver.awt; -import java.awt.EventQueue; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; +import javax.media.opengl.Threading; -import javax.media.nativewindow.NativeWindowException; - -import com.jogamp.newt.Display; import com.jogamp.newt.util.EDTUtil; import jogamp.newt.Debug; public class AWTEDTUtil implements EDTUtil { public static final boolean DEBUG = Debug.debug("EDT"); - private static Timer pumpMessagesTimer=null; - private static TimerTask pumpMessagesTimerTask=null; - private static final Map pumpMessageDisplayMap = new HashMap(); private static AWTEDTUtil singletonMainThread = new AWTEDTUtil(); // one singleton MainThread - private static long pollPeriod = EDTUtil.defaultEDTPollPeriod; public static AWTEDTUtil getSingleton() { return singletonMainThread; @@ -59,11 +47,11 @@ public class AWTEDTUtil implements EDTUtil { } final public long getPollPeriod() { - return pollPeriod; + return 0; } final public void setPollPeriod(long ms) { - pollPeriod = ms; + // nop } final public void reset() { @@ -75,7 +63,7 @@ public class AWTEDTUtil implements EDTUtil { } final public boolean isCurrentThreadEDT() { - return EventQueue.isDispatchThread(); + return Threading.isToolkitThread(); } final public boolean isRunning() { @@ -90,62 +78,22 @@ public class AWTEDTUtil implements EDTUtil { if(r == null) { return; } - - // handover to AWT MainThread .. - try { - if ( isCurrentThreadEDT() ) { - r.run(); - return; - } - if(wait) { - EventQueue.invokeAndWait(r); - } else { - EventQueue.invokeLater(r); - } - } catch (Exception e) { - throw new NativeWindowException(e); - } + + Threading.invoke(wait, r, null); } final public void waitUntilIdle() { // wait until previous events are processed, at least .. try { - EventQueue.invokeAndWait( new Runnable() { + Threading.invoke(true, new Runnable() { public void run() { } - }); + }, null); } catch (Exception e) { } } final public void waitUntilStopped() { // nop: AWT is always running } - - public static void addPumpMessage(Display dpy, Runnable pumpMessage) { - if(DEBUG) { - System.err.println("AWTEDTUtil.addPumpMessage(): "+Thread.currentThread().getName()+" - dpy "+dpy); - } - - synchronized (pumpMessageDisplayMap) { - if(null == pumpMessagesTimer) { - // AWT pump messages .. MAIN_THREAD uses main thread - pumpMessagesTimer = new Timer(); - pumpMessagesTimerTask = new TimerTask() { - public void run() { - synchronized(pumpMessageDisplayMap) { - for(Iterator i = pumpMessageDisplayMap.values().iterator(); i.hasNext(); ) { - AWTEDTUtil.getSingleton().invoke(true, i.next()); - // AWTEDTUtil.getSingleton().invoke(false, i.next()); - // i.next().run(); - } - } - } - }; - pumpMessagesTimer.scheduleAtFixedRate(pumpMessagesTimerTask, 0, pollPeriod); - } - pumpMessageDisplayMap.put(dpy, pumpMessage); - } - } - } -- cgit v1.2.3