[asterisk-commits] rizzo: branch rizzo/astobj2 r47273 - /team/rizzo/astobj2/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Nov 7 11:20:54 MST 2006


Author: rizzo
Date: Tue Nov  7 12:20:53 2006
New Revision: 47273

URL: http://svn.digium.com/view/asterisk?rev=47273&view=rev
Log:
put the code to unlink the sip_pvt outside __sip_destroy().
This will make it possible to optimize the sip_pvt expire code in
the monitor (reducing the complexity from O(N^2) to O(N)
(not done yet).

Remove two arguments from __sip_destroy - lockowner was always
set anyways, and lockdialoglist now is unnecessary because the
list is not touched anymore.



Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?rev=47273&r1=47272&r2=47273&view=diff
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Tue Nov  7 12:20:53 2006
@@ -1278,7 +1278,7 @@
 static void sip_scheddestroy(struct sip_pvt *p, int ms);
 static void sip_cancel_destroy(struct sip_pvt *p);
 static void sip_destroy(struct sip_pvt *p);
-static void __sip_destroy(struct sip_pvt *p, int lockowner, int lockdialoglist);
+static void __sip_destroy(struct sip_pvt *p);
 static void __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod, int reset);
 static void __sip_pretend_ack(struct sip_pvt *p);
 static int __sip_semi_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod);
@@ -2988,10 +2988,32 @@
 	
 }
 
-/*! \brief Execute destruction of SIP dialog structure, release memory */
-static void __sip_destroy(struct sip_pvt *p, int lockowner, int lockdialoglist)
+/*!
+ * unlink the pvt from its container.
+ * We do not care whether or not the pvt is locked because nobody
+ * should use it now (in a perfect world, that is).
+ */
+static void sip_pvt_unlink(struct sip_pvt *p)
 {
 	struct sip_pvt *cur, *prev = NULL;
+
+	dialoglist_lock();
+	for (prev = NULL, cur = dialoglist; cur; prev = cur, cur = cur->next) {
+		if (cur == p) {
+			UNLINK(cur, dialoglist, prev);
+			break;
+		}
+	}
+	dialoglist_unlock();
+	if (!cur)
+		ast_log(LOG_WARNING, "Trying to destroy \"%s\", not found in dialog list?!?! \n", p->callid);
+}
+
+/*! \brief Execute destruction of SIP dialog structure, release memory.
+ * Assume the pvt has been already extracted from the list.
+ */
+static void __sip_destroy(struct sip_pvt *p)
+{
 	struct sip_pkt *cp;
 
 	if (sip_debug_test_pvt(p) || option_debug > 2)
@@ -3034,13 +3056,11 @@
 
 	/* Unlink us from the owner if we have one */
 	if (p->owner) {
-		if (lockowner)
-			ast_channel_lock(p->owner);
+		ast_channel_lock(p->owner);
 		if (option_debug)
 			ast_log(LOG_DEBUG, "Detaching from %s\n", p->owner->name);
 		p->owner->tech_pvt = NULL;
-		if (lockowner)
-			ast_channel_unlock(p->owner);
+		ast_channel_unlock(p->owner);
 	}
 	/* Clear history */
 	if (p->history) {
@@ -3050,22 +3070,6 @@
 		free(p->history);
 		p->history = NULL;
 	}
-
-	/* Lock dialog list before removing ourselves from the list */
-	if (lockdialoglist)
-		dialoglist_lock();
-	for (prev = NULL, cur = dialoglist; cur; prev = cur, cur = cur->next) {
-		if (cur == p) {
-			UNLINK(cur, dialoglist, prev);
-			break;
-		}
-	}
-	if (lockdialoglist)
-		dialoglist_unlock();
-	if (!cur) {
-		ast_log(LOG_WARNING, "Trying to destroy \"%s\", not found in dialog list?!?! \n", p->callid);
-		return;
-	} 
 
 	/* remove all current packets in this dialog */
 	while((cp = p->packets)) {
@@ -3210,7 +3214,8 @@
 {
 	if (option_debug > 2)
 		ast_log(LOG_DEBUG, "Destroying SIP dialog %s\n", p->callid);
-	__sip_destroy(p, TRUE, TRUE);
+	sip_pvt_unlink(p);
+	__sip_destroy(p);
 }
 
 /*! \brief Convert SIP hangup causes to Asterisk hangup causes */
@@ -15022,7 +15027,8 @@
 				if (ast_test_flag(&sip->flags[0], SIP_NEEDDESTROY) && !sip->packets &&
 				    !sip->owner) {
 					sip_pvt_unlock(sip);
-					__sip_destroy(sip, TRUE, FALSE);
+					sip_pvt_unlink(sip);	/* XXX do it inline, here */
+					__sip_destroy(sip);
 					goto restartsearch;
 				}
 				sip_pvt_unlock(sip);



More information about the asterisk-commits mailing list