[asterisk-commits] akshayb: branch akshayb/ao2_containers r278481 - /team/akshayb/ao2_containers...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 21 11:20:35 CDT 2010


Author: akshayb
Date: Wed Jul 21 11:20:29 2010
New Revision: 278481

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=278481
Log:
shifting;

Modified:
    team/akshayb/ao2_containers/main/astobj2.c
    team/akshayb/ao2_containers/main/astobj2_btree.c
    team/akshayb/ao2_containers/main/astobj2_hash.c

Modified: team/akshayb/ao2_containers/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers/main/astobj2.c?view=diff&rev=278481&r1=278480&r2=278481
==============================================================================
--- team/akshayb/ao2_containers/main/astobj2.c (original)
+++ team/akshayb/ao2_containers/main/astobj2.c Wed Jul 21 11:20:29 2010
@@ -25,6 +25,19 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/utils.h"
 #include "asterisk/cli.h"
+
+/*
+ * Condition to decide what data type of variable is the container is
+ */
+
+#ifdef BTREE
+#include "asterisk/astobj2_btree.h"
+#define 
+#else
+#include "asterisk/astobj2_hash.h"
+struct ao2_container *c, const unsigned int n_buckets, ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn, ao2_link_fn *link_fn, ao2_unlink_fn *unlink_fn
+
+
 #define REF_FILE "/tmp/refs"
 
 /*!
@@ -391,35 +404,6 @@
 };
 
 
-	
-//Left Old code for reference. Has to be removed once work done
-
-/*
-struct ao2_container {
-	ao2_hash_fn *hash_fn;
-	ao2_callback_fn *cmp_fn;
-	int n_buckets;
-	int elements;
-	int version;
-	struct bucket buckets[0];
-};
-
-*/
- 
-/*!
- * \brief always zero hash function
- *
- * it is convenient to have a hash function that always returns 0.
- * This is basically used when we want to have a container that is
- * a simple linked list.
- *
- * returns 0
- */
-//hash_zero goes to var
-static int hash_zero(const void *user_obj, const int flags)
-{
-	return 0;
-}
 
 /*
  * Constructor definition to initialize ao2_container. Care Has to be taken 

Modified: team/akshayb/ao2_containers/main/astobj2_btree.c
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers/main/astobj2_btree.c?view=diff&rev=278481&r1=278480&r2=278481
==============================================================================
--- team/akshayb/ao2_containers/main/astobj2_btree.c (original)
+++ team/akshayb/ao2_containers/main/astobj2_btree.c Wed Jul 21 11:20:29 2010
@@ -316,4 +316,127 @@
 
 	for (; a->bucket < lim; a->bucket++, a->version = 0) {
 		/* scan the current bucket */
-		AST_BTREE_TRAVERSE(_
+		AST_BTREE_TRAVERSE(********){
+			if (p->version > a->version)
+				goto found;
+		}
+	}
+
+found:
+	if (p) {
+		ret = EXTERNAL_OBJ(p->astobj);
+		if (a->flags & AO2_ITERATOR_UNLINK) {
+			/* we are going to modify the container, so update version */
+			ast_atomic_fetchadd_int(&a->c->core.version, 1);
+			//Add the delete function here
+			ast_atomic_fetchadd_int(&a->c->elements, -1);
+			a->version = 0;
+			a->obj = NULL;
+			a->c_version = a->c->core.version;
+			ast_free(p);
+		} else {
+			a->version = p->version;
+			a->obj = p;
+			a->c_version = a->c->version;
+			/* inc refcount of returned object */
+			*q = p;
+		}
+	}
+		
+		return ret;
+}
+
+
+void *__ao2_iterator_next_debug(struct ao2_iterator *a, char *tag, char *file, int line, const char *funcname)
+{
+	struct bucket_entry *p;
+	void *ret = NULL;
+
+	ret = internal_ao2_iterator_next(a, &p);
+	
+	if (p) {
+		/* inc refcount of returned object */
+		__ao2_ref_debug(ret, 1, tag, file, line, funcname);
+	}
+
+	if (!(a->flags & AO2_ITERATOR_DONTLOCK))
+		ao2_unlock(a->c);
+
+	return ret;
+}
+
+void *__ao2_iterator_next(struct ao2_iterator *a)
+{
+	struct bucket_entry *p = NULL;
+	void *ret = NULL;
+
+	ret = internal_ao2_iterator_next(a, &p);
+	
+	if (p) {
+		/* inc refcount of returned object */
+		__ao2_ref(ret, 1);
+	}
+
+	if (!(a->flags & AO2_ITERATOR_DONTLOCK))
+		ao2_unlock(a->c);
+
+	return ret;
+}
+
+/* callback for destroying container.
+ * we can make it simple as we know what it does
+ */
+static int cd_cb(void *obj, void *arg, int flag)
+{
+	__ao2_ref(obj, -1);
+	return 0;
+}
+	
+static int cd_cb_debug(void *obj, void *arg, int flag)
+{
+	__ao2_ref_debug(obj, -1, "deref object via container destroy",  __FILE__, __LINE__, __PRETTY_FUNCTION__);
+	return 0;
+}
+	
+static void container_destruct(void *_c)
+{
+	struct ao2_container *c = _c;
+	int i;
+
+	__ao2_callback(c, OBJ_UNLINK, cd_cb, NULL);
+
+	for (i = 0; i < c->n_buckets; i++) {
+		struct bucket_entry *current;
+
+		while ((current = AST_LIST_REMOVE_HEAD(&c->buckets[i], entry))) {
+			ast_free(current);
+		}
+	}
+
+#ifdef AO2_DEBUG
+	ast_atomic_fetchadd_int(&ao2.total_containers, -1);
+#endif
+}
+
+static void container_destruct_debug(void *_c)
+{
+	struct ao2_container *c = _c;
+	int i;
+
+	__ao2_callback_debug(c, OBJ_UNLINK, cd_cb_debug, NULL, "container_destruct_debug called", __FILE__, __LINE__, __PRETTY_FUNCTION__);
+
+	for (i = 0; i < c->n_buckets; i++) {
+		struct bucket_entry *current;
+
+		while ((current = AST_LIST_REMOVE_HEAD(&c->buckets[i], entry))) {
+			ast_free(current);
+		}
+	}
+
+#ifdef AO2_DEBUG
+	ast_atomic_fetchadd_int(&ao2.total_containers, -1);
+#endif
+}
+
+
+

Modified: team/akshayb/ao2_containers/main/astobj2_hash.c
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers/main/astobj2_hash.c?view=diff&rev=278481&r1=278480&r2=278481
==============================================================================
--- team/akshayb/ao2_containers/main/astobj2_hash.c (original)
+++ team/akshayb/ao2_containers/main/astobj2_hash.c Wed Jul 21 11:20:29 2010
@@ -6,6 +6,19 @@
 	ao2_unlink_fn *unlink_fn;
 	sturct btree *btree;
 	};
+/*!
+ * \brief always zero hash function
+ *
+ * it is convenient to have a hash function that always returns 0.
+ * This is basically used when we want to have a container that is
+ * a simple linked list.
+ *
+ * returns 0
+ */
+static int hash_zero(const void *user_obj, const int flags)
+{
+	return 0;
+}
 
 void internal_ao2_container_var_alloc(ao2_hash_fn *hash_fn, const unsigned int n_buckets)
 {




More information about the asterisk-commits mailing list