[asterisk-commits] russell: branch russell/iax2_find_callno r114817 - /team/russell/iax2_find_ca...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 28 18:46:55 CDT 2008


Author: russell
Date: Mon Apr 28 18:46:55 2008
New Revision: 114817

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114817
Log:
Add some code that keeps track of active pvt structs in a 2nd container,
indexed by the peer call number.  I haven't actually modified find_callno
yet.  However, I may end up redoing this a different way, because I may
be forced to do so to avoid deadlocks ...

Modified:
    team/russell/iax2_find_callno/channels/chan_iax2.c

Modified: team/russell/iax2_find_callno/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax2_find_callno/channels/chan_iax2.c?view=diff&rev=114817&r1=114816&r2=114817
==============================================================================
--- team/russell/iax2_find_callno/channels/chan_iax2.c (original)
+++ team/russell/iax2_find_callno/channels/chan_iax2.c Mon Apr 28 18:46:55 2008
@@ -87,6 +87,7 @@
 #include "asterisk/netsock.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/linkedlists.h"
+#include "asterisk/dlinkedlists.h"
 #include "asterisk/event.h"
 #include "asterisk/astobj2.h"
 
@@ -644,6 +645,8 @@
 	int frames_dropped;
 	/*! received frame count: (just for stats) */
 	int frames_received;
+
+	AST_DLLIST_ENTRY(chan_iax2_pvt) entry;
 };
 
 /*!
@@ -842,6 +845,22 @@
  * index into the array where the associated pvt structure is stored.
  */
 static struct chan_iax2_pvt *iaxs[IAX_MAX_CALLS];
+
+/*!
+ * \brief Another container of iax2_pvt structures
+ *
+ * Active IAX2 pvt structs are also stored in this container, if they are a part
+ * of an active call where we know the remote side's call number.  The reason
+ * for this is that incoming media frames do not contain our call number.  So,
+ * instead of having to iterate the entire iaxs array, we use this container to
+ * look up calls where the remote side is using a given call number.
+ *
+ * This container is an array of lists.  The index into the array is the remote
+ * call number.  The list contains all calls where the remote side is using the
+ * index as its call number.
+ */
+static AST_DLLIST_HEAD(, chan_iax2_pvt) iax_peercallno_pvts[IAX_MAX_CALLS];
+
 /*!
  * \brief chan_iax2_pvt structure locks
  *
@@ -850,6 +869,7 @@
  * local call number for the associated pvt struct.
  */
 static ast_mutex_t iaxsl[IAX_MAX_CALLS];
+
 /*!
  * \brief The last time a call number was used
  *
@@ -1475,6 +1495,24 @@
 	return res;
 }
 
+static void store_by_peercallno(struct chan_iax2_pvt *pvt)
+{
+	AST_DLLIST_LOCK(&iax_peercallno_pvts[pvt->peercallno]);
+	AST_DLLIST_INSERT_HEAD(&iax_peercallno_pvts[pvt->peercallno], pvt, entry);
+	AST_DLLIST_UNLOCK(&iax_peercallno_pvts[pvt->peercallno]);
+}
+
+static void remove_by_peercallno(struct chan_iax2_pvt *pvt)
+{
+	if (!pvt->peercallno) {
+		return;
+	}
+
+	AST_DLLIST_LOCK(&iax_peercallno_pvts[pvt->peercallno]);
+	AST_DLLIST_REMOVE(&iax_peercallno_pvts[pvt->peercallno], pvt, entry);
+	AST_DLLIST_UNLOCK(&iax_peercallno_pvts[pvt->peercallno]);
+}
+
 /*!
  * \todo XXX Note that this function contains a very expensive operation that
  * happens for *every* incoming media frame.  It iterates through every
@@ -1499,6 +1537,10 @@
 	char host[80];
 
 	if (new <= NEW_ALLOW) {
+		if (callno) {
+			/* XXX Look for pvt by peer callno here ... */
+		}
+
 		for (x = 1; !res && x < maxnontrunkcall; x++) {
 			ast_mutex_lock(&iaxsl[x]);
 			if (iaxs[x]) {
@@ -1581,6 +1623,8 @@
 			ast_string_field_set(iaxs[x], mohinterpret, mohinterpret);
 			ast_string_field_set(iaxs[x], mohsuggest, mohsuggest);
 			ast_string_field_set(iaxs[x], parkinglot, default_parkinglot);
+
+			store_by_peercallno(iaxs[x]);
 		} else {
 			ast_log(LOG_WARNING, "Out of resources\n");
 			ast_mutex_unlock(&iaxsl[x]);
@@ -2173,6 +2217,8 @@
 			ast_string_field_free_memory(pvt);
 			ast_free(pvt);
 		}
+
+		remove_by_peercallno(pvt);
 	}
 	if (owner) {
 		ast_channel_unlock(owner);
@@ -6380,7 +6426,11 @@
 	pvt->rseqno = 0;
 	pvt->iseqno = 0;
 	pvt->aseqno = 0;
+
+	remove_by_peercallno(pvt);
 	pvt->peercallno = peercallno;
+	store_by_peercallno(pvt);
+
 	pvt->transferring = TRANSFER_NONE;
 	pvt->svoiceformat = -1;
 	pvt->voiceformat = 0;
@@ -7898,7 +7948,9 @@
 	if (!inaddrcmp(&sin, &iaxs[fr->callno]->addr) && !minivid &&
 		f.subclass != IAX_COMMAND_TXCNT &&		/* for attended transfer */
 		f.subclass != IAX_COMMAND_TXACC) {		/* for attended transfer */
-		iaxs[fr->callno]->peercallno = (unsigned short)(ntohs(mh->callno) & ~IAX_FLAG_FULL);
+		remove_by_peercallno(iaxs[fr->callno]);
+		iaxs[fr->callno]->peercallno = (unsigned short) (ntohs(mh->callno) & ~IAX_FLAG_FULL);
+		store_by_peercallno(iaxs[fr->callno]);
 	}
 	if (ntohs(mh->callno) & IAX_FLAG_FULL) {
 		if (iaxdebug)




More information about the asterisk-commits mailing list