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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Nov 19 02:52:42 MST 2006


Author: rizzo
Date: Sun Nov 19 03:52:40 2006
New Revision: 47837

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47837
Log:
document usage of sip_destroy() and __sip_destroy().


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?view=diff&rev=47837&r1=47836&r2=47837
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sun Nov 19 03:52:40 2006
@@ -1354,7 +1354,6 @@
 static void sip_scheddestroy(struct sip_pvt *p, int ms);
 static void sip_cancel_destroy(struct sip_pvt *p);
 static struct sip_pvt * sip_destroy(struct sip_pvt *p);
-static struct sip_pvt *__sip_destroy(struct sip_pvt *p);
 static void __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod);
 static void __sip_pretend_ack(struct sip_pvt *p);
 static int __sip_semi_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod);
@@ -3106,7 +3105,6 @@
 static void pvt_destructor(void *__p)
 {
 	struct sip_pvt *p = __p;
-	struct sip_pkt *cp;
 
 	if (sip_debug_test_pvt(p) || option_debug > 2)
 		ast_verbose("Really destroying SIP dialog '%s' Method: %s\n", p->callid, sip_methods[p->method].text);
@@ -3174,31 +3172,42 @@
 		p->history = NULL;
 	}
 
-	/* remove all current packets in this dialog */
+	if (p->chanvars) {
+		ast_variables_destroy(p->chanvars);
+		p->chanvars = NULL;
+	}
+
+	ast_string_field_free_pools(p);
+}
+
+/*!
+ * The function to call when we want to explicity destroy a sip_pvt
+ * that is not linked in the list (or when we want to optimize its
+ * destruction). It should be rarely used - callers should invoke
+ * sip_destroy() instead.
+ */
+static struct sip_pvt *__sip_destroy(struct sip_pvt *p)
+{
+	struct sip_pkt *cp;
+	/* remove all current packets in this dialog.
+	 * They have a reference to the sip_pvt so we cannot put this in
+	 * the destructor
+	 */
 	while((cp = p->packets)) {
 		p->packets = p->packets->next;
 		if (cp->retransid > -1)
 			ast_sched_del(sched, cp->retransid);
 		free(cp);
 	}
-	if (p->chanvars) {
-		ast_variables_destroy(p->chanvars);
-		p->chanvars = NULL;
-	}
-
-	ast_string_field_free_pools(p);
-}
-
-static struct sip_pvt *__sip_destroy(struct sip_pvt *p)
-{
 #ifdef USE_AO2
-	/* debugging */
+{	/* debugging */
 	int n = ao2_ref(p, 0);
 	if (n != 1) {
 		ast_verbose("__sip_destroy on object with %d refs\n", n);
 		ao2_bt();
 		*(char *)0 = 1;/* crash */
 	}
+}
 	pvt_unref(p);	/* automatically calls pvt_destructor on ao2*/
 #else
 	pvt_unref(p);	/* automatically calls pvt_destructor on ao2*/
@@ -3329,7 +3338,7 @@
 	return 0;
 }
 
-/*! \brief Destroy SIP call structure */
+/*! \brief Destroy SIP call structure (after unlinking it from the list) */
 static struct sip_pvt *sip_destroy(struct sip_pvt *p)
 {
 	if (option_debug > 2)
@@ -15373,6 +15382,7 @@
 				check_rtp_timeout(cur, t);
 				/* If we have sessions that needs to be destroyed, do it now */
 				if (test_destroy(cur) && !cur->packets && !cur->owner) {
+					/* XXX optimized version of sip_destroy() */
 					struct sip_pvt *tmp = cur;
 					sip_pvt_unlock(tmp);
 					/* unlink, and prepare for next iteration */



More information about the asterisk-commits mailing list