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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Nov 9 14:42:39 MST 2006


Author: rizzo
Date: Thu Nov  9 15:42:38 2006
New Revision: 47393

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47393
Log:
small reordering of lines and removal of code unused in the astobj2 case


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=47393&r1=47392&r2=47393
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Thu Nov  9 15:42:38 2006
@@ -82,6 +82,7 @@
  * the sip_hangup() function
  */
 
+// #define	USE_AO2		// enable to use astobj2
 
 #include "asterisk.h"
 
@@ -874,7 +875,10 @@
  */
 
 struct sip_pvt {
+#ifndef USE_AO2
+	struct sip_pvt *next;			/*!< Next dialog in chain */
 	ast_mutex_t pvt_lock;			/*!< Dialog private lock */
+#endif
 	int method;				/*!< SIP method that opened this dialog */
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(callid);	/*!< Global CallID */
@@ -985,7 +989,6 @@
 	struct sip_pkt *packets;		/*!< Packets scheduled for re-transmission */
 	struct sip_history_head *history;	/*!< History of this SIP dialog */
 	struct ast_variable *chanvars;		/*!< Channel variables to set for inbound call */
-	struct sip_pvt *next;			/*!< Next dialog in chain */
 	struct sip_invite_param *options;	/*!< Options for INVITE */
 	int autoframing;			/*!< The number of Asters we group in a Pyroflax
 							before strolling to the Grokyzpå
@@ -993,19 +996,9 @@
 							you know more) */
 };
 
-// #define	USE_AO2
 #ifdef	USE_AO2	/* astobj2 implementation */
 #include "asterisk/astobj2.h"
 ao2_container *dialogs;
-
-/* we never need to lock these */
-static void dialoglist_lock(void)
-{
-}
-
-static void dialoglist_unlock(void)
-{
-}
 
 #else	/* normal container */
 #define	CMP_MATCH	1
@@ -1641,12 +1634,20 @@
  */
 static void sip_pvt_lock(struct sip_pvt *pvt)
 {
+#ifdef USE_AO2
+	ao2_lock(pvt);
+#else
 	ast_mutex_lock(&pvt->pvt_lock);
+#endif
 }
 
 static void sip_pvt_unlock(struct sip_pvt *pvt)
 {
+#ifdef USE_AO2
+	ao2_unlock(pvt);
+#else
 	ast_mutex_unlock(&pvt->pvt_lock);
+#endif
 }
 
 /*!
@@ -3146,9 +3147,9 @@
 
 static struct sip_pvt *__sip_destroy(struct sip_pvt *p)
 {
-	ast_mutex_destroy(&p->pvt_lock);	/* XXX not used in ao2 */
 	pvt_unref(p);	/* automatically calls pvt_destructor on ao2*/
 #ifndef USE_AO2
+	ast_mutex_destroy(&p->pvt_lock);	/* XXX not used in ao2 */
 	pvt_destructor(p);
 	free(p);
 #endif
@@ -4346,7 +4347,9 @@
 	if (!p)
 		return NULL;
 
+#ifndef USE_AO2
 	ast_mutex_init(&p->pvt_lock);	/* XXX not necessary in ao2 */
+#endif
 
 	/* initialize fields so that __sip_destroy() can handle them */
 	p->method = intended_method;
