summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/com/sun
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2009-06-17 14:15:30 +0000
committerSven Gothel <[email protected]>2009-06-17 14:15:30 +0000
commit1e42ccc8a1c063056e7b0b41990e66d1718221b7 (patch)
tree8e23be5c70181ca460e7a408a834fdd55dd5fe8c /src/nativewindow/classes/com/sun
parenta92906bcb4ce4746f291d40a736949ec8476de61 (diff)
- 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
Diffstat (limited to 'src/nativewindow/classes/com/sun')
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java59
1 files changed, 6 insertions, 53 deletions
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,<br>
+ * Contains a thread safe X11 utility to retrieve thread local display connection,<br>
* as well as the static global discplay connection.<br>
*
- * The TLS variant is thread safe per se, but has the memory leak risk on applications
- * heavily utilizing runnables on a new thread.<br>
- *
- * The static variant is more nice to resources, but involves the default toolkit
- * locking mechanism, which invocation you have to provide as shown below.<br>
- * <PRE>
- NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
- try {
- long displayHandle = X11Util.getStaticDefaultDisplay();
- ...
- } finally {
- NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
- }
- * </PRE><br>
- *
- * We will use the TLS variant, where a long term display connection is being used,
- * ie in JOGL's <code>X11AWTGLXGraphicsConfigurationFactory</code>,
- * on all other situations where we just query some X11 attributes,
- * the locked static variant shall be used instead.<br>
+ * 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.<br>
*/
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();