[asterisk-commits] murf: branch murf/fast-ast2 r88583 - /team/murf/fast-ast2/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 5 10:54:53 CST 2007


Author: murf
Date: Mon Nov  5 10:54:52 2007
New Revision: 88583

URL: http://svn.digium.com/view/asterisk?view=rev&rev=88583
Log:
Fix up the local/extcontexts stuff in __ast_context_create so you look in the right places for context names; make sure ast_merge_contexts_and_delete() is doing the right thing.

Modified:
    team/murf/fast-ast2/main/pbx.c

Modified: team/murf/fast-ast2/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast2/main/pbx.c?view=diff&rev=88583&r1=88582&r2=88583
==============================================================================
--- team/murf/fast-ast2/main/pbx.c (original)
+++ team/murf/fast-ast2/main/pbx.c Mon Nov  5 10:54:52 2007
@@ -4609,33 +4609,31 @@
 										   hashtab_hash_contexts,
 										   1);
 	}
-	strncpy(search.name,name,sizeof(search.name));
-	tmp = ast_hashtab_lookup(contexts_tree, &search);
 	
-	if (!existsokay && tmp) {
-		ast_log(LOG_WARNING, "Tried to register context '%s', already in use\n", name);
-		return tmp;
-	}
-
 	if (!extcontexts) {
-		ast_wrlock_contexts();
+		ast_rdlock_contexts();
 		local_contexts = &contexts;
-	} else
+		strncpy(search.name,name,sizeof(search.name));
+		tmp = ast_hashtab_lookup(contexts_tree, &search);
+		if (!existsokay && tmp) {
+			ast_log(LOG_WARNING, "Tried to register context '%s', already in use\n", name);
+		}
+		ast_unlock_contexts();
+		if (tmp)
+			return tmp;
+	} else { /* local contexts just in a linked list; search there for the new context; slow, linear search, but not frequent */
 		local_contexts = extcontexts;
-
-#ifdef NO_MORE
-	for (tmp = *local_contexts; tmp; tmp = tmp->next) {
-		if (!strcasecmp(tmp->name, name)) {
-			if (!existsokay) {
-				ast_log(LOG_WARNING, "Tried to register context '%s', already in use\n", name);
-				tmp = NULL;
+		for (tmp = *local_contexts; tmp; tmp = tmp->next) {
+			if (!strcasecmp(tmp->name, name)) {
+				if (!existsokay) {
+					ast_log(LOG_WARNING, "Tried to register context '%s', already in use\n", name);
+					tmp = NULL;
+				}
+				return tmp;
 			}
-			if (!extcontexts)
-				ast_unlock_contexts();
-			return tmp;
-		}
-	}
-#endif
+		}
+	}
+	
 	if ((tmp = ast_calloc(1, length))) {
 		ast_rwlock_init(&tmp->lock);
 		ast_mutex_init(&tmp->macrolock);
@@ -4643,17 +4641,21 @@
 		tmp->root = NULL;
 		tmp->root_tree = NULL;
 		tmp->registrar = registrar;
-		tmp->next = *local_contexts;
 		tmp->includes = NULL;
 		tmp->ignorepats = NULL;
+	}
+	if (!extcontexts) {
+		ast_wrlock_contexts();
+		tmp->next = *local_contexts;
 		*local_contexts = tmp;
 		ast_hashtab_insert_safe(contexts_tree, tmp); /*put this context into the tree */
-		ast_debug(1, "Registered context '%s'\n", tmp->name);
-		ast_verb(3, "Registered extension context '%s'\n", tmp->name);
-	}
-
-	if (!extcontexts)
 		ast_unlock_contexts();
+	} else {
+		tmp->next = *local_contexts;
+		*local_contexts = tmp;
+	}
+	ast_debug(1, "Registered context '%s'\n", tmp->name);
+	ast_verb(3, "Registered extension context '%s'\n", tmp->name);
 	return tmp;
 }
 




More information about the asterisk-commits mailing list