[asterisk-commits] murf: branch murf/bug11210 r98997 - /team/murf/bug11210/channels/chan_iax2.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 17 14:10:56 CST 2008


Author: murf
Date: Thu Jan 17 14:10:56 2008
New Revision: 98997

URL: http://svn.digium.com/view/asterisk?view=rev&rev=98997
Log:
Begin to replace the findcallno innards for chan_iax; declare the hashtabs necc.

Modified:
    team/murf/bug11210/channels/chan_iax2.c

Modified: team/murf/bug11210/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/channels/chan_iax2.c?view=diff&rev=98997&r1=98996&r2=98997
==============================================================================
--- team/murf/bug11210/channels/chan_iax2.c (original)
+++ team/murf/bug11210/channels/chan_iax2.c Thu Jan 17 14:10:56 2008
@@ -662,7 +662,29 @@
 static struct ao2_container *peers;
 
 #define MAX_USER_BUCKETS MAX_PEER_BUCKETS
+
+#define MAX_FINDCALL1_BUCKETS 563
+#define MAX_FINDCALL2_BUCKETS 563
+#define MAX_FINDCALL3_BUCKETS 153
+#define MAX_FINDCALL4_BUCKETS 153
+
 static struct ao2_container *users;
+
+/* the following 4 hashtables must be maintained for the sake of speeding the
+   find_callno routine -- Any time one of the keys is modified, the pvt must
+   be removed from the table, updated, and relinked into the table. */
+
+static struct ao2_container *findcall1; /* keys: pvt->addr & pvt->peercallno */
+static struct ao2_container *findcall2; /* keys: pvt->addr & pvt->callno */
+static struct ao2_container *findcall3; /* keys: pvt->transfer & pvt->callno */
+static struct ao2_container *findcall4; /* keys: pvt->transfer & pvt->transfercallno */
+
+/* while 4 hash tables seems a big task, just remember that at least 3 and 4 should
+be comparably small; they would only be populated in transfer situations. The number
+of elements in 1 & 2 should track the number of open calls... If you want speed, 
+be prepared to pay the price... luckily, this is really not a huge price to 
+pay... (famous last words)... */
+
 
 static AST_LIST_HEAD_STATIC(firmwares, iax_firmware);
 
@@ -1244,6 +1266,122 @@
 	struct iax2_user *user = obj, *user2 = arg;
 
 	return !strcasecmp(user->name, user2->name) ? CMP_MATCH : 0;
