From fa35bd758189051dc25b8a0d32dc52360cfbc390 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 27 Sep 2011 12:51:47 +0200 Subject: NEWT/Threading: MainThread / DefaultEDTUtil - MainThread: This class no more implements EDTUtil! This class just provides a main-thread utility, forking of a main java class on another thread while being able to continue doing platform specific things on the main-thread. The latter is essential for eg. MacOSX, where we continue to run NSApp.run(). - DefaultEDTUtil: - if Lock.DEBUG validate that no recursive locks are being hold, where it shall not (EDT: startup and return from task execution) - If task execution's result wasn't waited for (checked), at least dump exeception's stack trace if i happened. - MacDisplay: Just use DefaultEDTUtil - MacWindow: - No more need of special locking -> removed nsViewLock, since: - using proper EDT - capability to run from multiple threads (native Java thread attachment) --- .../classes/com/jogamp/newt/util/MainThread.java | 87 ++++------------------ 1 file changed, 13 insertions(+), 74 deletions(-) (limited to 'src/newt/classes/com/jogamp') diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java index f74845afc..8de77420f 100644 --- a/src/newt/classes/com/jogamp/newt/util/MainThread.java +++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java @@ -41,23 +41,26 @@ import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; import java.security.AccessControlContext; import java.security.AccessController; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; import javax.media.nativewindow.NativeWindowFactory; import com.jogamp.common.os.Platform; import com.jogamp.common.util.ReflectionUtil; -import com.jogamp.newt.Display; import jogamp.newt.Debug; -import jogamp.newt.DefaultEDTUtil; import jogamp.newt.NEWTJNILibLoader; /** * NEWT Utility class MainThread

* + *

+ * FIXME: Update this documentation! + * This class just provides a main-thread utility, forking of a main java class + * on another thread while being able to continue doing platform specific things + * on the main-thread. The latter is essential for eg. MacOSX, where we continue + * to run NSApp.run(). + *

+ * * This class provides a startup singleton main thread, * from which a new thread with the users main class is launched.
* @@ -88,7 +91,7 @@ import jogamp.newt.NEWTJNILibLoader; * Which starts 4 threads, each with a window and OpenGL rendering.
*/ -public class MainThread implements EDTUtil { +public class MainThread { private static final String MACOSXDisplayClassName = "jogamp.newt.driver.macosx.MacDisplay"; /** if true, use the main thread EDT, otherwise AWT's EDT */ @@ -109,8 +112,6 @@ public class MainThread implements EDTUtil { private static final MainThread singletonMainThread = new MainThread(); // one singleton MainThread - private static final Map pumpMessageDisplayMap = new HashMap(); - static class MainAction extends Thread { private String mainClassName; private String[] mainClassArgs; @@ -148,10 +149,6 @@ public class MainThread implements EDTUtil { if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" user app fin"); if ( useMainThread ) { - singletonMainThread.invokeStop(new Runnable() { - public void run() { - // nop - }}); if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" MainThread fin - stop"); System.exit(0); } @@ -159,8 +156,6 @@ public class MainThread implements EDTUtil { } private static MainAction mainAction; - private static EDTUtil internalEDT; - /** Your new java application main entry, which pipelines your application */ public static void main(String[] args) { useMainThread = HINT_USE_MAIN_THREAD; @@ -197,26 +192,21 @@ public class MainThread implements EDTUtil { } if ( useMainThread ) { - final Thread current = Thread.currentThread(); - internalEDT = new DefaultEDTUtil(current.getThreadGroup(), "MainThread", new Runnable() { - public void run() { dispatchMessages(); } }); - - if(DEBUG) System.err.println("MainThread - run: "+internalEDT.toString()); - internalEDT.start(); // forever ! - // dispatch user's main thread .. mainAction.start(); if(isMacOSX) { try { - if(DEBUG) System.err.println("MainThread - runNSApp"); + if(DEBUG) { + System.err.println("MainThread.main(): "+Thread.currentThread().getName()+"- runNSApp"); + } ReflectionUtil.callStaticMethod(MACOSXDisplayClassName, "runNSApplication", null, null, MainThread.class.getClassLoader()); } catch (Exception e) { e.printStackTrace(); } } - if(DEBUG) System.err.println("MainThread - wait until last non daemon thread ends ..."); + if(DEBUG) { System.err.println("MainThread - wait until last non daemon thread ends ..."); } } else { // run user's main in this thread mainAction.run(); @@ -227,57 +217,6 @@ public class MainThread implements EDTUtil { return singletonMainThread; } - public static Runnable removePumpMessage(Display dpy) { - synchronized(pumpMessageDisplayMap) { - return pumpMessageDisplayMap.remove(dpy); - } - } - - public static void addPumpMessage(Display dpy, Runnable pumpMessage) { - synchronized (pumpMessageDisplayMap) { - pumpMessageDisplayMap.put(dpy, pumpMessage); - } - } - - private static void dispatchMessages() { - synchronized(pumpMessageDisplayMap) { - for(Iterator i = pumpMessageDisplayMap.values().iterator(); i.hasNext(); ) { - i.next().run(); - } - } - } - - final public void reset() { - // nop: ALWAYS RUNNING - } - - final public void start() { - // nop: ALWAYS RUNNING - } - - final public boolean isCurrentThreadEDT() { - return internalEDT.isCurrentThreadEDT(); - } - - final public boolean isRunning() { - return true; // ALWAYS RUNNING - } - - final public void invokeStop(Runnable r) { - internalEDT.invoke(true, r); // ALWAYS RUNNING - } - - final public void invoke(boolean wait, Runnable r) { - internalEDT.invoke(wait, r); - } - - final public void waitUntilIdle() { - internalEDT.waitUntilIdle(); - } - - final public void waitUntilStopped() { - // nop: ALWAYS RUNNING - } } -- cgit v1.2.3