[asterisk-commits] mmichelson: branch mmichelson/ao2_containers r141019 - /team/mmichelson/ao2_c...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 3 19:42:09 CDT 2008


Author: mmichelson
Date: Wed Sep  3 19:42:09 2008
New Revision: 141019

URL: http://svn.digium.com/view/asterisk?view=rev&rev=141019
Log:
Progress towards iterator code. The implementation
for astobj2_linkedlist is a bit ugly since nearly
the exact same code is duplicated twice.

The implementation for astobj2_skiplist needs work.
I tried to take the approach of using what the
ao2_iterator structure had to offer without having
to add private data (since most containers really
don't need to store any extra data in the iterator).
It appears, though, that the "version" method of
finding the next item when iterating will not
work with skiplists since items are added to the
list in any order.


Modified:
    team/mmichelson/ao2_containers/main/astobj2_hashtable.c
    team/mmichelson/ao2_containers/main/astobj2_linkedlist.c
    team/mmichelson/ao2_containers/main/astobj2_skiplist.c

Modified: team/mmichelson/ao2_containers/main/astobj2_hashtable.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/ao2_containers/main/astobj2_hashtable.c?view=diff&rev=141019&r1=141018&r2=141019
==============================================================================
--- team/mmichelson/ao2_containers/main/astobj2_hashtable.c (original)
+++ team/mmichelson/ao2_containers/main/astobj2_hashtable.c Wed Sep  3 19:42:09 2008
@@ -78,7 +78,7 @@
 	}
 
 	if (!(hash_pvt = ast_calloc(1, sizeof (*hash_pvt) + (n_buckets * sizeof(struct bucket))))) {
-		ao2_ref(c, -1);
+		ao2_ref(hashtable, -1);
 		return NULL;
 	}
 

Modified: team/mmichelson/ao2_containers/main/astobj2_linkedlist.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/ao2_containers/main/astobj2_linkedlist.c?view=diff&rev=141019&r1=141018&r2=141019
==============================================================================
--- team/mmichelson/ao2_containers/main/astobj2_linkedlist.c (original)
+++ team/mmichelson/ao2_containers/main/astobj2_linkedlist.c Wed Sep  3 19:42:09 2008
@@ -22,20 +22,21 @@
 static void *linkedlist_link_back(struct ao2_container *c, struct astobj2 *newobj);
 static void *linkedlist_link_front(struct ao2_container *c, struct astobj2 *newobj);
 static void *linkedlist_callback(struct ao2_container *c, enum search_flags flags, ao2_callback_fn *cb_fn, void *arg);
-static void *linkedlist_iterator_next(struct ao2_iterator *a);
+static void *linkedlist_iterator_next_back(struct ao2_iterator *a);
+static void *linkedlist_iterator_next_front(struct ao2_iterator *a);
 static void linkedlist_destroy(struct ao2_container *c);
 
 static const struct ao2_container_impl linkedlist_back_impl = {
 	.link = linkedlist_link_back,
 	.callback = linkedlist_callback,
-	.iterator_next = linkedlist_iterator_next,
+	.iterator_next = linkedlist_iterator_next_back,
 	.destroy = linkedlist_destroy,
 };
 
 static const struct ao2_container_impl linkedlist_front_impl = {
 	.link = linkedlist_link_front,
 	.callback = linkedlist_callback,
-	.iterator_next = linkedlist_iterator_next,
+	.iterator_next = linkedlist_iterator_next_front,
 	.destroy = linkedlist_destroy,
 };
 
@@ -153,17 +154,63 @@
 	return ret;
 }
 
-/*XXX This is my stopping point for the day. What I need to do is
- * to adjust the ao2_iterator strucure to take a private data pointer
- * like the ao2_container class does. Then the linked list iterator
- * can keep a pointer either to the next item in the list or the current
- * one. Whichever. This is a stub until that change can be made
- */
-static void *linkedlist_iterator_next(struct ao2_iterator *a)
-{
-	return NULL;
-}
-
+static void *linkedlist_iterator_next_back(struct ao2_iterator *a)
+{
+	struct the_list *list = a->c->private;
+	struct list_item *item;
+	void* ret = NULL;
+
+	if (a->c->version == a->c_version && (item = a->obj)) {
+		if ((item = AST_LIST_NEXT(item, entry))) {
+			goto found;
+		}
+		a->obj = NULL;
+	}
+
+	AST_LIST_TRAVERSE(list, item, entry) {
+		if (item->version > a->version)
+			goto found;
+	}
+
+found:
+	if (item) {
+		a->version = item->version;
+		a->obj = item;
+		a->c_version = a->c->version;
+		ret = item->astobj;
+	}
+
+	return ret;
+}
+
+static void *linkedlist_iterator_next_front(struct ao2_iterator *a)
+{
+	struct the_list *list = a->c->private;
+	struct list_item *item;
+	void* ret = NULL;
+
+	if (a->c->version == a->c_version && (item = a->obj)) {
+		if ((item = AST_LIST_NEXT(item, entry))) {
+			goto found;
+		}
+		a->obj = NULL;
+	}
+
+	AST_LIST_TRAVERSE(list, item, entry) {
+		if (item->version < a->version)
+			goto found;
+	}
+
+found:
+	if (item) {
+		a->version = item->version;
+		a->obj = item;
+		a->c_version = a->c->version;
+		ret = item->astobj;
+	}
+
+	return ret;
+}
 static void linkedlist_destroy(struct ao2_container *c)
 {
 	struct the_list *list = c->private;

Modified: team/mmichelson/ao2_containers/main/astobj2_skiplist.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/ao2_containers/main/astobj2_skiplist.c?view=diff&rev=141019&r1=141018&r2=141019
==============================================================================
--- team/mmichelson/ao2_containers/main/astobj2_skiplist.c (original)
+++ team/mmichelson/ao2_containers/main/astobj2_skiplist.c Wed Sep  3 19:42:09 2008
@@ -189,6 +189,23 @@
 /* Complete this once iterator stuff is accomplished */
 static void *skiplist_iterator_next(struct ao2_iterator *a)
 {
+	struct skiplist_pvt *skip_pvt = a->c->private;
+	struct list_item *item;
+	void *ret = NULL;
+	int i;
+
+	if (a->c->version == a->c_version && (item = a->obj)) {
+		if ((item = AST_LIST_NEXT(item, entry[0]))) {
+			goto found;
+		}
+		a->obj = NULL;
+	}
+
+	/* XXX We couldn't do things the quick way, so we need to
+	 * find our spot the not-so-quick way. Need to think this
+	 * out, since the "version" method that other iterators
+	 * use won't work.
+	 */
 	return NULL;
 }
 




More information about the asterisk-commits mailing list