+}
+
+/*!
+ * \note The only members of the pvt passed here guaranteed to be set are the addr and peercallno fields
+ */
+static int findcall1_hash_cb(const void *obj, const int flags)
+{
+	const struct chan_iax2_pvt *pvt = obj;
+	int x = pvt->addr.sin_addr.s_addr + pvt->addr.sin_port + pvt->peercallno;
+	if (x<0)
+		x = -x;
+	
+	return x;
+}
+
+/*!
+ * \note The only members of the pvt passed here guaranteed to be set are the addr and peercallno fields
+ */
+static int findcall1_cmp_cb(void *obj, void *arg, int flags)
+{
+	const struct chan_iax2_pvt *pvt1 = obj;
+	const struct chan_iax2_pvt *pvt2 = arg;
+
+	if (pvt1->addr.sin_addr.s_addr == pvt2->addr.sin_addr.s_addr
+		&& pvt1->addr.sin_port == pvt2->addr.sin_port
+		&& pvt1->peercallno == pvt2->peercallno)
+		return CMP_MATCH;
+	else 
+		return 0;
+}
+
+/*!
+ * \note The only members of the pvt passed here guaranteed to be set are the addr and callno fields
+ */
+static int findcall2_hash_cb(const void *obj, const int flags)
+{
+	const struct chan_iax2_pvt *pvt = obj;
+	int x = pvt->addr.sin_addr.s_addr + pvt->addr.sin_port + pvt->callno;
+	if (x<0)
+		x = -x;
+	
+	return x;
+}
+
+/*!
+ * \note The only members of the pvt passed here guaranteed to be set are the addr and callno fields
+ */
+static int findcall2_cmp_cb(void *obj, void *arg, int flags)
+{
+	const struct chan_iax2_pvt *pvt1 = obj;
+	const struct chan_iax2_pvt *pvt2 = arg;
+
+	if (pvt1->addr.sin_addr.s_addr == pvt2->addr.sin_addr.s_addr
+		&& pvt1->addr.sin_port == pvt2->addr.sin_port
+		&& pvt1->callno == pvt2->callno)
+		return CMP_MATCH;
+	else 
+		return 0;
+}
+
+/*!
+ * \note The only members of the pvt passed here guaranteed to be set are the transfer and callno fields
+ */
+static int findcall3_hash_cb(const void *obj, const int flags)
+{
+	const struct chan_iax2_pvt *pvt = obj;
+	int x = pvt->transfer.sin_addr.s_addr + pvt->transfer.sin_port + pvt->callno;
+	if (x<0)
+		x = -x;
+	
+	return x;
+}
+
+/*!
+ * \note The only members of the pvt passed here guaranteed to be set are the transfer and transfercallno fields
+ */
+static int findcall3_cmp_cb(void *obj, void *arg, int flags)
+{
+	const struct chan_iax2_pvt *pvt1 = obj;
+	const struct chan_iax2_pvt *pvt2 = arg;
+
+	if (pvt1->transfer.sin_addr.s_addr == pvt2->transfer.sin_addr.s_addr
+		&& pvt1->transfer.sin_port == pvt2->transfer.sin_port
+		&& pvt1->callno == pvt2->callno)
+		return CMP_MATCH;
+	else 
+		return 0;
+}
+
+/*!
+ * \note The only members of the pvt passed here guaranteed to be set are the addr and peercallno fields
+ */
+static int findcall4_hash_cb(const void *obj, const int flags)
+{
+	const struct chan_iax2_pvt *pvt = obj;
+	int x = pvt->transfer.sin_addr.s_addr + pvt->transfer.sin_port + pvt->transfercallno;
+	if (x<0)
+		x = -x;
+	
+	return x;
+}
+
+/*!
+ * \note The only members of the pvt passed here guaranteed to be set are the addr and peercallno fields
+ */
+static int findcall4_cmp_cb(void *obj, void *arg, int flags)
+{
+	const struct chan_iax2_pvt *pvt1 = obj;
+	const struct chan_iax2_pvt *pvt2 = arg;
+
+	if (pvt1->transfer.sin_addr.s_addr == pvt2->transfer.sin_addr.s_addr
+		&& pvt1->transfer.sin_port == pvt2->transfer.sin_port
+		&& pvt1->transfercallno == pvt2->transfercallno)
+		return CMP_MATCH;
+	else 
+		return 0;
 }
 
 /*!
@@ -11613,6 +11751,36 @@
 		ao2_ref(peers, -1);
 		return AST_MODULE_LOAD_FAILURE;
 	}
+	findcall1 = ao2_container_alloc(MAX_FINDCALL1_BUCKETS, findcall1_hash_cb, findcall1_cmp_cb);
+	if (!findcall1) {
+		ao2_ref(peers, -1);
+		ao2_ref(users, -1);
+		return AST_MODULE_LOAD_FAILURE;
+	}
+	findcall2 = ao2_container_alloc(MAX_FINDCALL2_BUCKETS, findcall2_hash_cb, findcall2_cmp_cb);
+	if (!findcall1) {
+		ao2_ref(peers, -1);
+		ao2_ref(users, -1);
+		ao2_ref(findcall1, -1);
+		return AST_MODULE_LOAD_FAILURE;
+	}
+	findcall3 = ao2_container_alloc(MAX_FINDCALL3_BUCKETS, findcall3_hash_cb, findcall3_cmp_cb);
+	if (!findcall1) {
+		ao2_ref(peers, -1);
+		ao2_ref(users, -1);
+		ao2_ref(findcall1, -1);
+		ao2_ref(findcall2, -1);
+		return AST_MODULE_LOAD_FAILURE;
+	}
+	findcall4 = ao2_container_alloc(MAX_FINDCALL4_BUCKETS, findcall4_hash_cb, findcall4_cmp_cb);
+	if (!findcall1) {
+		ao2_ref(peers, -1);
+		ao2_ref(users, -1);
+		ao2_ref(findcall1, -1);
+		ao2_ref(findcall2, -1);
+		ao2_ref(findcall3, -1);
+		return AST_MODULE_LOAD_FAILURE;
+	}
 
 	ast_custom_function_register(&iaxpeer_function);
 	ast_custom_function_register(&iaxvar_function);




More information about the asterisk-commits mailing list