From 1c03dfd6d1939a46018583419956e350e531f4fe Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 26 Mar 2012 04:02:48 +0200 Subject: DynamicLibraryBundle*: Allow DynamicLibraryBundleInfo impl. to designate a thread to load native libraries. (Fix Bug 566) Due to requirements of native libraries using tls_model("global-dynamic") a thread can be designated to load the 'tool' native libraries. In case the tool lib uses tls_model("global-dynamic"), an implementation shall try to let the early most thread load it. For example, AWT-EDT shall load Mesa8 (Ubuntu-TLS) libGL.so.1 --- .../com/jogamp/common/os/DynamicLibraryBundle.java | 5 ++++- .../jogamp/common/os/DynamicLibraryBundleInfo.java | 5 ++++- .../com/jogamp/common/util/RunnableExecutor.java | 23 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/java/com/jogamp/common/util/RunnableExecutor.java (limited to 'src') diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java index e90209a..efb6d89 100755 --- a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java +++ b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java @@ -81,7 +81,10 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { nativeLibraries = new ArrayList(); toolLibNames = info.getToolLibNames(); glueLibNames = info.getGlueLibNames(); - loadLibraries(); + info.getLibLoaderExecutor().invoke(true, new Runnable() { + public void run() { + loadLibraries(); + } } ) ; toolGetProcAddressFuncNameList = info.getToolGetProcAddressFuncNameList(); if( null != toolGetProcAddressFuncNameList ) { toolGetProcAddressFuncNameSet = new HashSet(toolGetProcAddressFuncNameList); diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java b/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java index ca486bf..6178048 100644 --- a/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java +++ b/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java @@ -30,6 +30,8 @@ package com.jogamp.common.os; import java.util.*; +import com.jogamp.common.util.RunnableExecutor; + public interface DynamicLibraryBundleInfo { public static final boolean DEBUG = DynamicLibraryBundle.DEBUG; @@ -83,7 +85,8 @@ public interface DynamicLibraryBundleInfo { /** @return true if the dynamic symbol lookup shall happen system wide, over all loaded libraries. Otherwise only the loaded native libraries are used for lookup, which shall be the default. */ public boolean shallLookupGlobal(); - + + public RunnableExecutor getLibLoaderExecutor(); } diff --git a/src/java/com/jogamp/common/util/RunnableExecutor.java b/src/java/com/jogamp/common/util/RunnableExecutor.java new file mode 100644 index 0000000..6f18f54 --- /dev/null +++ b/src/java/com/jogamp/common/util/RunnableExecutor.java @@ -0,0 +1,23 @@ +package com.jogamp.common.util; + +public interface RunnableExecutor { + /** {@link RunnableExecutor} implementation simply invoking {@link Runnable#run()}, + * i.e. on the current thread at the time of calling {@link #invoke(boolean, Runnable)}. + */ + public static final RunnableExecutor currentThreadExecutor = new CurrentThreadExecutor(); + + /** + * @param wait if true method waits until {@link Runnable#run()} is completed, otherwise don't wait. + * @param r the {@link Runnable} to be executed. + */ + void invoke(boolean wait, Runnable r); + + static class CurrentThreadExecutor implements RunnableExecutor { + private CurrentThreadExecutor() {} + + @Override + public void invoke(boolean wait, Runnable r) { + r.run(); + } + } +} -- cgit v1.2.3