From 1e42ccc8a1c063056e7b0b41990e66d1718221b7 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 17 Jun 2009 14:15:30 +0000 Subject: - Fix: Native X11 Display deadlock (Linux x86_64 32bit on 64bit) It turns out that under some circumstances, e.g. >3 threads within initialization time, the static X11Display usage result in a native deadlock within glXQueryServerString(). The call never returned. May be This happend even with NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); Removed X11Util.getStaticDefaultDisplay() This allows us to remove the ToolkitLock around these segments, due to a thread local X11Display utilization. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1977 232f8b59-042b-4e1e-8c03-345bb8c30851 --- .../com/sun/nativewindow/impl/x11/X11Util.java | 59 +++------------------- 1 file changed, 6 insertions(+), 53 deletions(-) (limited to 'src/nativewindow/classes/com/sun') 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 38d0fb73d..acd55a823 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java @@ -39,28 +39,11 @@ import javax.media.nativewindow.*; import com.sun.nativewindow.impl.*; /** - * Contains a thread safe X11 utility to retrieve tread local display connection,
+ * Contains a thread safe X11 utility to retrieve thread local display connection,
* as well as the static global discplay connection.
* - * The TLS variant is thread safe per se, but has the memory leak risk on applications - * heavily utilizing runnables on a new thread.
- * - * The static variant is more nice to resources, but involves the default toolkit - * locking mechanism, which invocation you have to provide as shown below.
- *
-   NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
-   try {
-     long displayHandle = X11Util.getStaticDefaultDisplay();
-     ...
-   } finally {
-     NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
-   }
- * 

- * - * We will use the TLS variant, where a long term display connection is being used, - * ie in JOGL's X11AWTGLXGraphicsConfigurationFactory, - * on all other situations where we just query some X11 attributes, - * the locked static variant shall be used instead.
+ * The TLS variant is thread safe per se, but be aware of the memory leak risk + * where an application heavily utilizing this class on temporary new threads.
*/ public class X11Util { private static final boolean DEBUG = Debug.debug("X11Util"); @@ -73,43 +56,13 @@ public class X11Util { private static ThreadLocal currentDisplayAssociation = new ThreadLocal(); - private static volatile long staticDefaultDisplay=0; - private static boolean staticDefaultDisplayXineramaEnable=false; - - private static long fetchStaticDefaultDisplay() { - if(0==staticDefaultDisplay) { - synchronized (X11Util.class) { - if(0==staticDefaultDisplay) { - 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(); - } - } - } - } - return staticDefaultDisplay; - } - - /** Returns the global static default display connection, read the toolkit lock/unlock - * requirements {@link X11Util above} for synchronization. */ - public static long getStaticDefaultDisplay() { - return fetchStaticDefaultDisplay(); - } - /** Returns the global static default display connection, read the toolkit lock/unlock * requirements {@link X11Util above} for synchronization. */ - public static boolean isXineramaEnabledOnStaticDefaultDisplay() { - fetchStaticDefaultDisplay(); - return staticDefaultDisplayXineramaEnable; + public static boolean isXineramaEnabledOnThreadLocalDefaultDisplay() { + long dpy = getThreadLocalDefaultDisplay(); + return X11Lib.XineramaEnabled(dpy); } - /** Returns this thread current default display. */ public static long getThreadLocalDefaultDisplay() { Long dpyL = (Long) currentDisplayAssociation.get(); -- cgit v1.2.3