[asterisk-commits] akshayb: branch akshayb/ao2_containers r265520 - in /team/akshayb/ao2_contain...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 24 18:45:48 CDT 2010


Author: akshayb
Date: Mon May 24 18:45:46 2010
New Revision: 265520

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=265520
Log: (empty)

Added:
    team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h   (with props)
    team/akshayb/ao2_containers/main/astobj2_hash.c   (with props)
Modified:
    team/akshayb/ao2_containers/include/asterisk/astobj2.h
    team/akshayb/ao2_containers/main/astobj2.c

Modified: team/akshayb/ao2_containers/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers/include/asterisk/astobj2.h?view=diff&rev=265520&r1=265519&r2=265520
==============================================================================
--- team/akshayb/ao2_containers/include/asterisk/astobj2.h (original)
+++ team/akshayb/ao2_containers/include/asterisk/astobj2.h Mon May 24 18:45:46 2010
@@ -682,20 +682,6 @@
  */
 typedef int (ao2_hash_fn)(const void *obj, const int flags);
 
-/*! 
- * ao2_link_fn is function in variable part of ao2_container. ao2_link_fn can 
- * for different type of container based on its data structure.
- */
-
-typedef void *(ao2_link_fn)(ao2_container *c, void *userdata);
-
-/*!
- * ao2_unlink_fn is function in variable part of ao2_container. ao2_unlink_fn 
- * can be used to remove a object from the container.
- */
-
-typedef void *(ao2_unlink_fn)(ao2_container *c, void *userdata);
-
 /*! \name Object Containers
  * Here start declarations of containers.
  */
@@ -718,6 +704,22 @@
  * destructor is set implicitly.
  */
 
+/*! 
+ * ao2_link_fn is function in variable part of ao2_container. ao2_link_fn can 
+ * for different type of container based on its data structure.
+ */
+
+typedef void* (ao2_link_fn)(struct ao2_container *c, void *userdata);
+
+/*!
+ * ao2_unlink_fn is function in variable part of ao2_container. ao2_unlink_fn 
+ * can be used to remove a object from the container.
+ */
+
+typedef void *(ao2_unlink_fn)(struct ao2_container *c, void *userdata);
+
+
+
 #if defined(REF_DEBUG)
 
 #define ao2_t_container_alloc(arg1,arg2,arg3,arg4) __ao2_container_alloc_debug((arg1), (arg2), (arg3), (arg4),  __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
@@ -732,6 +734,7 @@
 
 #define ao2_t_container_alloc(arg1,arg2,arg3,arg4) __ao2_container_alloc((arg1), (arg2), (arg3))
 #define ao2_container_alloc(arg1,arg2,arg3)        __ao2_container_alloc((arg1), (arg2), (arg3))
+
 
 #endif
 

Added: team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h?view=auto&rev=265520
==============================================================================
--- team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h (added)
+++ team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h Mon May 24 18:45:46 2010
@@ -1,0 +1,1 @@
+void internal_ao2_container_var_alloc(ao2_hash_fn *hash_fn, const unsigned int n_buckets);

Propchange: team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h
------------------------------------------------------------------------------
    svn:keywords = Akshay Bhardwaj 25/05/2010

Propchange: team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=265520&r1=265519&r2=265520
==============================================================================
--- team/akshayb/ao2_containers/main/astobj2.c (original)
+++ team/akshayb/ao2_containers/main/astobj2.c Mon May 24 18:45:46 2010
@@ -350,6 +350,9 @@
 /* each bucket in the container is a tailq. */
 AST_LIST_HEAD_NOLOCK(bucket, bucket_entry);
 
+
+/* ------------------------------------------ Changes Start from here --------------------------------------------- */
+/* Above part will not change */
 /*!
  * A container; stores the hash and callback functions, information on
  * the size, the hash bucket heads, and a version number, starting at 0
@@ -375,25 +378,25 @@
 
 struct ao2_container_core {
 	ao2_callback_fn *cmp_fn;
+	ao2_link_fn *link_fn;
+	ao2_unlink_fn *unlink_fn;
 	/*! Number of elements in the container */
 	int elements;
 	/*! described above */
 	int version;
 };
 
