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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Nov 6 09:10:57 MST 2006


Author: rizzo
Date: Mon Nov  6 10:10:57 2006
New Revision: 47224

URL: http://svn.digium.com/view/asterisk?rev=47224&view=rev
Log:
hide dialoglist lock/unlocking in wrapper functions.

candidate for trunk.


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=47224&r1=47223&r2=47224&view=diff
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Mon Nov  6 10:10:57 2006
@@ -558,9 +558,6 @@
 static int regobjs = 0;                  /*!< Registry objects */
 
 static struct ast_flags global_flags[2] = {{0}};        /*!< global SIP_ flags */
-
-/*! \brief Protect the SIP dialog list (of sip_pvt's) */
-AST_MUTEX_DEFINE_STATIC(dialoglock);
 
 AST_MUTEX_DEFINE_STATIC(netlock);
 
@@ -995,6 +992,20 @@
 
 static struct sip_pvt *dialoglist = NULL;
 
+/*! \brief Protect the SIP dialog list (of sip_pvt's) */
+AST_MUTEX_DEFINE_STATIC(dialoglock);
+
+/*! \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);
+}
+
 #define FLAG_RESPONSE (1 << 0)
 #define FLAG_FATAL (1 << 1)
 
@@ -2982,7 +2993,7 @@
 
 	/* Lock dialog list before removing ourselves from the list */
 	if (lockdialoglist)
-		ast_mutex_lock(&dialoglock);
+		dialoglist_lock();
 	for (prev = NULL, cur = dialoglist; cur; prev = cur, cur = cur->next) {
 		if (cur == p) {
 			UNLINK(cur, dialoglist, prev);
@@ -2990,7 +3001,7 @@
 		}
 	}
 	if (lockdialoglist)
-		ast_mutex_unlock(&dialoglock);
+		dialoglist_unlock();
 	if (!cur) {
 		ast_log(LOG_WARNING, "Trying to destroy \"%s\", not found in dialog list?!?! \n", p->callid);
 		return;
@@ -4297,10 +4308,10 @@
 	ast_string_field_set(p, context, default_context);
 
 	/* Add to active dialog list */
-	ast_mutex_lock(&dialoglock);
+	dialoglist_lock();
 	p->next = dialoglist;
 	dialoglist = p;
-	ast_mutex_unlock(&dialoglock);
+	dialoglist_unlock();
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : "(No Call-ID)", sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP");
 	return p;
@@ -4342,7 +4353,7 @@
 			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);
 	}
 
-	ast_mutex_lock(&dialoglock);
+	dialoglist_lock();
 	for (p = dialoglist; p; p = p->next) {
 		/* In pedantic, we do not want packets with bad syntax to be connected to a PVT */
 		int found = FALSE;
@@ -4373,11 +4384,11 @@
 		if (found) {
 			/* Found the call */
 			sip_pvt_lock(p);
-			ast_mutex_unlock(&dialoglock);
+			dialoglist_unlock();
 			return p;
 		}
 	}
-	ast_mutex_unlock(&dialoglock);
+	dialoglist_unlock();
 	
 	/* See if the method is capable of creating a dialog */
 	if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) {
@@ -8511,7 +8522,7 @@
 {
 	struct sip_pvt *sip_pvt_ptr;
 
-	ast_mutex_lock(&dialoglock);
+	dialoglist_lock();
 
 	if (option_debug > 3 && totag)
 		ast_log(LOG_DEBUG, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>");
@@ -8551,7 +8562,7 @@
 			break;
 		}
 	}
-	ast_mutex_unlock(&dialoglock);
+	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;
@@ -10427,7 +10438,7 @@
 
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
-	ast_mutex_lock(&dialoglock);
+	dialoglist_lock();
 	cur = dialoglist;
 	if (!subscriptions)
 		ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message");
@@ -10464,7 +10475,7 @@
 			numchans++;
 		}
 	}
-	ast_mutex_unlock(&dialoglock);
+	dialoglist_unlock();
 	if (!subscriptions)
 		ast_cli(fd, "%d active SIP channel%s\n", numchans, (numchans != 1) ? "s" : "");
 	else
@@ -10483,14 +10494,14 @@
 	char *c = NULL;
 	int wordlen = strlen(word);
 
