[asterisk-commits] russell: branch murf/bug11210 r99403 - /team/murf/bug11210/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 22 10:39:47 CST 2008


Author: russell
Date: Mon Jan 21 15:43:54 2008
New Revision: 99403

URL: http://svn.digium.com/view/asterisk?view=rev&rev=99403
Log:
Remove the dialog list lock, which is no longer needed and is just a remnant from when
it was a simple list.  Also, remove the lock inside of sip_pvt, in favor of using
the built-in lock since it is an astobj2.

Modified:
    team/murf/bug11210/channels/chan_sip.c

Change Statistics:
 team/murf/bug11210/channels/chan_sip.c |   59 +++++----------------
 1 file changed, 16 insertions(+), 43 deletions(-)

Modified: team/murf/bug11210/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/channels/chan_sip.c?view=diff&rev=99403&r1=99402&r2=99403
==============================================================================
--- team/murf/bug11210/channels/chan_sip.c (original)
+++ team/murf/bug11210/channels/chan_sip.c Mon Jan 21 15:43:54 2008
@@ -1155,7 +1155,6 @@
  */
 struct sip_pvt {
 	struct sip_pvt *next;			/*!< Next dialog in chain */
-	ast_mutex_t pvt_lock;			/*!< Dialog private lock */
 	enum invitestates invitestate;		/*!< Track state of SIP_INVITEs */
 	int method;				/*!< SIP method that opened this dialog */
 	AST_DECLARE_STRING_FIELDS(
@@ -1309,31 +1308,7 @@
  * the container and individual items, and functions to add/remove
  * references to the individual items.
  */
-/* static struct sip_pvt *dialoglist = NULL; */
-
 struct ao2_container *dialogs;
-
-
-/*! \brief Protect the SIP dialog list (of sip_pvt's) */
-AST_MUTEX_DEFINE_STATIC(dialoglock);
-
-#ifndef DETECT_DEADLOCKS
-/*! \brief hide the way the list is locked/unlocked */
-static void dialoglist_lock(void)
-{
-	ast_mutex_lock(&dialoglock);
-}
-
-static void dialoglist_unlock(void)
-{
-	ast_mutex_unlock(&dialoglock);
-}
-#else
-/* we don't want to HIDE the information about where the lock was requested if trying to debug 
- * deadlocks!  So, just make these macros! */
-#define dialoglist_lock(x) ast_mutex_lock(&dialoglock)
-#define dialoglist_unlock(x) ast_mutex_unlock(&dialoglock)
-#endif
 
 /*!
  * when we create or delete references, make sure to use these
@@ -2369,8 +2344,8 @@
 	return NULL;
 }
 
-#define sip_pvt_lock(x) ast_mutex_lock(&x->pvt_lock)
-#define sip_pvt_unlock(x) ast_mutex_unlock(&x->pvt_lock)
+#define sip_pvt_lock(x) ao2_lock(x)
+#define sip_pvt_unlock(x) ao2_unlock(x)
 
 /*!
  * helper functions to unreference various types of objects.
@@ -4502,10 +4477,8 @@
 		ast_variables_destroy(p->chanvars);
 		p->chanvars = NULL;
 	}
-	ast_mutex_destroy(&p->pvt_lock);
 
 	ast_string_field_free_memory(p);
-	
 }
 
 /*! \brief  update_call_counter: Handle call_limit for SIP users 
@@ -5825,8 +5798,6 @@
 		return NULL;
 	}
 
-	ast_mutex_init(&p->pvt_lock);
-
 	p->socket.fd = -1;
 	p->socket.type = SIP_TRANSPORT_UDP;
 	p->method = intended_method;
@@ -5876,7 +5847,6 @@
  			ast_log(LOG_WARNING, "Unable to create RTP audio %s%ssession: %s\n",
  				ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "and video " : "",
  				ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "and text " : "", strerror(errno));
-			ast_mutex_destroy(&p->pvt_lock);
 			if (p->chanvars) {
 				ast_variables_destroy(p->chanvars);
 				p->chanvars = NULL;
@@ -13716,11 +13686,12 @@
 	if (a->argc != 4)
 		return CLI_SHOWUSAGE;
 	len = strlen(a->argv[3]);
-	dialoglist_lock();
 	
 	i = ao2_iterator_init(dialogs, 0);
 
 	while ((cur = ao2_t_iterator_next(&i, "iterate thru dialogs"))) {
+		sip_pvt_lock(cur);
+
 		if (!strncasecmp(cur->callid, a->argv[3], len)) {
 			char formatbuf[BUFSIZ/2];
 			ast_cli(a->fd,"\n");
@@ -13792,11 +13763,15 @@
 
 			found++;
 		}
+
+		sip_pvt_unlock(cur);
+
 		ao2_t_ref(cur,-1,"toss dialog ptr set by iterator_next");
 	}
-	dialoglist_unlock();
+
 	if (!found) 
 		ast_cli(a->fd, "No such SIP Call ID starting with '%s'\n", a->argv[3]);
+
 	return CLI_SUCCESS;
 }
 
@@ -13821,12 +13796,15 @@
 
 	if (a->argc != 4)
 		return CLI_SHOWUSAGE;
+
 	if (!recordhistory)
 		ast_cli(a->fd, "\n***Note: History recording is currently DISABLED.  Use 'sip history' to ENABLE.\n");
+
 	len = strlen(a->argv[3]);
-	dialoglist_lock();
+
 	i = ao2_iterator_init(dialogs, 0);
 	while ((cur = ao2_t_iterator_next(&i,"iterate thru dialogs"))) {
+		sip_pvt_lock(cur);
 		if (!strncasecmp(cur->callid, a->argv[3], len)) {
 			struct sip_history *hist;
 			int x = 0;
@@ -13843,11 +13821,13 @@
 				ast_cli(a->fd, "Call '%s' has no history\n", cur->callid);
 			found++;
 		}
+		sip_pvt_unlock(cur);
 		ao2_t_ref(cur,-1,"toss dialog ptr from iterator_next");
 	}
-	dialoglist_unlock();
+
 	if (!found) 
 		ast_cli(a->fd, "No such SIP Call ID starting with '%s'\n", a->argv[3]);
+
 	return CLI_SUCCESS;
 }
 
@@ -18093,8 +18073,6 @@
 			for it to expire and send NOTIFY messages to the peer only to have them
 			ignored (or generate errors)
 			*/
-			dialoglist_lock();
-
 			i = ao2_iterator_init(dialogs, 0);
 
 			while ((p_old = ao2_t_iterator_next(&i,"iterate thru dialogs"))) {
@@ -18123,7 +18101,6 @@
 				sip_pvt_unlock(p_old);
 				ao2_t_ref(p_old,-1,"toss dialog ptr from iterator_next");
 			}
-			dialoglist_unlock();
 		}
 		if (!p->expiry)
 			p->needdestroy = 1;
@@ -22507,7 +22484,6 @@
 	AST_LIST_TRAVERSE_SAFE_END;
 	AST_LIST_UNLOCK(&threadl);
 
-	dialoglist_lock();
 	/* Hangup all dialogs if they have an owner */
 	i = ao2_iterator_init(dialogs, 0);
 	while ((p = ao2_t_iterator_next(&i, "iterate thru dialogs"))) {
@@ -22515,7 +22491,6 @@
 			ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
 		ao2_t_ref(p,-1,"toss dialog ptr from iterator_next");
 	}
-	dialoglist_unlock();
 	ast_log(LOG_NOTICE,"...Done! Now, grab a monitor lock and join threads...\n");
 
 	ast_mutex_lock(&monlock);
@@ -22528,14 +22503,12 @@
 	ast_mutex_unlock(&monlock);
 	ast_log(LOG_NOTICE,"...Done! Now, grab the dialoglist lock and get rid of the dialogs...\n");
 
-	dialoglist_lock();
 	/* Destroy all the dialogs and free their memory */
 	i = ao2_iterator_init(dialogs, 0);
 	while ((p = ao2_t_iterator_next(&i, "iterate thru dialogs"))) {
 		ao2_t_unlink(dialogs,p,"unlink from dialogs");
 		ao2_t_ref(p,-1,"throw away iterator result"); 
 	}
-	dialoglist_unlock();
 
 	ast_log(LOG_NOTICE,"...Done! Now, free up the ha's...\n");
 	/* Free memory for local network address mask */




More information about the asterisk-commits mailing list