summaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-07-05 22:48:12 +0200
committerSven Gothel <[email protected]>2013-07-05 22:48:12 +0200
commit433e3914324b90c910b018bb7d9d80e814c67123 (patch)
tree5b7e026db862f755a6cf2a67a3ae7abe702256a2 /src/newt
parentdec4b02fe4b93028c85de6a56b6af79601042d6e (diff)
Fix SWTEDTUtil regression caused by dec4b02fe4b93028c85de6a56b6af79601042d6e, ensuring EDT is running for reused Display instances.
Refine EDTUtil semantics of: - reset() - waitUntilStopped() AWTEDTUtil/SWTEDTUtil: Properly signal !running when shutdown SWTEDTUtil: Take SWT isDisposed() into account.
Diffstat (limited to 'src/newt')
-rw-r--r--src/newt/classes/com/jogamp/newt/util/EDTUtil.java15
-rw-r--r--src/newt/classes/jogamp/newt/DefaultEDTUtil.java11
-rw-r--r--src/newt/classes/jogamp/newt/DisplayImpl.java2
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java25
-rw-r--r--src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java53
5 files changed, 67 insertions, 39 deletions
diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
index 0df815609..75848785c 100644
--- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
+++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
@@ -65,14 +65,18 @@ public interface EDTUtil {
public void setPollPeriod(long ms);
/**
- * Create a new EDT. One should invoke <code>reset()</code><br>
- * after <code>invokeStop(..)</code> in case another start via <code>invoke(..)</code>
- * is expected.
+ * Resets the stopped EDT, i.e. prepares it for a restart via
+ * the next <code>invoke(..)</code> call.
+ * <p>
+ * One must stop the EDT first via {@link #invokeStop(boolean, Runnable)}
+ * and wait until it's stopped via {@link #waitUntilStopped()}.
+ * </p>
*
* @see #invoke(boolean, java.lang.Runnable)
* @see #invokeStop(boolean, java.lang.Runnable)
+ * @throws IllegalStateException if stop has not been issued, or EDT is still running (caller thread not being EDT or NEDT).
*/
- public void reset();
+ public void reset() throws IllegalStateException;
/**
* Returns true if the current thread is the event dispatch thread (EDT).
@@ -150,6 +154,9 @@ public interface EDTUtil {
/**
* Wait until EDT task is stopped.<br>
* No <code>stop</code> action is performed, {@link #invokeStop(boolean, java.lang.Runnable)} should be used before.
+ * <p>
+ * If caller thread is EDT or NEDT, this call will not block.
+ * </p>
*/
public void waitUntilStopped();
}
diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
index f8ee31a06..ecd94c278 100644
--- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
@@ -76,9 +76,14 @@ public class DefaultEDTUtil implements EDTUtil {
}
@Override
- public final void reset() {
- synchronized(edtLock) {
- waitUntilStopped();
+ public final void reset() throws IllegalStateException {
+ synchronized(edtLock) {
+ if( isRunning() ) {
+ if( !edt.shouldStop ) {
+ throw new IllegalStateException("EDT stop not issued.");
+ }
+ throw new IllegalStateException("EDT still running");
+ }
if(DEBUG) {
if(edt.tasks.size()>0) {
System.err.println(Thread.currentThread()+": Default-EDT reset, remaining tasks: "+edt.tasks.size()+" - "+edt);
diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java
index 09ea05e88..884ddac57 100644
--- a/src/newt/classes/jogamp/newt/DisplayImpl.java
+++ b/src/newt/classes/jogamp/newt/DisplayImpl.java
@@ -208,7 +208,7 @@ public abstract class DisplayImpl extends Display {
}
private void removeEDT(final Runnable task) {
- if(null!=edtUtil) {
+ if(null!=edtUtil) {
edtUtil.invokeStop(true, task);
// ready for restart ..
edtUtil.waitUntilStopped();
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
index 0cc5ddb3e..abd47d17e 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
@@ -68,9 +68,18 @@ public class AWTEDTUtil implements EDTUtil {
}
@Override
- final public void reset() {
- synchronized(edtLock) {
- waitUntilStopped();
+ public final void reset() throws IllegalStateException {
+ synchronized(edtLock) {
+ final Thread curT = Thread.currentThread();
+ final boolean onAWTEDT = EventQueue.isDispatchThread();
+ if( nedt.isRunning() ) {
+ if( !nedt.shouldStop ) {
+ throw new IllegalStateException("EDT stop not issued.");
+ }
+ if( nedt != curT && !onAWTEDT ) {
+ throw new IllegalStateException("EDT still running: Curr "+curT.getName()+", NEDT "+nedt.getName()+", on AWT-EDT "+onAWTEDT);
+ }
+ }
if(DEBUG) {
System.err.println(Thread.currentThread()+": AWT-EDT reset - edt: "+nedt);
}
@@ -110,7 +119,7 @@ public class AWTEDTUtil implements EDTUtil {
@Override
final public boolean isRunning() {
- return nedt.isRunning() ; // AWT is always running
+ return nedt.isRunning() ;
}
@Override
@@ -203,7 +212,7 @@ public class AWTEDTUtil implements EDTUtil {
@Override
final public void waitUntilStopped() {
synchronized(edtLock) {
- if(nedt.isRunning() && nedt != Thread.currentThread() && !EventQueue.isDispatchThread()) {
+ if( nedt.isRunning() && nedt != Thread.currentThread() && !EventQueue.isDispatchThread() ) {
while(nedt.isRunning()) {
try {
edtLock.wait();
@@ -278,10 +287,8 @@ public class AWTEDTUtil implements EDTUtil {
System.err.println(getName()+": AWT-EDT run() END "+ getName()+", "+error);
}
synchronized(edtLock) {
- isRunning = !shouldStop;
- if(!isRunning) {
- edtLock.notifyAll();
- }
+ isRunning = false;
+ edtLock.notifyAll();
}
if(DEBUG) {
System.err.println(getName()+": AWT-EDT run() EXIT "+ getName()+", exception: "+error);
diff --git a/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java b/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java
index 77049a010..a8e03c510 100644
--- a/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java
@@ -77,9 +77,19 @@ public class SWTEDTUtil implements EDTUtil {
}
@Override
- public void reset() {
- synchronized(edtLock) {
- waitUntilStopped();
+ public final void reset() throws IllegalStateException {
+ synchronized(edtLock) {
+ final Thread curT = Thread.currentThread();
+ final Thread swtT = !swtDisplay.isDisposed() ? swtDisplay.getThread() : null;
+ final boolean onSWTEDT = swtT == curT;
+ if( nedt.isRunning() ) {
+ if( !nedt.shouldStop ) {
+ throw new IllegalStateException("EDT stop not issued.");
+ }
+ if( nedt != curT && !onSWTEDT ) {
+ throw new IllegalStateException("EDT still running: Curr "+curT.getName()+", NEDT "+nedt.getName()+", SWT-EDT "+swtT.getName());
+ }
+ }
if(DEBUG) {
System.err.println(Thread.currentThread()+": SWT-EDT reset - edt: "+nedt);
}
@@ -104,7 +114,7 @@ public class SWTEDTUtil implements EDTUtil {
@Override
public boolean isCurrentThreadEDT() {
- return swtDisplay.getThread() == Thread.currentThread();
+ return !swtDisplay.isDisposed() && swtDisplay.getThread() == Thread.currentThread();
}
@Override
@@ -115,12 +125,12 @@ public class SWTEDTUtil implements EDTUtil {
@Override
public final boolean isCurrentThreadEDTorNEDT() {
final Thread ct = Thread.currentThread();
- return ct == swtDisplay.getThread() || ct == nedt ;
+ return ( !swtDisplay.isDisposed() && ct == swtDisplay.getThread() ) || ct == nedt ;
}
@Override
public boolean isRunning() {
- return nedt.isRunning() ; // SWT is always running
+ return nedt.isRunning() ;
}
@Override
@@ -142,33 +152,32 @@ public class SWTEDTUtil implements EDTUtil {
if( nedt.shouldStop ) {
// drop task ..
if(DEBUG) {
- System.err.println(Thread.currentThread()+": Warning: SWT-EDT about (1) to stop, won't enqueue new task: "+nedt);
- Thread.dumpStack();
+ System.err.println(Thread.currentThread()+": Warning: SWT-EDT about (1) to stop, won't enqueue new task: "+nedt+", isRunning "+nedt.isRunning());
+ // Thread.dumpStack();
}
return;
}
// System.err.println(Thread.currentThread()+" XXX stop: "+stop+", tasks: "+edt.tasks.size()+", task: "+task);
// Thread.dumpStack();
if(stop) {
+ if(DEBUG) {
+ System.err.println(Thread.currentThread()+": SWT-EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - "+nedt+", isRunning "+nedt.isRunning());
+ }
synchronized(nedt.sync) {
nedt.shouldStop = true;
nedt.sync.notifyAll(); // stop immediate if waiting (poll freq)
}
- if(DEBUG) {
- System.err.println(Thread.currentThread()+": SWT-EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - "+nedt);
- // Thread.dumpStack();
- }
- } else if( !nedt.isRunning() ) {
+ } else if( !nedt.isRunning() && !swtDisplay.isDisposed() ) {
// start if should not stop && not started yet
startImpl();
}
if( null == task ) {
wait = false;
+ } else if( swtDisplay.isDisposed() ) {
+ wait = false; // drop task, SWT disposed
} 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 {
rTask = new RunnableTask(task,
wait ? rTaskLock : null,
@@ -203,7 +212,7 @@ public class SWTEDTUtil implements EDTUtil {
_nedt = nedt;
}
final Thread ct = Thread.currentThread();
- if(!_nedt.isRunning() || _nedt == ct || swtDisplay.getThread() == ct) {
+ if( !_nedt.isRunning() || _nedt == ct || swtDisplay.isDisposed() || swtDisplay.getThread() == ct ) {
return;
}
try {
@@ -216,8 +225,10 @@ public class SWTEDTUtil implements EDTUtil {
@Override
final public void waitUntilStopped() {
synchronized(edtLock) {
- final Thread ct = Thread.currentThread();
- if(nedt.isRunning() && nedt != ct && swtDisplay.getThread() != ct) {
+ final Thread curT = Thread.currentThread();
+ final Thread swtT = !swtDisplay.isDisposed() ? swtDisplay.getThread() : null;
+ final boolean onSWTEDT = swtT == curT;
+ if( nedt.isRunning() && nedt != curT && !onSWTEDT ) {
while(nedt.isRunning()) {
try {
edtLock.wait();
@@ -296,10 +307,8 @@ public class SWTEDTUtil implements EDTUtil {
System.err.println(getName()+": SWT-EDT run() END "+ getName()+", "+error);
}
synchronized(edtLock) {
- isRunning = !shouldStop;
- if(!isRunning) {
- edtLock.notifyAll();
- }
+ isRunning = false;
+ edtLock.notifyAll();
}
if(DEBUG) {
System.err.println(getName()+": SWT-EDT run() EXIT "+ getName()+", exception: "+error);