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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 17 14:34:29 CST 2012


Author: rmudgett
Date: Mon Dec 17 14:34:25 2012
New Revision: 378072

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378072
Log:
chan_local: Misc lock and ref tweaks.

* awesome_locking() does not need to thrash the pvt lock as much.

* local_setoption() does not need to check for NULL pvt on cleanup since
it will never be NULL.

* Made ref the pvt before locking for consistency.

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=378072&r1=378071&r2=378072
==============================================================================
--- trunk/channels/chan_local.c (original)
+++ trunk/channels/chan_local.c Mon Dec 17 14:34:25 2012
@@ -161,7 +161,7 @@
 #define LOCAL_BRIDGE          (1 << 3) /*!< Report back the "true" channel as being bridged to */
 #define LOCAL_MOH_PASSTHRU    (1 << 4) /*!< Pass through music on hold start/stop frames */
 
-/* 
+/*!
  * \brief Send a pvt in with no locks held and get all locks
  *
  * \note NO locks should be held prior to calling this function
@@ -175,8 +175,8 @@
 	struct ast_channel *chan = NULL;
 	struct ast_channel *owner = NULL;
 
+	ao2_lock(p);
 	for (;;) {
-		ao2_lock(p);
 		if (p->chan) {
 			chan = p->chan;
 			ast_channel_ref(chan);
@@ -194,12 +194,11 @@
 			} else if(chan) {
 				ast_channel_lock(chan);
 			}
-			ao2_lock(p);
 		} else {
 			/* lock both channels first, then get the pvt lock */
 			ast_channel_lock_both(chan, owner);
-			ao2_lock(p);
-		}
+		}
+		ao2_lock(p);
 
 		/* Now that we have all the locks, validate that nothing changed */
 		if (p->owner != owner || p->chan != chan) {
@@ -211,7 +210,6 @@
 				ast_channel_unlock(chan);
 				chan = ast_channel_unref(chan);
 			}
-			ao2_unlock(p);
 			continue;
 		}
 
@@ -225,7 +223,7 @@
 static int local_setoption(struct ast_channel *ast, int option, void * data, int datalen)
 {
 	int res = 0;
-	struct local_pvt *p = NULL;
+	struct local_pvt *p;
 	struct ast_channel *otherchan = NULL;
 	ast_chan_write_info_t *write_info;
 
@@ -272,9 +270,7 @@
 	ast_channel_unlock(otherchan);
 
 setoption_cleanup:
-	if (p) {
-		ao2_ref(p, -1);
-	}
+	ao2_ref(p, -1);
 	if (otherchan) {
 		ast_channel_unref(otherchan);
 	}
@@ -468,8 +464,8 @@
 		return -1;
 	}
 
+	ao2_ref(p, 1);
 	ao2_lock(p);
-	ao2_ref(p, 1);
 	isoutbound = IS_OUTBOUND(ast, p);
 	if (isoutbound) {
 		/* Pass along answer since somebody answered us */
@@ -839,8 +835,8 @@
 		return -1;
 	}
 
+	ao2_ref(p, 1); /* ref for local_queue_frame */
 	ao2_lock(p);
-	ao2_ref(p, 1); /* ref for local_queue_frame */
 	isoutbound = IS_OUTBOUND(ast, p);
 	f.data.ptr = (char *) text;
 	f.datalen = strlen(text) + 1;
@@ -861,8 +857,8 @@
 		return -1;
 	}
 
+	ao2_ref(p, 1); /* ref for local_queue_frame */
 	ao2_lock(p);
-	ao2_ref(p, 1); /* ref for local_queue_frame */
 	isoutbound = IS_OUTBOUND(ast, p);
 	f.subclass.integer = subclass;
 	f.data.ptr = (char *)data;




More information about the asterisk-commits mailing list