aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-10-24 20:53:19 +0200
committerSven Gothel <[email protected]>2013-10-24 20:53:19 +0200
commit5f44808fb34aa48bca233281983019247ed86bb6 (patch)
tree77627676e4a65ede628b866bdcd18b93f9d27077 /src/java/com/jogamp/common/util
parentbb7c2da1ed6791bf50a32a880a939cdaecf82701 (diff)
TempJarCache: Make 'initialization' query/flag thread safe, i.e. synchronize if !isInit (dbl-check locking)
- isInit must be set to 'true' _after_ actual initialization, so caller can be blocked until done - staticInitError must be volatile as well
Diffstat (limited to 'src/java/com/jogamp/common/util')
-rw-r--r--src/java/com/jogamp/common/util/cache/TempJarCache.java25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/java/com/jogamp/common/util/cache/TempJarCache.java b/src/java/com/jogamp/common/util/cache/TempJarCache.java
index 48d8081..c127314 100644
--- a/src/java/com/jogamp/common/util/cache/TempJarCache.java
+++ b/src/java/com/jogamp/common/util/cache/TempJarCache.java
@@ -74,7 +74,7 @@ public class TempJarCache {
private static TempFileCache tmpFileCache;
- private static boolean staticInitError = false;
+ private static volatile boolean staticInitError = false;
private static volatile boolean isInit = false;
/**
@@ -86,7 +86,6 @@ public class TempJarCache {
if (!isInit) { // volatile: ok
synchronized (TempJarCache.class) {
if (!isInit) {
- isInit = true;
staticInitError = !TempFileCache.initSingleton();
if(!staticInitError) {
@@ -104,6 +103,7 @@ public class TempJarCache {
if(DEBUG) {
System.err.println("TempJarCache.initSingleton(): ok "+(false==staticInitError)+", "+ tmpFileCache.getTempDir());
}
+ isInit = true;
}
}
}
@@ -150,17 +150,31 @@ public class TempJarCache {
}
} */
+ private static boolean isInitializedImpl() {
+ if (!isInit) { // volatile: ok
+ synchronized (TempJarCache.class) {
+ if (!isInit) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
/**
* @return true if this class has been properly initialized, ie. is in use, otherwise false.
*/
public static boolean isInitialized() {
- return isInit && !staticInitError;
+ return isInitializedImpl() && !staticInitError;
}
/* package */ static void checkInitialized() {
- if(!isInit) {
+ if(!isInitializedImpl()) {
throw new RuntimeException("initSingleton() has to be called first.");
}
+ if(staticInitError) {
+ throw new RuntimeException("initSingleton() failed.");
+ }
}
public static TempFileCache getTempFileCache() {
@@ -205,6 +219,7 @@ public class TempJarCache {
* @throws IllegalArgumentException
*/
public synchronized static final boolean addNativeLibs(Class<?> certClass, URI jarURI, String nativeLibraryPath) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException {
+ checkInitialized();
final LoadState nativeLibJarsLS = nativeLibJars.get(jarURI);
if( !testLoadState(nativeLibJarsLS, LoadState.LOOKED_UP) ) {
nativeLibJars.put(jarURI, LoadState.LOOKED_UP);
@@ -239,6 +254,7 @@ public class TempJarCache {
* @throws IllegalArgumentException
*/
public synchronized static final void addClasses(Class<?> certClass, URI jarURI) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException {
+ checkInitialized();
final LoadState classFileJarsLS = classFileJars.get(jarURI);
if( !testLoadState(classFileJarsLS, LoadState.LOOKED_UP) ) {
classFileJars.put(jarURI, LoadState.LOOKED_UP);
@@ -267,6 +283,7 @@ public class TempJarCache {
* @throws IllegalArgumentException
*/
public synchronized static final void addResources(Class<?> certClass, URI jarURI) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException {
+ checkInitialized();
final LoadState resourceFileJarsLS = resourceFileJars.get(jarURI);
if( !testLoadState(resourceFileJarsLS, LoadState.LOOKED_UP) ) {
resourceFileJars.put(jarURI, LoadState.LOOKED_UP);