From 453ccee8e3ce90956756d1582852b13f45cd2f38 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Tue, 9 Jul 2013 15:04:50 +0200
Subject: NEWT EDTUtil: Exposed weakness of EDTUtil usage due to usage of
WeakReference, i.e. higher retention of Display instances.
- WeakReference Change 99479bf3197cde8e89c5b499d135417863d521c7
- Refines commits:
feb352145af1643a57eaae99c0342e6f5e0f2a2e
dec4b02fe4b93028c85de6a56b6af79601042d6e
433e3914324b90c910b018bb7d9d80e814c67123
Reviews EDTUtil API and usage:
- less confusing / more determined EDTUtil API
- EDTUtil's thread shall only be reset and started when required (-> lazy)
- EDTUtil's instance in Display shall be handled thread safe w/o extra blocking
- EDTUtil's implementations (Default, SWT and AWT) shall be aligned / similar as much as possible
Further note: SWT's EDTUtil (NewtCanvasSWT) shall not use a reused Display instance due to it's
custom SWTEDTUtil. We may need to disable the ref. cache if custom EDTUtil (setEDTUtil)
is intended (used).
---
src/newt/classes/com/jogamp/newt/Display.java | 17 ++++-----
.../classes/com/jogamp/newt/swt/NewtCanvasSWT.java | 4 +-
src/newt/classes/com/jogamp/newt/util/EDTUtil.java | 43 ++++++++++++----------
3 files changed, 35 insertions(+), 29 deletions(-)
(limited to 'src/newt/classes/com')
diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java
index 4f5df6c70..c618405c2 100644
--- a/src/newt/classes/com/jogamp/newt/Display.java
+++ b/src/newt/classes/com/jogamp/newt/Display.java
@@ -154,26 +154,25 @@ public abstract class Display {
/**
* Sets a new {@link EDTUtil} and returns the previous one.
*
- * If newEDTUtil
is null
,
+ * If usrEDTUtil
is null
,
* the device's default EDTUtil is created and used.
*
*
- * If a previous one exists and it differs from the new one,
- * it's being stopped, wait-until-idle and reset to allow a restart at a later time.
+ * If a previous one exists and it differs from usrEDTUtil
,
+ * it's being stopped, wait-until-idle.
*
*
- * If newEDTUtil
is not null and equals the previous one,
+ * If usrEDTUtil
is not null and equals the previous one,
* no change is being made.
*
- *
- * Note that newEDTUtil
will be started by this method,
- * if it is not running yet.
- *
*/
- public abstract EDTUtil setEDTUtil(EDTUtil newEDTUtil);
+ public abstract EDTUtil setEDTUtil(EDTUtil usrEDTUtil);
public abstract EDTUtil getEDTUtil();
+ /**
+ * @return true if EDT is running and not subject to be stopped, otherwise false.
+ */
public abstract boolean isEDTRunning();
public abstract void dispatchMessages();
diff --git a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
index dbe7c0d98..47dfca0f3 100644
--- a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
+++ b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
@@ -345,7 +345,9 @@ public class NewtCanvasSWT extends Canvas implements WindowClosingProtocol {
// set SWT EDT and start it
{
final Display newtDisplay = newtChild.getScreen().getDisplay();
- newtDisplay.setEDTUtil( new SWTEDTUtil(newtDisplay, getDisplay()) );
+ final EDTUtil edtUtil = new SWTEDTUtil(newtDisplay, getDisplay());
+ edtUtil.restart();
+ newtDisplay.setEDTUtil( edtUtil );
}
newtChild.setSize(w, h);
diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
index 75848785c..e86df2084 100644
--- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
+++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
@@ -65,18 +65,19 @@ public interface EDTUtil {
public void setPollPeriod(long ms);
/**
- * Resets the stopped EDT, i.e. prepares it for a restart via
- * the next invoke(..)
call.
+ * Starts or restarts the EDT.
*
- * One must stop the EDT first via {@link #invokeStop(boolean, Runnable)}
- * and wait until it's stopped via {@link #waitUntilStopped()}.
+ * If the EDT is running, it must be stopped first via {@link #invokeStop(boolean, Runnable)}
+ * and the caller should wait until it's stopped via {@link #waitUntilStopped()}.
*
- *
- * @see #invoke(boolean, java.lang.Runnable)
+ *
+ * @return true if EDT has been successfully restarted, otherwise false
+ * @throws IllegalStateException if EDT is running and not subject to be stopped, i.e. {@link #isRunning()} returns true
+ *
* @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).
+ * @see #waitUntilStopped()
*/
- public void reset() throws IllegalStateException;
+ public boolean restart() throws IllegalStateException;
/**
* Returns true if the current thread is the event dispatch thread (EDT).
@@ -111,7 +112,7 @@ public interface EDTUtil {
public boolean isCurrentThreadEDTorNEDT();
/**
- * @return True if EDT is running
+ * @return True if EDT is running and not subject to be stopped.
*/
public boolean isRunning();
@@ -129,27 +130,30 @@ public interface EDTUtil {
* All previous queued tasks will be finished.
* No new tasks are allowed, an Exception is thrown.
* Can be issued from within EDT, ie from within an enqueued task.
- * {@link #reset()} may follow immediately, ie creating a new EDT
+ * {@link #restart()} may follow immediately, ie creating a new EDT
*
*
+ * @return true if task
has been executed or queued for later execution, otherwise false
*/
- public void invokeStop(boolean wait, Runnable finalTask);
+ public boolean invokeStop(boolean wait, Runnable finalTask);
/**
- * Shall start the thread if not running, task
maybe null for this purpose.
- * Append task to the EDT task queue.
- * Wait until execution is finished if wait == true
.
+ * Appends task to the EDT task queue if current thread is not EDT,
+ * otherwise execute task immediately.
+ *
+ * Wait until execution is finished if wait == true
.
+ *
* Can be issued from within EDT, ie from within an enqueued task.
- *
- * @throws RuntimeException in case EDT is stopped and not {@link #reset()}
+ * @return true if task
has been executed or queued for later execution, otherwise false
*/
- public void invoke(boolean wait, Runnable task);
+ public boolean invoke(boolean wait, Runnable task);
/**
* Wait until the EDT task queue is empty.
* The last task may still be in execution when this method returns.
+ * @return true if waited for idle, otherwise false, i.e. in case of current thread is EDT or NEDT
*/
- public void waitUntilIdle();
+ public boolean waitUntilIdle();
/**
* Wait until EDT task is stopped.
@@ -157,7 +161,8 @@ public interface EDTUtil {
*
* If caller thread is EDT or NEDT, this call will not block.
*
+ * @return true if stopped, otherwise false, i.e. in case of current thread is EDT or NEDT
*/
- public void waitUntilStopped();
+ public boolean waitUntilStopped();
}
--
cgit v1.2.3