[asterisk-commits] rmudgett: trunk r387261 - /trunk/channels/chan_local.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 1 16:55:55 CDT 2013


Author: rmudgett
Date: Wed May  1 16:55:53 2013
New Revision: 387261

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387261
Log:
Simplify chan_local.c:manager_optimize_away() using ao2_find().

Modified:
    trunk/channels/chan_local.c

Modified: trunk/channels/chan_local.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_local.c?view=diff&rev=387261&r1=387260&r2=387261
==============================================================================
--- trunk/channels/chan_local.c (original)
+++ trunk/channels/chan_local.c Wed May  1 16:55:53 2013
@@ -1354,10 +1354,9 @@
 static int manager_optimize_away(struct mansession *s, const struct message *m)
 {
 	const char *channel;
-	struct local_pvt *p, *tmp = NULL;
-	struct ast_channel *c;
-	int found = 0;
-	struct ao2_iterator it;
+	struct local_pvt *p;
+	struct local_pvt *found;
+	struct ast_channel *chan;
 
 	channel = astman_get_header(m, "Channel");
 	if (ast_strlen_zero(channel)) {
@@ -1365,31 +1364,21 @@
 		return 0;
 	}
 
-	c = ast_channel_get_by_name(channel);
-	if (!c) {
+	chan = ast_channel_get_by_name(channel);
+	if (!chan) {
 		astman_send_error(s, m, "Channel does not exist.");
 		return 0;
 	}
 
-	p = ast_channel_tech_pvt(c);
-	ast_channel_unref(c);
-	c = NULL;
-
-	it = ao2_iterator_init(locals, 0);
-	while ((tmp = ao2_iterator_next(&it))) {
-		if (tmp == p) {
-			ao2_lock(tmp);
-			found = 1;
-			ast_clear_flag(tmp, LOCAL_NO_OPTIMIZATION);
-			ao2_unlock(tmp);
-			ao2_ref(tmp, -1);
-			break;
-		}
-		ao2_ref(tmp, -1);
-	}
-	ao2_iterator_destroy(&it);
-
+	p = ast_channel_tech_pvt(chan);
+	ast_channel_unref(chan);
+
+	found = p ? ao2_find(locals, p, 0) : NULL;
 	if (found) {
+		ao2_lock(found);
+		ast_clear_flag(found, LOCAL_NO_OPTIMIZATION);
+		ao2_unlock(found);
+		ao2_ref(found, -1);
 		astman_send_ack(s, m, "Queued channel to be optimized away");
 	} else {
 		astman_send_error(s, m, "Unable to find channel");




More information about the asterisk-commits mailing list