[asterisk-commits] akshayb: branch akshayb/ao2_containers r280981 - in /team/akshayb/ao2_contain...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Aug 4 21:21:33 CDT 2010
Author: akshayb
Date: Wed Aug 4 21:21:29 2010
New Revision: 280981
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=280981
Log:
Adding things
Modified:
team/akshayb/ao2_containers/include/asterisk/astobj2.h
team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h
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/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers/include/asterisk/astobj2.h?view=diff&rev=280981&r1=280980&r2=280981
==============================================================================
--- team/akshayb/ao2_containers/include/asterisk/astobj2.h (original)
+++ team/akshayb/ao2_containers/include/asterisk/astobj2.h Wed Aug 4 21:21:29 2010
@@ -19,6 +19,18 @@
#include "asterisk/compat.h"
#include "asterisk/linkedlists.h"
+// Specify which data structure to be used for ao2_container
+#define ASTOBJ2_HASH_H_ 1
+
+// Condition for BTREE
+#ifdef ASTOBJ2_BTREE_H_
+#include "asterisk/astobj2_btree.h"
+#endif
+
+// Condition for HASH
+#ifdef ASTOBJ2_HASH_H_
+#include "asterisk/astobj2_hash.h"
+#endif
/*! \file
* \ref AstObj2
@@ -680,7 +692,7 @@
* flags is ignored at the moment. Eventually, it will include the
* value of OBJ_POINTER passed to ao2_callback().
*/
-typedef int (ao2_hash_fn)(const void *obj, const int flags);
+//typedef int (ao2_hash_fn)(const void *obj, const int flags);
/*! \name Object Containers
* Here start declarations of containers.
@@ -709,14 +721,14 @@
* for different type of container based on its data structure.
*/
-typedef void* (ao2_link_fn)(struct ao2_container *c, void *userdata);
+//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);
+//typedef void *(ao2_unlink_fn)(struct ao2_container *c, void *userdata);
@@ -776,6 +788,7 @@
* \note This function automatically increases the reference count to account
* for the reference that the container now holds to the object.
*/
+/*
#ifdef REF_DEBUG
//Definition of ao2_link remains here.
@@ -791,7 +804,7 @@
void *__ao2_link_debug(struct ao2_container *c, void *new_obj, char *tag, char *file, int line, const char *funcname);
void *__ao2_link(struct ao2_container *c, void *newobj);
-
+*/
/*!
* \brief Remove an object from a container
*
@@ -808,6 +821,7 @@
* reference to the object will be automatically released. (The
* refcount will be decremented).
*/
+/*
#ifdef REF_DEBUG
#define ao2_t_unlink(arg1, arg2, arg3) __ao2_unlink_debug((arg1), (arg2), (arg3), __FILE__, __LINE__, __PRETTY_FUNCTION__)
@@ -822,6 +836,7 @@
void *__ao2_unlink_debug(struct ao2_container *c, void *obj, char *tag, char *file, int line, const char *funcname);
void *__ao2_unlink(struct ao2_container *c, void *obj);
+*/
/*@} */
Modified: 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=diff&rev=280981&r1=280980&r2=280981
==============================================================================
--- team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h (original)
+++ team/akshayb/ao2_containers/include/asterisk/astobj2_hash.h Wed Aug 4 21:21:29 2010
@@ -1,13 +1,144 @@
+/*
+ * astobj2_hash.h
+ *
+ * Created on: 2 August 2010
+ * Author: Akshay Bhardwaj
+*/
-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];
- };
+
+// Definition of variable part of ao2_container. This is data member of ao2_container
+struct ao2_container;
+struct ao2_container_var;
//void internal_ao2_container_var_alloc(ao2_hash_fn *hash_fn, const unsigned int n_buckets);
-void internal_ao2_container_var_alloc(ao2_hash_fn *hash_fn, const unsigned int n_buckets, ao2_link_fn *link_fn, ao2_unlink_fn *unlink_fn);
+//void internal_ao2_container_var_alloc(ao2_hash_fn *hash_fn, const unsigned int n_buckets, ao2_link_fn *link_fn, ao2_unlink_fn *unlink_fn);
+
+
+//Function to return the container size for the particular data structure
+size_t get_container_size(int num_buckets);
+
+/*!
+ * Type of a generic function to generate a hash value from an object.
+ * flags is ignored at the moment. Eventually, it will include the
+ * value of OBJ_POINTER passed to ao2_callback().
+ */
+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)(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);
+
+//Decide location for ao2_container_alloc part
+/*
+#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)
+#define ao2_container_alloc(arg1,arg2,arg3) __ao2_container_alloc_debug((arg1), (arg2), (arg3), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
+
+#elif defined(__AST_DEBUG_MALLOC)
+
+#define ao2_t_container_alloc(arg1,arg2,arg3,arg4) __ao2_container_alloc_debug((arg1), (arg2), (arg3), (arg4), __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
+#define ao2_container_alloc(arg1,arg2,arg3) __ao2_container_alloc_debug((arg1), (arg2), (arg3), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
+
+#else
+
+#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
+
+struct ao2_container *__ao2_container_alloc(const unsigned int n_buckets,
+ ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn);
+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);
+*/
+/*! \name Object Management
+ * Here we have functions to manage objects.
+ *
+ * We can use the functions below on any kind of
+ * object defined by the user.
+ */
+/*@{ */
+
+/*!
+ * \brief Add an object to a container.
+ *
+ * \param c the container to operate on.
+ * \param newobj the object to be added.
+ *
+ * \retval NULL on errors
+ * \retval newobj on success.
+ *
+ * This function inserts an object in a container according its key.
+ *
+ * \note Remember to set the key before calling this function.
+ *
+ * \note This function automatically increases the reference count to account
+ * for the reference that the container now holds to the object.
+ */
+#ifdef REF_DEBUG
+
+//Definition of ao2_link remains here.
+#define ao2_t_link(arg1, arg2, arg3) __ao2_link_debug((arg1), (arg2), (arg3), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define ao2_link(arg1, arg2) __ao2_link_debug((arg1), (arg2), "", __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#else
+
+#define ao2_t_link(arg1, arg2, arg3) __ao2_link((arg1), (arg2))
+#define ao2_link(arg1, arg2) __ao2_link((arg1), (arg2))
+
+#endif
+
+void *__ao2_link_debug(struct ao2_container *c, void *new_obj, char *tag, char *file, int line, const char *funcname);
+void *__ao2_link(struct ao2_container *c, void *newobj);
+
+/*!
+ * \brief Remove an object from a container
+ *
+ * \param c the container
+ * \param obj the object to unlink
+ *
+ * \retval NULL, always
+ *
+ * \note The object requested to be unlinked must be valid. However, if it turns
+ * out that it is not in the container, this function is still safe to
+ * be called.
+ *
+ * \note If the object gets unlinked from the container, the container's
+ * reference to the object will be automatically released. (The
+ * refcount will be decremented).
+ */
+#ifdef REF_DEBUG
+
+#define ao2_t_unlink(arg1, arg2, arg3) __ao2_unlink_debug((arg1), (arg2), (arg3), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define ao2_unlink(arg1, arg2) __ao2_unlink_debug((arg1), (arg2), "", __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+#else
+
+#define ao2_t_unlink(arg1, arg2, arg3) __ao2_unlink((arg1), (arg2))
+#define ao2_unlink(arg1, arg2) __ao2_unlink((arg1), (arg2))
+
+#endif
+
+void *__ao2_unlink_debug(struct ao2_container *c, void *obj, char *tag, char *file, int line, const char *funcname);
+void *__ao2_unlink(struct ao2_container *c, void *obj);
+
+
+/*@} */
+
+
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=280981&r1=280980&r2=280981
==============================================================================
--- team/akshayb/ao2_containers/main/astobj2.c (original)
+++ team/akshayb/ao2_containers/main/astobj2.c Wed Aug 4 21:21:29 2010
@@ -19,6 +19,7 @@
*/
#include "asterisk.h"
+
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/_private.h"
@@ -30,13 +31,18 @@
* Condition to decide what data type of variable is the container is
*/
-#ifdef BTREE
+// Specify which data structure to be used for ao2_container
+#define ASTOBJ2_HASH_H_ 1
+
+// Condition for BTREE
+#ifdef ASTOBJ2_BTREE_H_
#include "asterisk/astobj2_btree.h"
-#define
-#else
+#endif
+
+// Condition for HASH
+#ifdef ASTOBJ2_HASH_H_
#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
-
+#endif
#define REF_FILE "/tmp/refs"
@@ -148,8 +154,10 @@
/* the underlying functions common to debug and non-debug versions */
static int internal_ao2_ref(void *user_data, const int delta);
+//static struct ao2_container *internal_ao2_container_alloc(struct ao2_container *c, const unsigned n_buckets, ao2_hash_fn *hash_fn,
+// ao2_callback_fn *cmp_fn, ao2_link_fn *link_fn, ao2_unlink_fn *unlink_fn);
static struct ao2_container *internal_ao2_container_alloc(struct ao2_container *c, const unsigned n_buckets, ao2_hash_fn *hash_fn,
- ao2_callback_fn *cmp_fn, ao2_link_fn *link_fn, ao2_unlink_fn *unlink_fn);
+ ao2_callback_fn *cmp_fn);
static struct bucket_entry *internal_ao2_link(struct ao2_container *c, void *user_data, const char *file, int line, const char *func);
static void *internal_ao2_callback(struct ao2_container *c,
const enum search_flags flags, void *cb_fn, void *arg, void *data, enum ao2_callback_type type,
@@ -432,17 +440,15 @@
* function ao2_container_size : to calculate size of ao2_container that would
* allocated by using __ao2_alloc_debug and __ao2_alloc
*/
-
-
-
-
+// ao2_container_alloc for HASH
+#ifdef ASTOBJ2_HASH_H_
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 */
const unsigned int num_buckets = hash_fn ? n_buckets : 1;
- size_t container_size = get_container_size(num_buckets)
+ size_t container_size = get_container_size(num_buckets);
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, link_fn, unlink_fn);
@@ -455,12 +461,47 @@
//Have to search location for this thing.
const unsigned int num_buckets = hash_fn ? n_buckets : 1;
/* replace this size callculation by a function that is to be supplied by the writter as, buckets is not common in btree and other data structures. This has to be done when writing code for btree part. */
- //size_t container_size = sizeof(struct ao2_container) + num_buckets * sizeof(struct bucket);
- size_t container_size = get_container_size(num_buckets);
+ 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, link_fn, unlink_fn);
}
+#endif
+// ao2_container_alloc for BTREE . Still have to figure out how to distinguish between the two ;
+#ifdef ASTOBJ2_BTREE_H_
+static struct ao2_container *internal_ao2_container_alloc(struct ao2_container *c, ao2_callback_fn *cmp_fn, ao2_link_fn *link_fn, ao2_unlink_fn *unlink_fn, int order)
+{
+ 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->core.cmp_fn = cmp_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, link_fn ,unlink_fn, order);
+
+#ifdef AO2_DEBUG
+ ast_atomic_fetchadd_int(&ao2.total_containers, 1);
+#endif
+
+ return c;
+}
+
+struct ao2_container *__ao2_container_alloc_debug(ao2_callback_fn *cmp_fn, int order, char*tag, char *file, int line, const char *funcname, int ref_debug)
+{
+ size_t container_size = sizeof(struct ao2_container);
+ struct ao2_container *c = __ao2_alloc_debug(container_size, container_destruct_debug, tag, file, line, funcname, ref_debug);
+ return internal_ao2_container_alloc(c, cmp_fn, link_fn, unlink_fn, order);
+}
+
+struct ao2_container *__ao2_container_alloc(ao2_callback_fn *cmp_fn, int order)
+{
+ size_t container_size = sizeof(struct ao2_container);
+ struct ao2_container *c = __ao2_alloc(container_size, container_destruct);
+ return internal_ao2_container_alloc(c, cmp_fn, link_fn, unlink_fn, order);
+}
+#endif
+// ao2_container_alloc for btree ends
/*!
* return the number of elements in the container
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=280981&r1=280980&r2=280981
==============================================================================
--- team/akshayb/ao2_containers/main/astobj2_btree.c (original)
+++ team/akshayb/ao2_containers/main/astobj2_btree.c Wed Aug 4 21:21:29 2010
@@ -13,20 +13,6 @@
// Writing Code for ao2_container allocation
-
-struct ao2_container *__ao2_container_alloc_debug(ao2_callback_fn *cmp_fn, int order, char*tag, char *file, int line, const char *funcname, int ref_debug)
-{
- size_t container_size = sizeof(struct ao2_container);
- struct ao2_container *c = __ao2_alloc_debug(container_size, container_destruct_debug, tag, file, line, funcname, ref_debug);
- return internal_ao2_container_alloc(c, cmp_fn, link_fn, unlink_fn, order);
-}
-
-struct ao2_container *__ao2_container_alloc(ao2_callback_fn *cmp_fn, int order)
-{
- size_t container_size = sizeof(struct ao2_container);
- struct ao2_container *c = __ao2_alloc(container_size, container_destruct);
- return internal_ao2_container_alloc(c, cmp_fn, link_fn, unlink_fn, order);
-}
void internal_ao2_container_var_alloc(struct ao2_container *c, ao2_link_fn *link_fn, ao2_unlink_fn *unlink_fn, int order)
{
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=280981&r1=280980&r2=280981
==============================================================================
--- team/akshayb/ao2_containers/main/astobj2_hash.c (original)
+++ team/akshayb/ao2_containers/main/astobj2_hash.c Wed Aug 4 21:21:29 2010
@@ -1,11 +1,17 @@
#include "asterisk/astobj2.h"
#include "asterisk/astobj2_hash.h"
+// ao2_conatiner_var definition.
+
struct ao2_container_var {
- ao2_link_fn *link_fn;
- ao2_unlink_fn *unlink_fn;
- sturct btree *btree;
- };
+ ao2_hash_fn *hash_fn;
+ ao2_link_fn *link_fn;
+ ao2_unlink_fn *unlink_fn;
+ int n_buckets;
+ /*! variable size */
+ struct bucket buckets[0];
+ };
+
/*!
* \brief always zero hash function
*
@@ -20,17 +26,20 @@
return 0;
}
+
+
+
+
+// I remove the variable part of the alloc function, as it was acting useless.
+
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;
}
-//This funtion calculates the size of ao2_container. Just replace the code in case of other containers:
-
-size_t get_container_size (const unsigned int num_buckets)
-{
- return (sizeof(struct ao2_container) + num_buckets * sizeof(struct bucket));
+size_t get_container_size(num_buckets){
+ return sizeof(struct ao2_container) + num_buckets * sizeof(struct bucket);
}
static struct bucket_entry *internal_ao2_link(struct ao2_container *c, void *user_data, const char *file, int line, const char *func)
More information about the asterisk-commits
mailing list