summaryrefslogtreecommitdiffstats
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
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
-rwxr-xr-xmake/scripts/runtest.sh6
-rw-r--r--src/java/com/jogamp/common/util/cache/TempJarCache.java25
2 files changed, 24 insertions, 7 deletions
diff --git a/make/scripts/runtest.sh b/make/scripts/runtest.sh
index 028eae2..61257d1 100755
--- a/make/scripts/runtest.sh
+++ b/make/scripts/runtest.sh
@@ -52,7 +52,7 @@ rm -f $LOG
#D_ARGS="-Djogamp.debug.Lock"
#D_ARGS="-Djogamp.debug.Lock -Djogamp.debug.Lock.TraceLock"
#D_ARGS="-Djogamp.debug.Lock.TraceLock"
-D_ARGS="-Djogamp.debug.IOUtil"
+#D_ARGS="-Djogamp.debug.IOUtil"
#D_ARGS="-Djogamp.debug=all"
function onetest() {
@@ -95,8 +95,8 @@ function onetest() {
#onetest com.jogamp.common.util.TestRunnableTask01 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestIOUtil01 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestIOUtilURICompose 2>&1 | tee -a $LOG
-onetest com.jogamp.common.util.TestIOUtilURIHandling 2>&1 | tee -a $LOG
-#onetest com.jogamp.common.util.TestTempJarCache 2>&1 | tee -a $LOG
+#onetest com.jogamp.common.util.TestIOUtilURIHandling 2>&1 | tee -a $LOG
+onetest com.jogamp.common.util.TestTempJarCache 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestJarUtil 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestValueConversion 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestSyncRingBuffer01 $*
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);