summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/com/sun
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow/classes/com/sun')
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java21
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java38
2 files changed, 38 insertions, 21 deletions
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java
index ae606a790..20e8cf966 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java
@@ -43,21 +43,28 @@ import javax.media.nativewindow.*;
import java.awt.GraphicsEnvironment;
public class JAWTUtil {
- static {
- JAWTNativeLibLoader.loadAWTImpl();
- NativeLibLoaderBase.loadNativeWindow("awt");
- }
-
- // See whether we're running in headless mode
- private static boolean headlessMode;
static {
+ JAWTNativeLibLoader.loadAWTImpl();
+ NativeLibLoaderBase.loadNativeWindow("awt");
+
lockedStack = null;
headlessMode = GraphicsEnvironment.isHeadless();
}
+ // See whether we're running in headless mode
+ private static final boolean headlessMode;
+
private static Exception lockedStack;
+ // Just a hook to let this class being initialized,
+ // ie loading the native libraries ..
+ public static void init() { }
+
+ public static boolean isHeadlessMode() {
+ return headlessMode;
+ }
+
public static synchronized void lockToolkit() throws NativeWindowException {
if (null!=lockedStack) {
lockedStack.printStackTrace();
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java
index 731bd3caf..38d0fb73d 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java
@@ -73,18 +73,23 @@ public class X11Util {
private static ThreadLocal currentDisplayAssociation = new ThreadLocal();
- private static long staticDefaultDisplay=0;
+ private static volatile long staticDefaultDisplay=0;
private static boolean staticDefaultDisplayXineramaEnable=false;
private static long fetchStaticDefaultDisplay() {
if(0==staticDefaultDisplay) {
synchronized (X11Util.class) {
if(0==staticDefaultDisplay) {
- staticDefaultDisplay = X11Lib.XOpenDisplay(null);
- if(0==staticDefaultDisplay) {
- throw new NativeWindowException("Unable to create a static default display connection");
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
+ try {
+ staticDefaultDisplay = X11Lib.XOpenDisplay(null);
+ if(0==staticDefaultDisplay) {
+ throw new NativeWindowException("Unable to create a static default display connection");
+ }
+ staticDefaultDisplayXineramaEnable = X11Lib.XineramaEnabled(staticDefaultDisplay);
+ } finally {
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
}
- staticDefaultDisplayXineramaEnable = X11Lib.XineramaEnabled(staticDefaultDisplay);
}
}
}
@@ -109,15 +114,20 @@ public class X11Util {
public static long getThreadLocalDefaultDisplay() {
Long dpyL = (Long) currentDisplayAssociation.get();
if(null==dpyL) {
- long dpy = X11Lib.XOpenDisplay(null);
- if(0==dpy) {
- throw new NativeWindowException("Unable to create a default display connection on Thread "+Thread.currentThread().getName());
- }
- dpyL = new Long(dpy);
- currentDisplayAssociation.set( dpyL );
- if(DEBUG) {
- Exception e = new Exception("Created new TLS display connection 0x"+Long.toHexString(dpy)+" for thread "+Thread.currentThread().getName());
- e.printStackTrace();
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
+ try {
+ long dpy = X11Lib.XOpenDisplay(null);
+ if(0==dpy) {
+ throw new NativeWindowException("Unable to create a default display connection on Thread "+Thread.currentThread().getName());
+ }
+ dpyL = new Long(dpy);
+ currentDisplayAssociation.set( dpyL );
+ if(DEBUG) {
+ Exception e = new Exception("Created new TLS display connection 0x"+Long.toHexString(dpy)+" for thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ } finally {
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
}
}
return dpyL.longValue();