-	
-
-struct ao2_container {
-	ao2_contaniner_core core;
+struct ao2_container_var {
 	ao2_hash_fn *hash_fn;
-	ao2_link_fn *link_fn;
-	ao2_unlink_fn *unlink_fn;
 	int n_buckets;
 	/*! variable size */
 	struct bucket buckets[0];
 };
 
-
+struct ao2_container {
+	ao2_container_core core;
+	ao2_container_var var;
+};
 
 
 	
@@ -434,13 +437,14 @@
 {
 	if (!c)
 		return NULL;
-	
+/* This too can be grouped in a alloc function. But that is un-necessary and would be done later */	
 	c->core.version = 1; /* 0 is a reserved value here */
-	c->n_buckets = hash_fn ? n_buckets : 1;
-	c->hash_fn = hash_fn ? hash_fn : hash_zero;
-	c->core->cmp_fn = cmp_fn;
-	c->link_fn = link_fn;
-	c->unlink_fn = unlink_fn;
+	c->core.cmp_fn = cmp_fn;
+	c->core.link_fn = link_fn;
+	c->core.unlink_fn = unlink_fn;
+/* This can be put in separate allocation function for varialbe an core part. We can just leave core part here and and constructor for variable part,in astobj2_hash.c */
+
+	internal_ao2_container_var_alloc(c, hash_fn, n_buckets);
 
 #ifdef AO2_DEBUG
 	ast_atomic_fetchadd_int(&ao2.total_containers, 1);
@@ -454,13 +458,11 @@
  * allocated by using __ao2_alloc_debug and __ao2_alloc
  */
 
-size_t ao2_container_size (
-
-
-
-struct ao2_container *__ao2_container_alloc_debug(const unsigned int n_buckets, ao2_hash_fn *hash_fn,
-						  ao2_callback_fn *cmp_fn, char *tag, char *file, int line,
-						  const char *funcname, int ref_debug)
+
+
+
+struct ao2_container *__ao2_container_alloc_debug(const unsigned int n_buckets, ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn, 
+			char *tag, char *file, int line, const char *funcname, int ref_debug)
 {
 	/* XXX maybe consistency check on arguments ? */
 	/* compute the container size */
@@ -468,11 +470,10 @@
 	size_t container_size = sizeof(struct ao2_container) + num_buckets * sizeof(struct bucket);
 	struct ao2_container *c = __ao2_alloc_debug(container_size, container_destruct_debug, tag, file, line, funcname, ref_debug);
 
-	return internal_ao2_container_alloc(c, num_buckets, hash_fn, cmp_fn);
-}
-
-struct ao2_container *__ao2_container_alloc(const unsigned int n_buckets, ao2_hash_fn *hash_fn,
-					    ao2_callback_fn *cmp_fn)
+	return internal_ao2_container_alloc(c, num_buckets, hash_fn, cmp_fn, link_fn, unlink_fn);
+}
+
+struct ao2_container *__ao2_container_alloc(const unsigned int n_buckets, ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn)
 {
 	/* XXX maybe consistency check on arguments ? */
 	/* compute the container size */
@@ -482,7 +483,7 @@
 	size_t container_size = sizeof(struct ao2_container) + num_buckets * sizeof(struct bucket);
 	struct ao2_container *c = __ao2_alloc(container_size, container_destruct);
 
-	return internal_ao2_container_alloc(c, num_buckets, hash_fn, cmp_fn);
+	return internal_ao2_container_alloc(c, num_buckets, hash_fn, cmp_fn, link_fn, unlink_fn);
 }
 
 /*!

Added: team/akshayb/ao2_containers/main/astobj2_hash.c
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers/main/astobj2_hash.c?view=auto&rev=265520
==============================================================================
--- team/akshayb/ao2_containers/main/astobj2_hash.c (added)
+++ team/akshayb/ao2_containers/main/astobj2_hash.c Mon May 24 18:45:46 2010
@@ -1,0 +1,8 @@
+#include "asterisk/astobj2.h"
+#include "asterisk/astobj2_hash.h"
+
+void internal_ao2_container_var_alloc(ao2_hash_fn *hash_fn, const unsigned int n_buckets)
+{
+	c->var.hash_fn = hash_fn;
+	c->var.n_buckets = n_buckets;
+}

Propchange: team/akshayb/ao2_containers/main/astobj2_hash.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/akshayb/ao2_containers/main/astobj2_hash.c
------------------------------------------------------------------------------
    svn:keywords = Akshay Bhardwaj 25/05/2010

Propchange: team/akshayb/ao2_containers/main/astobj2_hash.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list