[svn-commits] kpfleming: trunk r40949 - in /trunk: ./ include/asterisk/ main/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Aug 23 12:28:14 MST 2006


Author: kpfleming
Date: Wed Aug 23 14:28:13 2006
New Revision: 40949

URL: http://svn.digium.com/view/asterisk?rev=40949&view=rev
Log:
use RTLD_NOLOAD if it's available to make loading dynamic modules a little faster and less resource-intensive
also, keep trying to dlclose() a module until it actually goes away, since it may have other modules it brought in when it was loaded (thanks PCadach for pointing this problem out to me)

Modified:
    trunk/configure
    trunk/configure.ac
    trunk/include/asterisk/autoconfig.h.in
    trunk/main/loader.c

Modified: trunk/configure
URL: http://svn.digium.com/view/asterisk/trunk/configure?rev=40949&r1=40948&r2=40949&view=diff
==============================================================================
--- trunk/configure (original)
+++ trunk/configure Wed Aug 23 14:28:13 2006
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 40790 .
+# From configure.ac Revision: 40837 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.60.
 #
@@ -13654,6 +13654,76 @@
 rm -f core conftest.err conftest.$ac_objext \
       conftest$ac_exeext conftest.$ac_ext
 
+{ echo "$as_me:$LINENO: checking checking for RTLD_NOLOAD" >&5
+echo $ECHO_N "checking checking for RTLD_NOLOAD... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <dlfcn.h>
+int
+main ()
+{
+int foo = RTLD_NOLOAD;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_RTLD_NOLOAD 1
+_ACEOF
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+
 
 { echo "$as_me:$LINENO: checking checking for compiler 'attribute pure' support" >&5
 echo $ECHO_N "checking checking for compiler 'attribute pure' support... $ECHO_C" >&6; }

Modified: trunk/configure.ac
URL: http://svn.digium.com/view/asterisk/trunk/configure.ac?rev=40949&r1=40948&r2=40949&view=diff
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Wed Aug 23 14:28:13 2006
@@ -237,6 +237,15 @@
 	AC_MSG_RESULT(no)
 )
 
+AC_MSG_CHECKING(checking for RTLD_NOLOAD)
+AC_LINK_IFELSE(
+	AC_LANG_PROGRAM([#include <dlfcn.h>],
+			[int foo = RTLD_NOLOAD;]),
+	AC_MSG_RESULT(yes)
+	AC_DEFINE([HAVE_RTLD_NOLOAD], 1, [Define to 1 if your system has a dynamic linker that supports RTLD_NOLOAD.]),
+	AC_MSG_RESULT(no)
+)
+
 AST_GCC_ATTRIBUTE(pure)
 AST_GCC_ATTRIBUTE(malloc)
 AST_GCC_ATTRIBUTE(const)

Modified: trunk/include/asterisk/autoconfig.h.in
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/autoconfig.h.in?rev=40949&r1=40948&r2=40949&view=diff
==============================================================================
--- trunk/include/asterisk/autoconfig.h.in (original)
+++ trunk/include/asterisk/autoconfig.h.in Wed Aug 23 14:28:13 2006
@@ -269,6 +269,10 @@
 
 /* Define to 1 if you have the `rint' function. */
 #undef HAVE_RINT
+
+/* Define to 1 if your system has a dynamic linker that supports RTLD_NOLOAD.
+   */
+#undef HAVE_RTLD_NOLOAD
 
 /* Define to 1 if you have the `select' function. */
 #undef HAVE_SELECT

Modified: trunk/main/loader.c
URL: http://svn.digium.com/view/asterisk/trunk/main/loader.c?rev=40949&r1=40948&r2=40949&view=diff
==============================================================================
--- trunk/main/loader.c (original)
+++ trunk/main/loader.c Wed Aug 23 14:28:13 2006
@@ -324,7 +324,7 @@
 static void unload_dynamic_module(struct ast_module *mod)
 {
 	if (mod->lib)
-		dlclose(mod->lib);
+		while (!dlclose(mod->lib));
 	/* WARNING: the structure pointed to by mod is now gone! */
 }
 
@@ -368,7 +368,7 @@
 	*/
 	if (resource_being_loaded != (mod = AST_LIST_LAST(&module_list))) {
 		/* no, it did not, so close it and return */
-		dlclose(lib);
+		while (!dlclose(lib));
 		/* note that the module's destructor will call ast_module_unregister(),
 		   which will free the structure we allocated in resource_being_loaded */
 		return NULL;
@@ -376,15 +376,27 @@
 
 	wants_global = ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS);
 
-	/* we are done with this first load, so clean up and start over */
-
-	dlclose(lib);
-	resource_being_loaded = NULL;
-
 	/* if we are being asked only to load modules that provide global symbols,
 	   and this one does not, then close it and return */
-	if (global_symbols_only && !wants_global)
+	if (global_symbols_only && !wants_global) {
+		while (!dlclose(lib));
 		return NULL;
+	}
+
+	/* if the system supports RTLD_NOLOAD, we can just 'promote' the flags
+	   on the already-opened library to what we want... if not, we have to
+	   close it and start over
+	*/
+#if HAVE_RTLD_NOLOAD
+	if (!dlopen(fn, RTLD_NOLOAD | (wants_global ? RTLD_GLOBAL : RTLD_NOW))) {
+		ast_log(LOG_WARNING, "%s\n", dlerror());
+		while (!dlclose(lib));
+		free(resource_being_loaded);
+		return NULL;
+	}
+#else
+	while (!dlclose(lib));
+	resource_being_loaded = NULL;
 
 	/* start the load process again */
 
@@ -402,6 +414,8 @@
 	/* since the module was successfully opened, and it registered itself
 	   the previous time we did that, we're going to assume it worked this
 	   time too :) */
+#endif
+
 	AST_LIST_LAST(&module_list)->lib = lib;
 	resource_being_loaded = NULL;
 



More information about the svn-commits mailing list