[asterisk-commits] mmichelson: branch mmichelson/ao2_containers r140408 - in /team/mmichelson/ao...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 28 18:50:32 CDT 2008


Author: mmichelson
Date: Thu Aug 28 18:50:31 2008
New Revision: 140408

URL: http://svn.digium.com/view/asterisk?view=rev&rev=140408
Log:
Adding the astobj2_linkedlist implementation.
That wasy easy..........
...........oh wait, the iterators need to be
changed so they will work with multiple container
types, too. >_<

I knew this was coming but had forgotten that I
had put it off when writing the hashtable implementation.

Now I know what's next on the agenda. Do what I did
with ao2_containers to ao2_iterators.


Added:
    team/mmichelson/ao2_containers/main/astobj2_linkedlist.c   (with props)
Modified:
    team/mmichelson/ao2_containers/include/asterisk/astobj2.h
    team/mmichelson/ao2_containers/include/asterisk/astobj2_private.h
    team/mmichelson/ao2_containers/main/Makefile
    team/mmichelson/ao2_containers/main/astobj2_hashtable.c

Modified: team/mmichelson/ao2_containers/include/asterisk/astobj2.h
URL: http://svn.digium.com/view/asterisk/team/mmichelson/ao2_containers/include/asterisk/astobj2.h?view=diff&rev=140408&r1=140407&r2=140408
==============================================================================
--- team/mmichelson/ao2_containers/include/asterisk/astobj2.h (original)
+++ team/mmichelson/ao2_containers/include/asterisk/astobj2.h Thu Aug 28 18:50:31 2008
@@ -677,6 +677,9 @@
  */
 struct ao2_container *ao2_hashtable_alloc(const uint n_buckets,
 										  ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn);
