Author: nextgens
Date: 2008-06-19 09:09:02 +0000 (Thu, 19 Jun 2008)
New Revision: 20472
Modified:
trunk/freenet/src/freenet/support/LibraryLoader.java
trunk/freenet/src/freenet/support/io/NativeThread.java
Log:
Attempt to detect whether the native-library loading worked or not
Modified: trunk/freenet/src/freenet/support/LibraryLoader.java
===================================================================
--- trunk/freenet/src/freenet/support/LibraryLoader.java 2008-06-18
23:37:30 UTC (rev 20471)
+++ trunk/freenet/src/freenet/support/LibraryLoader.java 2008-06-19
09:09:02 UTC (rev 20472)
@@ -25,13 +25,16 @@
} else
if(System.getProperty("os.arch").toLowerCase().matches("(ppc)")) {
arch = "ppc";
} else {
+ // We want to try the i386 libraries if the
architecture is unknown
+ // Wrappers MUST fallback to "plain java"
implementation if loading native libraries fails
arch = "i386";
}
return arch;
}
- public static void loadNative(String path, String libraryName) {
+ public static boolean loadNative(String path, String libraryName) {
+ boolean success = false;
final boolean isWindows = File.pathSeparatorChar == ';';
final String prefix = (isWindows ? ".dll" :
((System.getProperty("os.name")).toLowerCase().startsWith("mac") ? ".jnilib" :
".so"));
final String libraryNameWithPrefix = (isWindows ? "" : "lib") +
libraryName;
@@ -43,6 +46,7 @@
if (nativeLib.exists()) {
System.out.println("Attempting to load the NativeThread
library ["+libraryName+']');
System.loadLibrary(libraryName);
+ success = true;
} else {
try {
// Get the resource
@@ -68,10 +72,13 @@
// Finally, load the dll
System.out.println("Attempting to load the
"+libraryName+" library ["+resource+']');
System.load(temporaryLib.getPath());
+ success = true;
} catch(Throwable e) {
System.err.println("Caught the following
exception attempting to load "+resourceName);
e.printStackTrace();
}
}
+
+ return success;
}
}
Modified: trunk/freenet/src/freenet/support/io/NativeThread.java
===================================================================
--- trunk/freenet/src/freenet/support/io/NativeThread.java 2008-06-18
23:37:30 UTC (rev 20471)
+++ trunk/freenet/src/freenet/support/io/NativeThread.java 2008-06-19
09:09:02 UTC (rev 20472)
@@ -41,9 +41,7 @@
// Loading the NativeThread library isn't useful on macos
_loadNative =
("Linux".equalsIgnoreCase(System.getProperty("os.name"))) &&
(NodeStarter.extBuildNumber > 18);
Logger.debug(NativeThread.class, "Run init(): should
loadNative="+_loadNative);
- if(_loadNative) {
- //System.loadLibrary("NativeThread");
- LibraryLoader.loadNative("/freenet/support/io/",
"NativeThread");
+ if(_loadNative &&
LibraryLoader.loadNative("/freenet/support/io/", "NativeThread")) {
NATIVE_PRIORITY_BASE = getLinuxPriority();
NATIVE_PRIORITY_RANGE = 20 - NATIVE_PRIORITY_BASE;
System.out.println("Using the NativeThread
implementation (base nice level is "+NATIVE_PRIORITY_BASE+')');
@@ -118,7 +116,7 @@
/* The user has reniced freenet or we didn't use the
PacketSender to create the thread
* either ways it's bad for us.
*
- * Let's diable the renicing as we can't rely on it
anymore.
+ * Let's disable the renicing as we can't rely on it
anymore.
*/
_disabled = true;
Logger.error(this, "Freenet has detected it has been
reniced : THAT'S BAD, DON'T DO IT! Nice level detected statically:
"+NATIVE_PRIORITY_BASE+" actual nice level: "+realPrio+" on "+this);