Author: mladen.turk(a)jboss.com
Date: 2007-10-12 07:35:20 -0400 (Fri, 12 Oct 2007)
New Revision: 1106
Modified:
trunk/sight/java/org/jboss/sight/Library.java
Log:
Make Library calls synchronized
Modified: trunk/sight/java/org/jboss/sight/Library.java
===================================================================
--- trunk/sight/java/org/jboss/sight/Library.java 2007-10-12 11:18:09 UTC (rev 1105)
+++ trunk/sight/java/org/jboss/sight/Library.java 2007-10-12 11:35:20 UTC (rev 1106)
@@ -35,7 +35,7 @@
/* Default library names */
private static String [] NAMES = {"sight-1", "libsight-1"};
-
+ private static Object lock = new Object();
/*
* A handle to the unique Library singleton instance.
*/
@@ -116,34 +116,36 @@
static public boolean initialize(String libraryName)
throws Exception
{
- if (_instance == null) {
- if (libraryName == null)
- _instance = new Library();
- else
- _instance = new Library(libraryName);
- SIGHT_MAJOR_VERSION = version(0x01);
- SIGHT_MINOR_VERSION = version(0x02);
- SIGHT_PATCH_VERSION = version(0x03);
- SIGHT_IS_DEV_VERSION = version(0x04);
- APR_MAJOR_VERSION = version(0x11);
- APR_MINOR_VERSION = version(0x12);
- APR_PATCH_VERSION = version(0x13);
- APR_IS_DEV_VERSION = version(0x14);
+ synchronized(lock) {
+ if (_instance == null) {
+ if (libraryName == null)
+ _instance = new Library();
+ else
+ _instance = new Library(libraryName);
+ SIGHT_MAJOR_VERSION = version(0x01);
+ SIGHT_MINOR_VERSION = version(0x02);
+ SIGHT_PATCH_VERSION = version(0x03);
+ SIGHT_IS_DEV_VERSION = version(0x04);
+ APR_MAJOR_VERSION = version(0x11);
+ APR_MINOR_VERSION = version(0x12);
+ APR_PATCH_VERSION = version(0x13);
+ APR_IS_DEV_VERSION = version(0x14);
- if (APR_MAJOR_VERSION < 1) {
- throw new UnsatisfiedLinkError("Unsupported APR Version (" +
- getAprVersionString() + ")");
+ if (APR_MAJOR_VERSION < 1) {
+ throw new UnsatisfiedLinkError("Unsupported APR Version ("
+
+ getAprVersionString() +
")");
+ }
+ if (initialize0()) {
+ /* Initialize Runtime objects */
+ File.initializeStdFiles();
+ Service.loadResources();
+ return true;
+ }
+ return false;
}
- if (initialize0()) {
- /* Initialize Runtime objects */
- File.initializeStdFiles();
- Service.loadResources();
+ else
return true;
- }
- return false;
}
- else
- return true;
}
/**
@@ -153,19 +155,19 @@
static public void shutdown()
throws Exception
{
- try {
- if (_instance != null) {
- synchronized(_instance) {
+ synchronized(lock) {
+ try {
+ if (_instance != null) {
terminate0();
}
+ else {
+ throw new UnsatisfiedLinkError("Library was not
initialized");
+ }
}
- else {
- throw new UnsatisfiedLinkError("Library was not initialized");
+ finally {
+ _instance = null;
}
}
- finally {
- _instance = null;
- }
}
/**
@@ -184,19 +186,19 @@
* Clear the global APR pool and
* close all the native objects.
*/
- static synchronized public void clear()
+ static public void clear()
throws Exception
{
- if (_instance != null) {
- synchronized(_instance) {
+ synchronized(lock) {
+ if (_instance != null) {
clear0();
/* Reinitialize Runtime objects */
File.initializeStdFiles();
}
+ else {
+ throw new UnsatisfiedLinkError("Library was not initialized");
+ }
}
- else {
- throw new UnsatisfiedLinkError("Library was not initialized");
- }
}
}
Show replies by date