@@ -4510,7 +4513,6 @@
  */
 static struct sip_pvt *find_call(struct sip_request *req, struct sockaddr_in *sin, const int intended_method)
 {
-	static int profile_id = -1;
 	struct sip_pvt *p = NULL;
 	char totag[128];	/* not initialized, but not used if !pedantic */
 	char fromtag[128];	/* not initialized, but not used if !pedantic */
@@ -4549,9 +4551,6 @@
 			ast_log(LOG_DEBUG, "= Looking for  Call ID: %s (Checking %s) --From tag %s --To-tag %s  \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag);
 	}
 
-	dialoglist_lock();
-	if (profile_id == -1)
-		profile_id = ast_add_profile("find_call", 0);
 #ifdef USE_AO2
 	p = ao2_callback(dialogs, 0 /* single, data */, find_call_cb, &arg);
 	if (p) {
@@ -4559,17 +4558,14 @@
 		return p;
 	}
 #else
-	ast_mark(profile_id, 1 /* start */);
+	dialoglist_lock();
 	for (p = dialoglist; p; p = p->next) {
 		if (find_call_cb(p, &arg, 0)) {
 			/* Found the call, lock p before unlocking the container */
-			ast_mark(profile_id, 0 /* stop */);
 			sip_pvt_lock(p);
 			break;
 		}
 	}
-	if (!p)
-		ast_mark(profile_id, 0 /* stop */);
 	dialoglist_unlock();
 	if (p)
 		return p;
@@ -8753,16 +8749,16 @@
 		ast_log(LOG_DEBUG, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>");
 
 	/* Search dialogs and find the match */
-	dialoglist_lock();
 #ifdef USE_AO2
 	sip_pvt_ptr = ao2_callback(dialogs, 0 /* single, data */, find_pvt_byid_cb, &arg);
 #else
+	dialoglist_lock();
 	for (sip_pvt_ptr = dialoglist; sip_pvt_ptr; sip_pvt_ptr = sip_pvt_ptr->next) {
 		if (find_pvt_byid_cb(sip_pvt_ptr, &arg, 0))
 			break;
 	}
+	dialoglist_unlock();
 #endif
-	dialoglist_unlock();
 	if (option_debug > 3 && !sip_pvt_ptr)
 		ast_log(LOG_DEBUG, "Found no match for callid %s to-tag %s from-tag %s\n", callid, totag, fromtag);
 	return sip_pvt_ptr;
@@ -10636,7 +10632,7 @@
 #define FORMAT3 "%-15.15s  %-10.10s  %-11.11s  %-15.15s  %-13.13s  %-15.15s %-10.10s\n"
 #define FORMAT2 "%-15.15s  %-10.10s  %-11.11s  %-11.11s  %-4.4s  %-7.7s  %-15.15s\n"
 #define FORMAT  "%-15.15s  %-10.10s  %-11.11s  %5.5d/%5.5d  %-4.4s  %-3.3s %-3.3s  %-15.15s %-10.10s\n"
-static int show_chanannels_cb(void *__cur, void *__arg, int flags)
+static int show_channels_cb(void *__cur, void *__arg, int flags)
 {
 	struct sip_pvt *cur = __cur;
 	struct __show_chan_arg *arg = __arg;
@@ -10685,16 +10681,16 @@
 		ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message");
 	else 
 		ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox");
-	dialoglist_lock();
 #ifdef USE_AO2
 	cur = NULL;	/* silence compiler */
-        ao2_callback(dialogs, OBJ_MULTIPLE|OBJ_NODATA, show_chanannels_cb, &arg);
+        ao2_callback(dialogs, OBJ_MULTIPLE|OBJ_NODATA, show_channels_cb, &arg);
 #else
+	dialoglist_lock();
 	for (cur = dialoglist; cur; cur = cur->next) {
-		show_chanannels_cb(cur, &arg, 0);
-	}
+		show_channels_cb(cur, &arg, 0);
+	}
+	dialoglist_unlock();
 #endif
-	dialoglist_unlock();
 	if (!subscriptions)
 		ast_cli(fd, "%d active SIP channel%s\n", arg.numchans, (arg.numchans != 1) ? "s" : "");
 	else
@@ -10932,7 +10928,6 @@
 	arg.str = argv[3];
 	arg.len = strlen(argv[3]);
 	arg.found = 0;
-	dialoglist_lock();
 #ifdef USE_AO2
     {
 	ao2_iterator i = ao2_iterator_init(dialogs, 0);
@@ -10942,11 +10937,12 @@
 	}
     }
 #else
+	dialoglist_lock();
 	for (cur = dialoglist; cur; cur = cur->next) {
 		show_channel_cb(cur, &arg);
 	}
+	dialoglist_unlock();
 #endif
-	dialoglist_unlock();
 	if (arg.found == 0) 
 		ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]);
 	return RESULT_SUCCESS;
@@ -10988,7 +10984,6 @@
 	arg.str = argv[3];
 	arg.len = strlen(argv[3]);
 	arg.found = 0;
-	dialoglist_lock();
 #ifdef USE_AO2
     {
 	ao2_iterator i = ao2_iterator_init(dialogs, 0);
@@ -10998,11 +10993,12 @@
 	}
     }
 #else
+	dialoglist_lock();
 	for (cur = dialoglist; cur; cur = cur->next) {
 		show_history_cb(cur, &arg);
 	}
+	dialoglist_unlock();
 #endif
-	dialoglist_unlock();
 	if (!arg.found) 
 		ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]);
 	return RESULT_SUCCESS;
@@ -14633,7 +14629,6 @@
 			for it to expire and send NOTIFY messages to the peer only to have them
 			ignored (or generate errors)
 			*/
-			dialoglist_lock();
 			{
 			struct sip_pvt *p_old;
 
@@ -14659,6 +14654,7 @@
 				ao2_ref(p_old, -1);
 			}
 #else
+			dialoglist_lock();
 			for (p_old = dialoglist; p_old; p_old = p_old->next) {
 				if (p_old == p)
 					continue;
@@ -14677,9 +14673,9 @@
 				}
 				sip_pvt_unlock(p_old);
 			}
+			dialoglist_unlock();
 #endif
 			}
-			dialoglist_unlock();
 		}
 		if (!p->expiry)
 			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
@@ -15186,12 +15182,10 @@
 		*/
 		if (!fastrestart) {
 			struct sip_pvt *cur, *prev = NULL;
-			time_t t;
-			dialoglist_lock();
-			t = time(NULL);
+			time_t t = time(NULL);
 #ifdef USE_AO2
 	/* XXX should really use a callback here */
-	{
+			{
 			ao2_iterator i = ao2_iterator_init(dialogs, 0);
 
 			prev = NULL;	/* silence compiler */
@@ -15204,8 +15198,9 @@
 				sip_pvt_unlock(cur);
 				ao2_ref(cur, -1);
 			}
-	}
+			}
 #else
+			dialoglist_lock();
 			cur = dialoglist;
         		while (cur) {
 				sip_pvt_lock(cur);
@@ -15229,8 +15224,8 @@
 					cur = cur->next;
 				}
 			}
+			dialoglist_unlock();
 #endif
-			dialoglist_unlock();
 		}
 
 		pthread_testcancel();



More information about the asterisk-commits mailing list