From 644eb1c3157ba3a18e4aec0f7bcb55081a9a3320 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 1 Dec 2011 16:19:59 +0100 Subject: DynamicLibraryBundle/NativeLibrary: Add destroy() to bundle, causing unloading of native library. --- .../com/jogamp/common/os/DynamicLibraryBundle.java | 23 ++++++++++++++++- src/java/com/jogamp/common/os/NativeLibrary.java | 30 ++++++++++++++-------- 2 files changed, 42 insertions(+), 11 deletions(-) (limited to 'src/java/com/jogamp/common') diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java index b7e0739..c8bf30a 100755 --- a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java +++ b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java @@ -71,6 +71,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { private HashSet toolGetProcAddressFuncNameSet; private List toolGetProcAddressFuncNameList; + /** Instantiates and loads all {@link NativeLibrary}s incl. JNI libraries. */ public DynamicLibraryBundle(DynamicLibraryBundleInfo info) { if(null==info) { throw new RuntimeException("Null DynamicLibraryBundleInfo"); @@ -102,6 +103,26 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { System.err.println(" All Complete: "+isLibComplete()); } } + + /** Unload all {@link NativeLibrary}s, and remove all references. */ + public void destroy() { + if(DEBUG) { + System.err.println(Thread.currentThread().getName()+" - DynamicLibraryBundle.destroy() START: "+info.getClass().getName()); + } + toolGetProcAddressFuncNameSet = null; + toolGetProcAddressHandle = 0; + for(int i = 0; i iter = possiblePaths.iterator(); iter.hasNext(); ) { String path = iter.next(); if (DEBUG) { - System.err.println("Trying to load " + path); + System.err.println("NativeLibrary.open(): Trying to load " + path); } Platform.initSingleton(); // loads native gluegen-rt library long res; @@ -182,15 +188,12 @@ public class NativeLibrary implements DynamicLookupHelper { res = dynLink.openLibraryLocal(path, DEBUG); } if (res != 0) { - if (DEBUG) { - System.err.println("Successfully loaded " + path + ": res = 0x" + Long.toHexString(res)); - } - return new NativeLibrary(res, path); + return new NativeLibrary(res, path, global); } } if (DEBUG) { - System.err.println("Did not succeed in loading (" + windowsLibName + ", " + unixLibName + ", " + macOSXLibName + ")"); + System.err.println("NativeLibrary.open(): Did not succeed in loading (" + windowsLibName + ", " + unixLibName + ", " + macOSXLibName + ")"); } // For now, just return null to indicate the open operation didn't @@ -226,11 +229,18 @@ public class NativeLibrary implements DynamicLookupHelper { /** Closes this native library. Further lookup operations are not allowed after calling this method. */ public void close() { - if (libraryHandle == 0) + if (DEBUG) { + System.err.println("NativeLibrary.close(): closing " + this); + } + if (libraryHandle == 0) { throw new RuntimeException("Library already closed"); + } long handle = libraryHandle; libraryHandle = 0; dynLink.closeLibrary(handle); + if (DEBUG) { + System.err.println("NativeLibrary.close(): Successfully closed " + this); + } } /** @@ -293,7 +303,7 @@ public class NativeLibrary implements DynamicLookupHelper { // from the LWJGL library String clPath = getPathFromClassLoader(libName, loader); if (DEBUG) { - System.err.println("Class loader path to " + libName + ": " + clPath); + System.err.println("NativeLibrary Class loader path to " + libName + ": " + clPath); } if (clPath != null) { paths.add(clPath); -- cgit v1.2.3