summaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-11-30 15:02:07 +0100
committerSven Gothel <[email protected]>2012-11-30 15:02:07 +0100
commit9ddbfb35882aa4c361d161ab8aca91ed670a97c8 (patch)
tree870319d2056e3b4ea657222c3d5991f787948e3f /src/newt/classes
parent0bb202f2883e1eb82256140f13310046f7b13c62 (diff)
Simplify NEWT EDTUtil invoke: To start EDT Runnable maybe null - start EDT even if on EDT thread.
DEBUG: Name EDTUtil impl, e.g. Default, AWT and SWT
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/Display.java6
-rw-r--r--src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java34
-rw-r--r--src/newt/classes/com/jogamp/newt/util/EDTUtil.java2
-rw-r--r--src/newt/classes/jogamp/newt/DefaultEDTUtil.java42
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java32
5 files changed, 54 insertions, 62 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java
index e97dec88d..4c263a195 100644
--- a/src/newt/classes/com/jogamp/newt/Display.java
+++ b/src/newt/classes/com/jogamp/newt/Display.java
@@ -165,11 +165,11 @@ public abstract class Display {
* <code>null</code> is returned and no change is being made.
* </p>
* <p>
- * Note that <code>newEDTUtil</code> will not be started if not done so already,
- * to do so you may issue {@link EDTUtil#invoke(boolean, Runnable) invoke}
+ * Note that <code>newEDTUtil</code> will not be started by this method.
+ * To do so you may issue {@link EDTUtil#invoke(boolean, Runnable) invoke}
* on the new EDTUtil:
* <pre>
- * newEDTUtil.invoke(true, new Runnable() { public void run() { } } );
+ * newEDTUtil.invoke(true, null);
* </pre>
* </p>
*/
diff --git a/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java b/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java
index 42e1c9be5..2203d744a 100644
--- a/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java
+++ b/src/newt/classes/com/jogamp/newt/swt/SWTEDTUtil.java
@@ -27,8 +27,6 @@
*/
package com.jogamp.newt.swt;
-import java.awt.EventQueue;
-
import javax.media.nativewindow.NativeWindowException;
import jogamp.newt.Debug;
@@ -83,7 +81,7 @@ public class SWTEDTUtil implements EDTUtil {
synchronized(edtLock) {
waitUntilStopped();
if(DEBUG) {
- System.err.println(Thread.currentThread()+": EDT reset - edt: "+nedt);
+ System.err.println(Thread.currentThread()+": SWT-EDT reset - edt: "+nedt);
}
this.nedt = new NewtEventDispatchThread(threadGroup, name);
this.nedt.setDaemon(true); // don't stop JVM from shutdown ..
@@ -92,13 +90,13 @@ public class SWTEDTUtil implements EDTUtil {
private final void startImpl() {
if(nedt.isAlive()) {
- throw new RuntimeException("EDT Thread.isAlive(): true, isRunning: "+nedt.isRunning()+", edt: "+nedt);
+ throw new RuntimeException("SWT-EDT Thread.isAlive(): true, isRunning: "+nedt.isRunning()+", edt: "+nedt);
}
start_iter++;
nedt.setName(name+start_iter);
nedt.shouldStop = false;
if(DEBUG) {
- System.err.println(Thread.currentThread()+": EDT START - edt: "+nedt);
+ System.err.println(Thread.currentThread()+": SWT-EDT START - edt: "+nedt);
// Thread.dumpStack();
}
nedt.start();
@@ -136,9 +134,6 @@ public class SWTEDTUtil implements EDTUtil {
}
private void invokeImpl(boolean wait, Runnable task, boolean stop) {
- if(task == null) {
- throw new RuntimeException("Null Runnable");
- }
Throwable throwable = null;
RunnableTask rTask = null;
Object rTaskLock = new Object();
@@ -147,7 +142,7 @@ public class SWTEDTUtil implements EDTUtil {
if( nedt.shouldStop ) {
// drop task ..
if(DEBUG) {
- System.err.println("Warning: EDT about (1) to stop, won't enqueue new task: "+nedt);
+ System.err.println(Thread.currentThread()+": Warning: SWT-EDT about (1) to stop, won't enqueue new task: "+nedt);
Thread.dumpStack();
}
return;
@@ -157,20 +152,21 @@ public class SWTEDTUtil implements EDTUtil {
if(stop) {
nedt.shouldStop = true;
if(DEBUG) {
- System.err.println(Thread.currentThread()+": EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - "+nedt);
+ System.err.println(Thread.currentThread()+": SWT-EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - "+nedt);
// Thread.dumpStack();
}
+ } else if( !nedt.isRunning() ) {
+ // start if should not stop && not started yet
+ startImpl();
}
- if( isCurrentThreadEDT() ) {
+ if( null == task ) {
+ wait = false;
+ } else if( isCurrentThreadEDT() ) {
task.run();
wait = false; // running in same thread (EDT) -> no wait
} else if( swtDisplay.isDisposed() ) {
wait = false; // drop task, SWT disposed
} else {
- // start if should not stop && not started yet
- if( !stop && !nedt.isRunning() ) {
- startImpl();
- }
rTask = new RunnableTask(task,
wait ? rTaskLock : null,
true /* always catch and report Exceptions, don't disturb EDT */);
@@ -255,7 +251,7 @@ public class SWTEDTUtil implements EDTUtil {
@Override
final public void run() {
if(DEBUG) {
- System.err.println(getName()+": EDT run() START "+ getName());
+ System.err.println(getName()+": SWT-EDT run() START "+ getName());
}
RuntimeException error = null;
try {
@@ -289,11 +285,11 @@ public class SWTEDTUtil implements EDTUtil {
if(t instanceof RuntimeException) {
error = (RuntimeException) t;
} else {
- error = new RuntimeException("Within EDT", t);
+ error = new RuntimeException("Within SWT-EDT", t);
}
} finally {
if(DEBUG) {
- System.err.println(getName()+": EDT run() END "+ getName()+", "+error);
+ System.err.println(getName()+": SWT-EDT run() END "+ getName()+", "+error);
}
synchronized(edtLock) {
isRunning = !shouldStop;
@@ -302,7 +298,7 @@ public class SWTEDTUtil implements EDTUtil {
}
}
if(DEBUG) {
- System.err.println(getName()+": EDT run() EXIT "+ getName()+", exception: "+error);
+ System.err.println(getName()+": SWT-EDT run() EXIT "+ getName()+", exception: "+error);
}
if(null!=error) {
throw error;
diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
index 7e19d9de5..293e13592 100644
--- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
+++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
@@ -125,7 +125,7 @@ public interface EDTUtil {
public void invokeStop(Runnable finalTask);
/**
- * Shall start the thread if not running.<br>
+ * Shall start the thread if not running, <code>task</code> maybe null for this purpose.<br>
* Append task to the EDT task queue.<br>
* Wait until execution is finished if <code>wait == true</code>.<br>
* Can be issued from within EDT, ie from within an enqueued task.<br>
diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
index 98987ef96..b141f9d29 100644
--- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
@@ -81,10 +81,10 @@ public class DefaultEDTUtil implements EDTUtil {
waitUntilStopped();
if(DEBUG) {
if(edt.tasks.size()>0) {
- System.err.println(Thread.currentThread()+": EDT reset, remaining tasks: "+edt.tasks.size()+" - "+edt);
+ System.err.println(Thread.currentThread()+": Default-EDT reset, remaining tasks: "+edt.tasks.size()+" - "+edt);
// Thread.dumpStack();
}
- System.err.println(Thread.currentThread()+": EDT reset - edt: "+edt);
+ System.err.println(Thread.currentThread()+": Default-EDT reset - edt: "+edt);
}
this.edt = new EventDispatchThread(threadGroup, name);
this.edt.setDaemon(true); // don't stop JVM from shutdown ..
@@ -93,13 +93,13 @@ public class DefaultEDTUtil implements EDTUtil {
private final void startImpl() {
if(edt.isAlive()) {
- throw new RuntimeException("EDT Thread.isAlive(): true, isRunning: "+edt.isRunning()+", edt: "+edt+", tasks: "+edt.tasks.size());
+ throw new RuntimeException("Default-EDT Thread.isAlive(): true, isRunning: "+edt.isRunning()+", edt: "+edt+", tasks: "+edt.tasks.size());
}
start_iter++;
edt.setName(name+start_iter);
edt.shouldStop = false;
if(DEBUG) {
- System.err.println(Thread.currentThread()+": EDT START - edt: "+edt);
+ System.err.println(Thread.currentThread()+": Default-EDT START - edt: "+edt);
// Thread.dumpStack();
}
edt.start();
@@ -136,9 +136,6 @@ public class DefaultEDTUtil implements EDTUtil {
}
private void invokeImpl(boolean wait, Runnable task, boolean stop) {
- if(task == null) {
- throw new RuntimeException("Null Runnable");
- }
Throwable throwable = null;
RunnableTask rTask = null;
Object rTaskLock = new Object();
@@ -147,7 +144,7 @@ public class DefaultEDTUtil implements EDTUtil {
if( edt.shouldStop ) {
// drop task ..
if(DEBUG) {
- System.err.println("Warning: EDT about (1) to stop, won't enqueue new task: "+edt);
+ System.err.println(Thread.currentThread()+": Warning: Default-EDT about (1) to stop, won't enqueue new task: "+edt);
Thread.dumpStack();
}
return;
@@ -157,24 +154,25 @@ public class DefaultEDTUtil implements EDTUtil {
if(stop) {
edt.shouldStop = true;
if(DEBUG) {
- System.err.println(Thread.currentThread()+": EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - tasks: "+edt.tasks.size()+" - "+edt);
+ System.err.println(Thread.currentThread()+": Default-EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - tasks: "+edt.tasks.size()+" - "+edt);
// Thread.dumpStack();
}
+ } else if( !edt.isRunning() ) {
+ // start if should not stop && not started yet
+ startImpl();
}
- if( isCurrentThreadEDT() ) {
+ if( null == task ) {
+ wait = false;
+ } else if( isCurrentThreadEDT() ) {
task.run();
wait = false; // running in same thread (EDT) -> no wait
if(stop && edt.tasks.size()>0) {
- System.err.println("Warning: EDT about (2) to stop, having remaining tasks: "+edt.tasks.size()+" - "+edt);
+ System.err.println(Thread.currentThread()+": Warning: Default-EDT about (2) to stop, having remaining tasks: "+edt.tasks.size()+" - "+edt);
if(DEBUG) {
Thread.dumpStack();
}
}
} else {
- // start if should not stop && not started yet
- if( !stop && !edt.isRunning() ) {
- startImpl();
- }
synchronized(edt.tasks) {
wait = wait && edt.isRunning();
rTask = new RunnableTask(task,
@@ -207,7 +205,7 @@ public class DefaultEDTUtil implements EDTUtil {
}
}
if(DEBUG && stop) {
- System.err.println(Thread.currentThread()+": EDT signal STOP X edt: "+edt);
+ System.err.println(Thread.currentThread()+": Default-EDT signal STOP X edt: "+edt);
}
}
@@ -282,7 +280,7 @@ public class DefaultEDTUtil implements EDTUtil {
@Override
final public void run() {
if(DEBUG) {
- System.err.println(getName()+": EDT run() START "+ getName());
+ System.err.println(getName()+": Default-EDT run() START "+ getName());
}
validateNoRecursiveLocksHold();
RuntimeException error = null;
@@ -324,12 +322,12 @@ public class DefaultEDTUtil implements EDTUtil {
if(t instanceof RuntimeException) {
error = (RuntimeException) t;
} else {
- error = new RuntimeException("Within EDT", t);
+ error = new RuntimeException("Within Default-EDT", t);
}
} finally {
if(DEBUG) {
RunnableTask rt = ( tasks.size() > 0 ) ? tasks.get(0) : null ;
- System.err.println(getName()+": EDT run() END "+ getName()+", tasks: "+tasks.size()+", "+rt+", "+error);
+ System.err.println(getName()+": Default-EDT run() END "+ getName()+", tasks: "+tasks.size()+", "+rt+", "+error);
}
synchronized(edtLock) {
if(null==error) {
@@ -344,9 +342,9 @@ public class DefaultEDTUtil implements EDTUtil {
}
if(DEBUG) {
if(null!=task && task.getAttachment()==null) {
- System.err.println(getName()+" Warning: EDT exit: Last task Not Final: "+tasks.size()+", "+task+" - "+edt);
+ System.err.println(getName()+" Warning: Default-EDT exit: Last task Not Final: "+tasks.size()+", "+task+" - "+edt);
} else if(tasks.size()>0) {
- System.err.println(getName()+" Warning: EDT exit: Remaining tasks Post Final: "+tasks.size());
+ System.err.println(getName()+" Warning: Default-EDT exit: Remaining tasks Post Final: "+tasks.size());
}
Thread.dumpStack();
}
@@ -358,7 +356,7 @@ public class DefaultEDTUtil implements EDTUtil {
}
}
if(DEBUG) {
- System.err.println(getName()+": EDT run() EXIT "+ getName()+", exception: "+error);
+ System.err.println(getName()+": Default-EDT run() EXIT "+ getName()+", exception: "+error);
}
if(null!=error) {
throw error;
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
index 2175f2190..cb9bc90b8 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
@@ -72,7 +72,7 @@ public class AWTEDTUtil implements EDTUtil {
synchronized(edtLock) {
waitUntilStopped();
if(DEBUG) {
- System.err.println(Thread.currentThread()+": EDT reset - edt: "+nedt);
+ System.err.println(Thread.currentThread()+": AWT-EDT reset - edt: "+nedt);
}
this.nedt = new NewtEventDispatchThread(threadGroup, name);
this.nedt.setDaemon(true); // don't stop JVM from shutdown ..
@@ -81,13 +81,13 @@ public class AWTEDTUtil implements EDTUtil {
private final void startImpl() {
if(nedt.isAlive()) {
- throw new RuntimeException("EDT Thread.isAlive(): true, isRunning: "+nedt.isRunning()+", edt: "+nedt);
+ throw new RuntimeException("AWT-EDT Thread.isAlive(): true, isRunning: "+nedt.isRunning()+", edt: "+nedt);
}
start_iter++;
nedt.setName(name+start_iter);
nedt.shouldStop = false;
if(DEBUG) {
- System.err.println(Thread.currentThread()+": EDT START - edt: "+nedt);
+ System.err.println(Thread.currentThread()+": AWT-EDT START - edt: "+nedt);
// Thread.dumpStack();
}
nedt.start();
@@ -124,9 +124,6 @@ public class AWTEDTUtil implements EDTUtil {
}
private void invokeImpl(boolean wait, Runnable task, boolean stop) {
- if(task == null) {
- throw new RuntimeException("Null Runnable");
- }
Throwable throwable = null;
RunnableTask rTask = null;
Object rTaskLock = new Object();
@@ -135,7 +132,7 @@ public class AWTEDTUtil implements EDTUtil {
if( nedt.shouldStop ) {
// drop task ..
if(DEBUG) {
- System.err.println("Warning: EDT about (1) to stop, won't enqueue new task: "+nedt);
+ System.err.println(Thread.currentThread()+": Warning: AWT-EDT about (1) to stop, won't enqueue new task: "+nedt);
Thread.dumpStack();
}
return;
@@ -145,18 +142,19 @@ public class AWTEDTUtil implements EDTUtil {
if(stop) {
nedt.shouldStop = true;
if(DEBUG) {
- System.err.println(Thread.currentThread()+": EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - "+nedt);
+ System.err.println(Thread.currentThread()+": AWT-EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - "+nedt);
// Thread.dumpStack();
}
+ } else if( !nedt.isRunning() ) {
+ // start if should not stop && not started yet
+ startImpl();
}
- if( isCurrentThreadEDT() ) {
+ if( null == task ) {
+ wait = false;
+ } else if( isCurrentThreadEDT() ) {
task.run();
wait = false; // running in same thread (EDT) -> no wait
} else {
- // start if should not stop && not started yet
- if( !stop && !nedt.isRunning() ) {
- startImpl();
- }
rTask = new RunnableTask(task,
wait ? rTaskLock : null,
true /* always catch and report Exceptions, don't disturb EDT */);
@@ -239,7 +237,7 @@ public class AWTEDTUtil implements EDTUtil {
@Override
final public void run() {
if(DEBUG) {
- System.err.println(getName()+": EDT run() START "+ getName());
+ System.err.println(getName()+": AWT-EDT run() START "+ getName());
}
RuntimeException error = null;
try {
@@ -269,11 +267,11 @@ public class AWTEDTUtil implements EDTUtil {
if(t instanceof RuntimeException) {
error = (RuntimeException) t;
} else {
- error = new RuntimeException("Within EDT", t);
+ error = new RuntimeException("Within AWT-EDT", t);
}
} finally {
if(DEBUG) {
- System.err.println(getName()+": EDT run() END "+ getName()+", "+error);
+ System.err.println(getName()+": AWT-EDT run() END "+ getName()+", "+error);
}
synchronized(edtLock) {
isRunning = !shouldStop;
@@ -282,7 +280,7 @@ public class AWTEDTUtil implements EDTUtil {
}
}
if(DEBUG) {
- System.err.println(getName()+": EDT run() EXIT "+ getName()+", exception: "+error);
+ System.err.println(getName()+": AWT-EDT run() EXIT "+ getName()+", exception: "+error);
}
if(null!=error) {
throw error;