diff options
author | Sven Gothel <[email protected]> | 2011-12-01 16:51:00 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-12-01 16:51:00 +0100 |
commit | 1113d44644469eaae69fd11fe7108ab432e4cf38 (patch) | |
tree | 424f14be20828f71b14ca218b56c707350ac3e7c /src/jogl/classes/javax | |
parent | 53ba4a2b3639a3746218693ea588159e5c6d07c7 (diff) |
GLProfile: use dbl checked locking w/ volatile ; Proper shutdown sequence.
Diffstat (limited to 'src/jogl/classes/javax')
-rw-r--r-- | src/jogl/classes/javax/media/opengl/GLProfile.java | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index f9e47f2db..6591f4ae1 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -109,24 +109,30 @@ public class GLProfile { * @param firstUIActionOnProcess Should be <code>true</code> if called before the first UI action of the running program, * otherwise <code>false</code>. */ - public static synchronized void initSingleton(final boolean firstUIActionOnProcess) { - if(!initialized) { - initialized = true; - // run the whole static initialization privileged to speed up, - // since this skips checking further access - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - if(TempJarCache.isInitialized()) { - String[] atomicNativeJarBaseNames = new String[] { "nativewindow", "jogl", null }; - if( ReflectionUtil.isClassAvailable("com.jogamp.newt.NewtFactory", GLProfile.class.getClassLoader()) ) { - atomicNativeJarBaseNames[2] = "newt"; - } - JNILibLoaderBase.addNativeJarLibs(GLProfile.class, "jogl.all", "jogl-all", atomicNativeJarBaseNames); - } - initProfilesForDefaultDevices(firstUIActionOnProcess); - return null; + public static void initSingleton(final boolean firstUIActionOnProcess) { + if(!initialized) { // volatile: ok + synchronized(GLProfile.class) { + if(!initialized) { + initialized = true; + Platform.initSingleton(); + + // run the whole static initialization privileged to speed up, + // since this skips checking further access + AccessController.doPrivileged(new PrivilegedAction<Object>() { + public Object run() { + if(TempJarCache.isInitialized()) { + String[] atomicNativeJarBaseNames = new String[] { "nativewindow", "jogl", null }; + if( ReflectionUtil.isClassAvailable("com.jogamp.newt.NewtFactory", GLProfile.class.getClassLoader()) ) { + atomicNativeJarBaseNames[2] = "newt"; + } + JNILibLoaderBase.addNativeJarLibs(GLProfile.class, "jogl-all", atomicNativeJarBaseNames); + } + initProfilesForDefaultDevices(firstUIActionOnProcess); + return null; + } + }); } - }); + } } } @@ -147,12 +153,16 @@ public class GLProfile { * The shutdown implementation is called via the JVM shutdown hook, if not manually invoked here.<br> * Invoke <code>shutdown()</code> manually is recommended, due to the unreliable JVM state within the shutdown hook.<br> */ - public static synchronized void shutdown() { - if(initialized) { - initialized = false; - NativeWindowFactory.shutdown(); - GLDrawableFactory.shutdown(); - GLContext.shutdown(); + public static void shutdown() { + if(initialized) { // volatile: ok + synchronized(GLProfile.class) { + if(initialized) { + initialized = false; + GLDrawableFactory.shutdown(); // may utilize static GLContext mappings + GLContext.shutdown(); // does not utilize shared resources of GLDrawableFactory + NativeWindowFactory.shutdown(); + } + } } } @@ -1157,7 +1167,7 @@ public class GLProfile { private static /*final*/ AbstractGraphicsDevice defaultDesktopDevice; private static /*final*/ AbstractGraphicsDevice defaultEGLDevice; - static boolean initialized = false; + private static volatile boolean initialized = false; /** * Tries the profiles implementation and native libraries. @@ -1193,7 +1203,7 @@ public class GLProfile { // - Instantiate GLDrawableFactory incl its shared dummy drawable/context, // which will register at GLContext .. // - GLDrawableFactory.initialize(); + GLDrawableFactory.initSingleton(); Throwable t=null; // if successfull it has a shared dummy drawable and context created @@ -1451,7 +1461,7 @@ public class GLProfile { } private static void validateInitialization() { - if(!initialized) { + if(!initialized) { // volatile: ok synchronized(GLProfile.class) { if(!initialized) { initSingleton(false); |