summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/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/nativewindow/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/nativewindow/classes/jogamp')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java46
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java8
2 files changed, 36 insertions, 18 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
index d5811d9c5..80dd5c402 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
@@ -60,13 +60,23 @@ public class JAWTUtil {
private static final Method isQueueFlusherThread;
private static final boolean j2dExist;
- private static Class sunToolkitClass;
- private static Method sunToolkitAWTLockMethod;
- private static Method sunToolkitAWTUnlockMethod;
- private static boolean hasSunToolkitAWTLock;
+ private static final Class sunToolkitClass;
+ private static final Method sunToolkitAWTLockMethod;
+ private static final Method sunToolkitAWTUnlockMethod;
+ private static final boolean hasSunToolkitAWTLock;
private static final JAWTToolkitLock jawtToolkitLock;
+ private static class PrivilegedDataBlob1 {
+ PrivilegedDataBlob1() {
+ ok = false;
+ }
+ Class sunToolkitClass;
+ Method sunToolkitAWTLockMethod;
+ Method sunToolkitAWTUnlockMethod;
+ boolean ok;
+ }
+
static {
JAWTJNILibLoader.loadAWTImpl();
JAWTJNILibLoader.loadNativeWindow("awt");
@@ -87,22 +97,28 @@ public class JAWTUtil {
isQueueFlusherThread = m;
j2dExist = ok;
- AccessController.doPrivileged(new PrivilegedAction() {
+ PrivilegedDataBlob1 pdb1 = (PrivilegedDataBlob1) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
- try {
- sunToolkitClass = Class.forName("sun.awt.SunToolkit");
- sunToolkitAWTLockMethod = sunToolkitClass.getDeclaredMethod("awtLock", new Class[]{});
- sunToolkitAWTLockMethod.setAccessible(true);
- sunToolkitAWTUnlockMethod = sunToolkitClass.getDeclaredMethod("awtUnlock", new Class[]{});
- sunToolkitAWTUnlockMethod.setAccessible(true);
+ PrivilegedDataBlob1 d = new PrivilegedDataBlob1();
+ try {
+ d.sunToolkitClass = Class.forName("sun.awt.SunToolkit");
+ d.sunToolkitAWTLockMethod = sunToolkitClass.getDeclaredMethod("awtLock", new Class[]{});
+ d.sunToolkitAWTLockMethod.setAccessible(true);
+ d.sunToolkitAWTUnlockMethod = sunToolkitClass.getDeclaredMethod("awtUnlock", new Class[]{});
+ d.sunToolkitAWTUnlockMethod.setAccessible(true);
+ d.ok=true;
} catch (Exception e) {
// Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5
}
- return null;
+ return d;
}
});
+ sunToolkitClass = pdb1.sunToolkitClass;
+ sunToolkitAWTLockMethod = pdb1.sunToolkitAWTLockMethod;
+ sunToolkitAWTUnlockMethod = pdb1.sunToolkitAWTUnlockMethod;
+
boolean _hasSunToolkitAWTLock = false;
- if (null != sunToolkitAWTLockMethod && null != sunToolkitAWTUnlockMethod) {
+ if ( pdb1.ok ) {
try {
sunToolkitAWTLockMethod.invoke(null, (Object[])null);
sunToolkitAWTUnlockMethod.invoke(null, (Object[])null);
@@ -152,11 +168,11 @@ public class JAWTUtil {
}
- public static final boolean hasJava2D() {
+ public static boolean hasJava2D() {
return j2dExist;
}
- public static final boolean isJava2DQueueFlusherThread() {
+ public static boolean isJava2DQueueFlusherThread() {
boolean b = false;
if(j2dExist) {
try {
diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
index 4098e101b..052a9934e 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
@@ -54,7 +54,7 @@ public class X11Util {
private static final boolean DEBUG = Debug.debug("X11Util");
private static final boolean TRACE_DISPLAY_LIFECYCLE = Debug.getBooleanProperty("nativewindow.debug.X11Util.TraceDisplayLifecycle", true, AccessController.getContext());
- private static String nullDisplayName = null;
+ private static volatile String nullDisplayName = null;
private static boolean isFirstX11ActionOnProcess = false;
private static boolean isInit = false;
@@ -117,7 +117,7 @@ public class X11Util {
}
public static String getNullDisplayName() {
- if(null==nullDisplayName) {
+ if(null==nullDisplayName) { // volatile: ok
synchronized(X11Util.class) {
if(null==nullDisplayName) {
NativeWindowFactory.getDefaultToolkitLock().lock();
@@ -174,17 +174,19 @@ public class X11Util {
public final Throwable getCreationStack() { return creationStack; }
+ @Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
+ @Override
public String toString() {
return "NamedX11Display["+name+", 0x"+Long.toHexString(handle)+", refCount "+refCount+", unCloseable "+unCloseable+"]";
}
}
/** Returns the number of unclosed X11 Displays.
- * @param realXCloseAndPendingDisplays if true, {@link #closePendingDisplayConnections()} is called.
+ * @param realXCloseOpenAndPendingDisplays if true, {@link #closePendingDisplayConnections()} is called.
*/
public static int shutdown(boolean realXCloseOpenAndPendingDisplays, boolean verbose) {
int num=0;