+
+struct ao2_container *ao2_linkedlist_alloc_front(ao2_callback_fn *cmp_fn);
+struct ao2_container *ao2_linkedlist_alloc_back(ao2_callback_fn *cmp_fn);
 
 /*! \brief
  * Returns the number of elements in a container.

Modified: team/mmichelson/ao2_containers/include/asterisk/astobj2_private.h
URL: http://svn.digium.com/view/asterisk/team/mmichelson/ao2_containers/include/asterisk/astobj2_private.h?view=diff&rev=140408&r1=140407&r2=140408
==============================================================================
--- team/mmichelson/ao2_containers/include/asterisk/astobj2_private.h (original)
+++ team/mmichelson/ao2_containers/include/asterisk/astobj2_private.h Thu Aug 28 18:50:31 2008
@@ -2,6 +2,7 @@
 #define ASTOBJ2_PRIVATE_H
 
 #include "asterisk.h"
+#include "asterisk/astobj2.h"
 #include "asterisk/lock.h"
 
 /*!

Modified: team/mmichelson/ao2_containers/main/Makefile
URL: http://svn.digium.com/view/asterisk/team/mmichelson/ao2_containers/main/Makefile?view=diff&rev=140408&r1=140407&r2=140408
==============================================================================
--- team/mmichelson/ao2_containers/main/Makefile (original)
+++ team/mmichelson/ao2_containers/main/Makefile Thu Aug 28 18:50:31 2008
@@ -27,8 +27,9 @@
 	netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
 	cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \
 	strcompat.o threadstorage.o dial.o event.o adsistub.o audiohook.o \
-	astobj2.o astobj2_hashtable.o hashtab.o global_datastores.o version.o \
-	features.o taskprocessor.o timing.o datastore.o
+	astobj2.o astobj2_hashtable.o astobj2_linkedlist.o hashtab.o \
+	global_datastores.o version.o features.o taskprocessor.o timing.o \
+	datastore.o
 
 # we need to link in the objects statically, not as a library, because
 # otherwise modules will not have them available if none of the static

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=140408&r1=140407&r2=140408
==============================================================================
--- team/mmichelson/ao2_containers/main/astobj2_hashtable.c (original)
+++ team/mmichelson/ao2_containers/main/astobj2_hashtable.c Thu Aug 28 18:50:31 2008
@@ -185,7 +185,7 @@
 	return ret;
 }
 
-void *hashtable_iterator_next(struct ao2_iterator *a)
+static void *hashtable_iterator_next(struct ao2_iterator *a)
 {
 	int lim;
 	struct bucket_list *p = NULL;
@@ -231,7 +231,7 @@
 	return ret;
 }
 
-void hashtable_destroy(struct ao2_container *c)
+static void hashtable_destroy(struct ao2_container *c)
 {
 	struct hashtable_pvt *hash_pvt = c->private;
 	int i;

Added: team/mmichelson/ao2_containers/main/astobj2_linkedlist.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/ao2_containers/main/astobj2_linkedlist.c?view=auto&rev=140408
==============================================================================
--- team/mmichelson/ao2_containers/main/astobj2_linkedlist.c (added)
+++ team/mmichelson/ao2_containers/main/astobj2_linkedlist.c Thu Aug 28 18:50:31 2008
@@ -1,0 +1,167 @@
+/*
+ * astobj2 - replacement containers for asterisk data structures.
+ *
+ * Copyright (C) 2006 Marta Carbone, Luigi Rizzo - Univ. di Pisa, Italy
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#include "asterisk.h"
+#include "asterisk/astobj2_private.h"
+#include "asterisk/linkedlists.h"
+#include "asterisk/utils.h"
+
+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_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,
+	.destroy = linkedlist_destroy,
+};
+
+static const struct ao2_container_impl linkedlist_front_impl = {
+	.link = linkedlist_link_front,
+	.callback = linkedlist_callback,
+	.iterator_next = linkedlist_iterator_next,
+	.destroy = linkedlist_destroy,
+};
+
+AST_LIST_HEAD_NOLOCK(the_list, list_item);
+
+struct list_item {
+	AST_LIST_ENTRY(list_item) entry;
+	int version;
+	struct astobj2 *astobj;
+};
+
+struct ao2_container *ao2_linkedlist_alloc_back(ao2_callback_fn *cmp_fn)
+{
+	struct ao2_container *list = ao2_container_common_alloc(cmp_fn, &linkedlist_back_impl);
+	struct the_list *new_list;
+
+	if (!list) {
+		return NULL;
+	}
+
+	if (!(new_list = ast_calloc(1, sizeof(*new_list)))) {
+		return NULL;
+	}
+
+	list->private = new_list;
+	return list;
+}
+
+struct ao2_container *ao2_linkedlist_alloc_front(ao2_callback_fn *cmp_fn)
+{
+	struct ao2_container *list = ao2_container_common_alloc(cmp_fn, &linkedlist_front_impl);
+	struct the_list *new_list;
+
+	if (!list) {
+		return NULL;
+	}
+
+	if (!(new_list = ast_calloc(1, sizeof(*new_list)))) {
+		return NULL;
+	}
+
+	list->private = new_list;
+	return list;
+}
+
+static void *linkedlist_link_back(struct ao2_container *c, struct astobj2 *newobj)
+{
+	struct list_item *item = ast_calloc(1, sizeof(*item));
+	struct the_list *list = c->private;
+
+	if (!item) {
+		return NULL;
+	}
+
+	AST_LIST_INSERT_TAIL(list, item, entry);
+	return item;
+}
+
+static void *linkedlist_link_front(struct ao2_container *c, struct astobj2 *newobj)
+{
+	struct list_item *item = ast_calloc(1, sizeof(*item));
+	struct the_list *list = c->private;
+
+	if (!item) {
+		return NULL;
+	}
+
+	AST_LIST_INSERT_HEAD(list, item, entry);
+	return item;
+}
+
+static void *linkedlist_callback(struct ao2_container *c, const enum search_flags flags, ao2_callback_fn *cb_fn, void *arg)
+{
+	struct the_list *list = c->private;
+	struct list_item *item;
+	void *ret = NULL;
+
+	AST_LIST_TRAVERSE_SAFE_BEGIN(list, item, entry) {
+		int match = cb_fn(EXTERNAL_OBJ(item->astobj), arg, flags) & (CMP_MATCH | CMP_STOP);
+
+		if (match == 0) {
+			continue;
+		} else if (match == CMP_STOP) {
+			break;
+		}
+
+		/* match is CMP_MATCH */
+		if (!(flags & OBJ_NODATA)) {
+			ao2_ref(EXTERNAL_OBJ(item->astobj), 1);
+			ret = item->astobj;
+		}
+
+		if (flags & OBJ_UNLINK) {
+			struct list_item *x = item;
+			ast_atomic_fetchadd_int(&c->version, 1);
+			AST_LIST_REMOVE_CURRENT(entry);
+			ast_atomic_fetchadd_int(&c->elements, -1);
+			ao2_ref(EXTERNAL_OBJ(x->astobj), -1);
+			free(x);
+		}
+
+		if ((match & CMP_STOP) || (flags & OBJ_MULTIPLE) == 0) {
+			break;
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+	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_destroy(struct ao2_container *c)
+{
+	struct the_list *list = c->private;
+	struct list_item *item;
+
+	while ((item = AST_LIST_REMOVE_HEAD(list, entry))) {
+		ast_free(item);
+	}
+}

Propchange: team/mmichelson/ao2_containers/main/astobj2_linkedlist.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mmichelson/ao2_containers/main/astobj2_linkedlist.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Propchange: team/mmichelson/ao2_containers/main/astobj2_linkedlist.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list