[asterisk-commits] russell: trunk r82282 - /trunk/utils/hashtest2.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 12 10:53:41 CDT 2007


Author: russell
Date: Wed Sep 12 10:53:40 2007
New Revision: 82282

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82282
Log:
Change the traversal to use ao2_callback() instead of an ao2_iterator.  Using
ao2_callback() is a much more efficient way of performing an operation on every
item in the container.  This change makes hashtest2 run in about 25% of the
time it ran before on my system.

In general, I would say that it makes the most sense to use an ao2_iterator if
the operation being performed is going to take a long time and you don't want
to keep the container locked while you work with each object.  Otherwise,
the use of ao2_callback is preferred.

Modified:
    trunk/utils/hashtest2.c

Modified: trunk/utils/hashtest2.c
URL: http://svn.digium.com/view/asterisk/trunk/utils/hashtest2.c?view=diff&rev=82282&r1=82281&r2=82282
==============================================================================
--- trunk/utils/hashtest2.c (original)
+++ trunk/utils/hashtest2.c Wed Sep 12 10:53:40 2007
@@ -148,16 +148,17 @@
 	els_added++; /* unprotected, sometimes off, but, not really important, either */
 }
 
+static int do_nothing_cb(void *obj, void *arg, int flags)
+{
+	return 0;
+}
+
 static void traverse_elements(void)
 {
-	struct ht_element *el;
-	struct ao2_iterator it = ao2_iterator_init(glob_hashtab, 0);
 #ifdef DEBUG
 	printf("Traverse hashtab\n");
 #endif
-	while ((el = ao2_iterator_next(&it))) {
-		ao2_ref(el,-1);
-	}
+	ao2_callback(glob_hashtab, OBJ_NODATA, do_nothing_cb, NULL);
 	els_traversals++; /* unprotected, sometimes off, but, not really important, either */
 }
 




More information about the asterisk-commits mailing list