summaryrefslogtreecommitdiffstats
path: root/src/newt/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-02-26 21:43:20 +0100
committerSven Gothel <[email protected]>2011-02-26 21:43:20 +0100
commit76444dce2b678a7f6769564abac4f8a73f414609 (patch)
tree09358c0a48715c69e7e8f511cf3d9be729177509 /src/newt/classes/jogamp
parent77546f8968779fbdcfe58f89c6924803642889c7 (diff)
Clean/Fix: Threading Code
- Remove unsafe double checked locking - Annotate safe double checked locking (volatile) - use 'static final' if possible
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r--src/newt/classes/jogamp/newt/DefaultEDTUtil.java45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
index 016906581..3b14f30fc 100644
--- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
@@ -54,7 +54,7 @@ public class DefaultEDTUtil implements EDTUtil {
public DefaultEDTUtil(ThreadGroup tg, String name, Runnable dispatchMessages) {
this.threadGroup = tg;
- this.name=new String(Thread.currentThread().getName()+"-"+name+"-EDT-");
+ this.name=Thread.currentThread().getName()+"-"+name+"-EDT-";
this.dispatchMessages=dispatchMessages;
this.edt = new EventDispatchThread(threadGroup, name);
this.edt.setDaemon(true); // don't stop JVM from shutdown ..
@@ -113,7 +113,7 @@ public class DefaultEDTUtil implements EDTUtil {
invokeImpl(wait, task, false);
}
- private final void invokeImpl(boolean wait, Runnable task, boolean stop) {
+ private void invokeImpl(boolean wait, Runnable task, boolean stop) {
if(task == null) {
throw new RuntimeException("Null Runnable");
}
@@ -192,30 +192,33 @@ public class DefaultEDTUtil implements EDTUtil {
}
final public void waitUntilIdle() {
- if(edt.isRunning() && edt != Thread.currentThread()) {
- synchronized(edt.tasks) {
- while(edt.isRunning() && edt.tasks.size()>0) {
- try {
- edt.tasks.notifyAll();
- edt.tasks.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ final EventDispatchThread _edt;
+ synchronized(edtLock) {
+ _edt = edt;
+ }
+ if(!_edt.isRunning() || _edt == Thread.currentThread()) {
+ return;
+ }
+ synchronized(_edt.tasks) {
+ while(_edt.isRunning() && _edt.tasks.size()>0) {
+ try {
+ _edt.tasks.notifyAll();
+ _edt.tasks.wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
}
}
}
final public void waitUntilStopped() {
- if(edt.isRunning() && edt != Thread.currentThread() ) {
- synchronized(edtLock) {
- if(edt.isRunning() && edt != Thread.currentThread() ) {
- while(edt.isRunning()) {
- try {
- edtLock.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ synchronized(edtLock) {
+ if(edt.isRunning() && edt != Thread.currentThread() ) {
+ while(edt.isRunning()) {
+ try {
+ edtLock.wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
}
}
@@ -235,6 +238,7 @@ public class DefaultEDTUtil implements EDTUtil {
return isRunning;
}
+ @Override
final public void start() throws IllegalThreadStateException {
isRunning = true;
super.start();
@@ -244,6 +248,7 @@ public class DefaultEDTUtil implements EDTUtil {
* Utilizing locking only on tasks and its execution,
* not for event dispatching.
*/
+ @Override
final public void run() {
if(DEBUG) {
System.err.println(getName()+": EDT run() START "+ getName());