[asterisk-commits] file: trunk r43954 - /trunk/main/pbx.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Sep 28 15:49:56 MST 2006


Author: file
Date: Thu Sep 28 17:49:55 2006
New Revision: 43954

URL: http://svn.digium.com/view/asterisk?rev=43954&view=rev
Log:
Cache the application pointer so we don't have to needlessly search for it over and over. This should yield a suitable performance increase.

Modified:
    trunk/main/pbx.c

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?rev=43954&r1=43953&r2=43954&view=diff
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Thu Sep 28 17:49:55 2006
@@ -104,6 +104,7 @@
 });
 
 struct ast_context;
+struct ast_app;
 
 /*!
    \brief ast_exten: An extension
@@ -119,6 +120,7 @@
 	const char *label;		/*!< Label */
 	struct ast_context *parent;	/*!< The context this extension belongs to  */
 	const char *app; 		/*!< Application to execute */
+	struct ast_app *cached_app;     /*!< Cached location of application */
 	void *data;			/*!< Data to use (arguments) */
 	void (*datad)(void *);		/*!< Data destructor */
 	struct ast_exten *peer;		/*!< Next higher priority with our extension */
@@ -1659,7 +1661,9 @@
 			ast_mutex_unlock(&conlock);
 			return res;	/* the priority we were looking for */
 		} else {	/* spawn */
-			app = pbx_findapp(e->app);
+			if (!e->cached_app)
+				e->cached_app = pbx_findapp(e->app);
+			app = e->cached_app;
 			ast_mutex_unlock(&conlock);
 			if (!app) {
 				ast_log(LOG_WARNING, "No application '%s' for extension (%s, %s, %d)\n", e->app, context, exten, priority);
@@ -3472,6 +3476,25 @@
 	show_dialplan_help, complete_show_dialplan_context },
 };
 
+static void unreference_cached_app(struct ast_app *app)
+{
+	struct ast_context *context = NULL;
+	struct ast_exten *eroot = NULL, *e = NULL;
+
+	ast_lock_contexts();
+	while ((context = ast_walk_contexts(context))) {
+		while ((eroot = ast_walk_context_extensions(context, eroot))) {
+			while ((e = ast_walk_extension_priorities(eroot, e))) {
+				if (e->cached_app == app)
+					e->cached_app = NULL;
+			}
+		}
+	}
+	ast_unlock_contexts();
+
+	return;
+}
+
 int ast_unregister_application(const char *app)
 {
 	struct ast_app *tmp;
@@ -3479,6 +3502,7 @@
 	AST_LIST_LOCK(&apps);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&apps, tmp, list) {
 		if (!strcasecmp(app, tmp->name)) {
+			unreference_cached_app(tmp);
 			AST_LIST_REMOVE_CURRENT(&apps, list);
 			if (option_verbose > 1)
 				ast_verbose( VERBOSE_PREFIX_2 "Unregistered application '%s'\n", tmp->name);



More information about the asterisk-commits mailing list