-	ast_mutex_lock(&dialoglock);
+	dialoglist_lock();
 	for (cur = dialoglist; cur; cur = cur->next) {
 		if (!strncasecmp(word, cur->callid, wordlen) && ++which > state) {
 			c = ast_strdup(cur->callid);
 			break;
 		}
 	}
-	ast_mutex_unlock(&dialoglock);
+	dialoglist_unlock();
 	return c;
 }
 
@@ -10615,7 +10626,7 @@
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 	len = strlen(argv[3]);
-	ast_mutex_lock(&dialoglock);
+	dialoglist_lock();
 	for (cur = dialoglist; cur; cur = cur->next) {
 		if (!strncasecmp(cur->callid, argv[3], len)) {
 			char formatbuf[BUFSIZ/2];
@@ -10669,7 +10680,7 @@
 			found++;
 		}
 	}
-	ast_mutex_unlock(&dialoglock);
+	dialoglist_unlock();
 	if (!found) 
 		ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]);
 	return RESULT_SUCCESS;
@@ -10687,7 +10698,7 @@
 	if (!recordhistory)
 		ast_cli(fd, "\n***Note: History recording is currently DISABLED.  Use 'sip history' to ENABLE.\n");
 	len = strlen(argv[3]);
-	ast_mutex_lock(&dialoglock);
+	dialoglist_lock();
 	for (cur = dialoglist; cur; cur = cur->next) {
 		if (!strncasecmp(cur->callid, argv[3], len)) {
 			struct sip_history *hist;
@@ -10706,7 +10717,7 @@
 			found++;
 		}
 	}
-	ast_mutex_unlock(&dialoglock);
+	dialoglist_unlock();
 	if (!found) 
 		ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]);
 	return RESULT_SUCCESS;
@@ -14333,7 +14344,7 @@
 			for it to expire and send NOTIFY messages to the peer only to have them
 			ignored (or generate errors)
 			*/
-			ast_mutex_lock(&dialoglock);
+			dialoglist_lock();
 			for (p_old = dialoglist; p_old; p_old = p_old->next) {
 				if (p_old == p)
 					continue;
@@ -14352,7 +14363,7 @@
 				}
 				sip_pvt_unlock(p_old);
 			}
-			ast_mutex_unlock(&dialoglock);
+			dialoglist_unlock();
 		}
 		if (!p->expiry)
 			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
@@ -14862,7 +14873,7 @@
 				sipsock_read_id = ast_io_change(io, sipsock_read_id, sipsock, NULL, 0, NULL);
 		}
 		/* Check for dialogs needing to be killed */
-		ast_mutex_lock(&dialoglock);
+		dialoglist_lock();
 restartsearch:		
 		t = time(NULL);
 		/* don't scan the dialogs list if it hasn't been a reasonable period
@@ -14882,7 +14893,7 @@
 			}
 			sip_pvt_unlock(sip);
 		}
-		ast_mutex_unlock(&dialoglock);
+		dialoglist_unlock();
 
 		pthread_testcancel();
 		/* Wait for sched or io */
@@ -17207,13 +17218,13 @@
 	ast_manager_unregister("SIPpeers");
 	ast_manager_unregister("SIPshowpeer");
 
-	ast_mutex_lock(&dialoglock);
+	dialoglist_lock();
 	/* Hangup all dialogs if they have an owner */
 	for (p = dialoglist; p ; p = p->next) {
 		if (p->owner)
 			ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
 	}
-	ast_mutex_unlock(&dialoglock);
+	dialoglist_unlock();
 
 	ast_mutex_lock(&monlock);
 	if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
@@ -17224,7 +17235,7 @@
 	monitor_thread = AST_PTHREADT_STOP;
 	ast_mutex_unlock(&monlock);
 
-	ast_mutex_lock(&dialoglock);
+	dialoglist_lock();
 	/* Destroy all the dialogs and free their memory */
 	p = dialoglist;
 	while (p) {
@@ -17239,7 +17250,7 @@
 		free(pl);
 	}
 	dialoglist = NULL;
-	ast_mutex_unlock(&dialoglock);
+	dialoglist_unlock();
 
 	/* Free memory for local network address mask */
 	ast_free_ha(localaddr);



More information about the asterisk-commits mailing list