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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Nov 7 11:44:00 MST 2006


Author: rizzo
Date: Tue Nov  7 12:43:59 2006
New Revision: 47277

URL: http://svn.digium.com/view/asterisk?rev=47277&view=rev
Log:
simplify the expire loop in do_monitor(). This is now O(N)
which is as simple as it can be with the current structure,
instead of O(N^2) as it was before.

The diffs between team/rizzo/astobj2-47271 and this one are certainly trunk
candidate because of the performance implications.


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=47277&r1=47276&r2=47277&view=diff
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Tue Nov  7 12:43:59 2006
@@ -14990,7 +14990,6 @@
 static void *do_monitor(void *data)
 {
 	int res;
-	struct sip_pvt *sip;
 	struct sip_peer *peer = NULL;
 	int fastrestart = FALSE;
 	int lastpeernum = -1;
@@ -15015,23 +15014,33 @@
 		   get back to this point every millisecond or less)
 		*/
 		if (!fastrestart) {
+			struct sip_pvt *cur, *prev = NULL;
 			time_t t;
+
 			dialoglist_lock();
-restartsearch:		
 			t = time(NULL);
-			for (sip = dialoglist; sip; sip = sip->next) {
-				sip_pvt_lock(sip);
+			cur = dialoglist;
+        		while (cur) {
+				sip_pvt_lock(cur);
 				/* Check RTP timeouts and kill calls if we have a timeout set and do not get RTP */
-				check_rtp_timeout(sip, t);
+				check_rtp_timeout(cur, t);
 				/* If we have sessions that needs to be destroyed, do it now */
-				if (ast_test_flag(&sip->flags[0], SIP_NEEDDESTROY) && !sip->packets &&
-				    !sip->owner) {
-					sip_pvt_unlock(sip);
-					sip_pvt_unlink(sip);	/* XXX do it inline, here */
-					__sip_destroy(sip);
-					goto restartsearch;
+				if (ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY) && !cur->packets && !cur->owner) {
+					struct sip_pvt *tmp = cur;
+					sip_pvt_unlock(tmp);
+					/* unlink, and prepare for next iteration */
+					cur = cur->next;
+					if (prev == NULL)
+						dialoglist = cur;
+					else
+						prev->next = cur;
+					/* now we can free the record */
+					__sip_destroy(tmp);
+				} else {
+					sip_pvt_unlock(cur);
+					prev = cur;
+					cur = cur->next;
 				}
-				sip_pvt_unlock(sip);
 			}
 			dialoglist_unlock();
 		}



More information about the asterisk-commits mailing list