[asterisk-commits] russell: branch russell/chan_refcount r82479 - in /team/russell/chan_refcount...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 14 17:22:34 CDT 2007


Author: russell
Date: Fri Sep 14 17:22:33 2007
New Revision: 82479

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82479
Log:
Convert action_redirect.  This also resolves a potential deadlock because it
doesn't hold the first channel's lock while finding the 2nd one

Modified:
    team/russell/chan_refcount/include/asterisk/pbx.h
    team/russell/chan_refcount/main/manager.c

Modified: team/russell/chan_refcount/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/include/asterisk/pbx.h?view=diff&rev=82479&r1=82478&r2=82479
==============================================================================
--- team/russell/chan_refcount/include/asterisk/pbx.h (original)
+++ team/russell/chan_refcount/include/asterisk/pbx.h Fri Sep 14 17:22:33 2007
@@ -768,8 +768,14 @@
  */
 int ast_context_unlockmacro(const char *macrocontext);
 
+/*!
+ * \note The channel passed to this function does not need to be locked
+ */
 int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority);
 
+/*!
+ * \note The channel passed to this function does not need to be locked
+ */
 int ast_async_goto_by_name(const char *chan, const char *context, const char *exten, int priority);
 
 /*! Synchronously or asynchronously make an outbound call and send it to a

Modified: team/russell/chan_refcount/main/manager.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/main/manager.c?view=diff&rev=82479&r1=82478&r2=82479
==============================================================================
--- team/russell/chan_refcount/main/manager.c (original)
+++ team/russell/chan_refcount/main/manager.c Fri Sep 14 17:22:33 2007
@@ -1787,7 +1787,7 @@
 	const char *exten = astman_get_header(m, "Exten");
 	const char *context = astman_get_header(m, "Context");
 	const char *priority = astman_get_header(m, "Priority");
-	struct ast_channel *chan, *chan2 = NULL;
+	struct ast_channel *chan = NULL, *chan2 = NULL;
 	int pi = 0;
 	int res;
 
@@ -1795,15 +1795,15 @@
 		astman_send_error(s, m, "Channel not specified");
 		return 0;
 	}
+
 	if (!ast_strlen_zero(priority) && (sscanf(priority, "%d", &pi) != 1)) {
 		if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
 			astman_send_error(s, m, "Invalid priority\n");
 			return 0;
 		}
 	}
-	/* XXX watch out, possible deadlock - we are trying to get two channels!!! */
-	chan = ast_get_channel_by_name_locked(name);
-	if (!chan) {
+
+	if (!(chan = ast_channel_get_by_name(name))) {
 		char buf[BUFSIZ];
 		snprintf(buf, sizeof(buf), "Channel does not exist: %s", name);
 		astman_send_error(s, m, buf);
@@ -1811,17 +1811,17 @@
 	}
 	if (ast_check_hangup(chan)) {
 		astman_send_error(s, m, "Redirect failed, channel not up.\n");
-		ast_channel_unlock(chan);
-		return 0;
-	}
+		goto return_unref;
+	}
+
 	if (!ast_strlen_zero(name2))
-		chan2 = ast_get_channel_by_name_locked(name2);
+		chan2 = ast_channel_get_by_name(name2);
+
 	if (chan2 && ast_check_hangup(chan2)) {
 		astman_send_error(s, m, "Redirect failed, extra channel not up.\n");
-		ast_channel_unlock(chan);
-		ast_channel_unlock(chan2);
-		return 0;
-	}
+		goto return_unref;
+	}
+
 	res = ast_async_goto(chan, context, exten, pi);
 	if (!res) {
 		if (!ast_strlen_zero(name2)) {
@@ -1837,10 +1837,13 @@
 			astman_send_ack(s, m, "Redirect successful");
 	} else
 		astman_send_error(s, m, "Redirect failed");
+
+return_unref:
 	if (chan)
-		ast_channel_unlock(chan);
+		ast_channel_unref(chan);
 	if (chan2)
-		ast_channel_unlock(chan2);
+		ast_channel_unref(chan2);
+
 	return 0;
 }
 




More information about the asterisk-commits mailing list