[asterisk-commits] akshayb: branch akshayb/ao2_containers r265223 - /team/akshayb/ao2_containers...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat May 22 13:38:41 CDT 2010
Author: akshayb
Date: Sat May 22 13:38:39 2010
New Revision: 265223
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=265223
Log:
Added new definition of ao2_container. And started writing the ao2 allocation related function.
Modified:
team/akshayb/ao2_containers/main/astobj2.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=265223&r1=265222&r2=265223
==============================================================================
--- team/akshayb/ao2_containers/main/astobj2.c (original)
+++ team/akshayb/ao2_containers/main/astobj2.c Sat May 22 13:38:39 2010
@@ -137,11 +137,11 @@
static int internal_ao2_ref(void *user_data, const int delta);
static struct ao2_container *internal_ao2_container_alloc(struct ao2_container *c, const uint n_buckets, ao2_hash_fn *hash_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 struct bucket_list *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,
char *tag, char *file, int line, const char *funcname);
-static void *internal_ao2_iterator_next(struct ao2_iterator *a, struct bucket_entry **q);
+static void *internal_ao2_iterator_next(struct ao2_iterator *a, struct bucket_list **q);
int __ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var)
{
@@ -348,7 +348,7 @@
static void container_destruct_debug(void *c);
/* each bucket in the container is a tailq. */
-AST_LIST_HEAD_NOLOCK(bucket, bucket_entry);
+AST_LIST_HEAD_NOLOCK(bucket, bucket_list);
/*!
* A container; stores the hash and callback functions, information on
@@ -367,25 +367,60 @@
*
* \todo Linking and unlink objects is typically expensive, as it
* involves a malloc() of a small object which is very inefficient.
- * To optimize this, we allocate larger arrays of bucket_entry's
+ * To optimize this, we allocate larger arrays of bucket_list's
* when we run out of them, and then manage our own freelist.
* This will be more efficient as we can do the freelist management while
* we hold the lock (that we need anyways).
*/
+
+struct ao2_container_core {
+ ao2_callback_fn *cmp_fn;
+ /*! Number of elements in the container */
+ int elements;
+ /*! described above */
+ int version;
+};
+
+struct ao2_container {
+ ao2_contaniner_core core;
+ ao2_hash_fn *hash_fn;
+ ao2_link_fn *link_fn;
+ ao2_unlink_fn *unlink_fn;
+ int n_buckets;
+ /*! variable size */
+ struct bucket buckets[0];
+};
+
+/* Hash function definition
+ This is based on old definition */
+
+static struct ao2_container *internal_ao2_container_alloc(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)
+{
+ if (!c)
+ return NULL;
+
+ 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;
+
+
+/*Older code
+
struct ao2_container {
ao2_hash_fn *hash_fn;
ao2_callback_fn *cmp_fn;
int n_buckets;
- /*! Number of elements in the container */
int elements;
- /*! described above */
int version;
- /*! variable size */
struct bucket buckets[0];
};
-
-/*!
- * \brief always zero hash function
+*/
+
+/*!
+ * \brief always zero on
*
* 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
@@ -461,8 +496,8 @@
* used within a bucket.
* XXX \todo this should be private to the container code
*/
-struct bucket_entry {
- AST_LIST_ENTRY(bucket_entry) entry;
+struct bucket_list {
+ AST_LIST_ENTRY(bucket_list) entry;
int version;
struct astobj2 *astobj; /* pointer to internal data */
};
@@ -471,11 +506,11 @@
* link an object to a container
*/
-static struct bucket_entry *internal_ao2_link(struct ao2_container *c, void *user_data, const char *file, int line, const char *func)
+static struct bucket_list *internal_ao2_link(struct ao2_container *c, void *user_data, const char *file, int line, const char *func)
{
int i;
/* create a new list entry */
- struct bucket_entry *p;
+ struct bucket_list *p;
struct astobj2 *obj = INTERNAL_OBJ(user_data);
if (obj == NULL)
@@ -503,7 +538,7 @@
void *__ao2_link_debug(struct ao2_container *c, void *user_data, char *tag, char *file, int line, const char *funcname)
{
- struct bucket_entry *p = internal_ao2_link(c, user_data, file, line, funcname);
+ struct bucket_list *p = internal_ao2_link(c, user_data, file, line, funcname);
if (p) {
__ao2_ref_debug(user_data, +1, tag, file, line, funcname);
@@ -514,7 +549,7 @@
void *__ao2_link(struct ao2_container *c, void *user_data)
{
- struct bucket_entry *p = internal_ao2_link(c, user_data, __FILE__, __LINE__, __PRETTY_FUNCTION__);
+ struct bucket_list *p = internal_ao2_link(c, user_data, __FILE__, __LINE__, __PRETTY_FUNCTION__);
if (p) {
__ao2_ref(user_data, +1);
@@ -533,7 +568,7 @@
/*
* Unlink an object from the container
- * and destroy the associated * bucket_entry structure.
+ * and destroy the associated * ao2_bucket_list structure.
*/
void *__ao2_unlink_debug(struct ao2_container *c, void *user_data, char *tag,
char *file, int line, const char *funcname)
@@ -658,7 +693,7 @@
for (; i < last ; i++) {
/* scan the list with prev-cur pointers */
- struct bucket_entry *cur;
+ struct bucket_list *cur;
AST_LIST_TRAVERSE_SAFE_BEGIN(&c->buckets[i], cur, entry) {
int match = (CMP_MATCH | CMP_STOP);
@@ -823,10 +858,10 @@
/*
* move to the next element in the container.
*/
-static void *internal_ao2_iterator_next(struct ao2_iterator *a, struct bucket_entry **q)
+static void *internal_ao2_iterator_next(struct ao2_iterator *a, struct bucket_list **q)
{
int lim;
- struct bucket_entry *p = NULL;
+ struct bucket_list *p = NULL;
void *ret = NULL;
*q = NULL;
@@ -892,7 +927,7 @@
void *__ao2_iterator_next_debug(struct ao2_iterator *a, char *tag, char *file, int line, const char *funcname)
{
- struct bucket_entry *p;
+ struct bucket_list *p;
void *ret = NULL;
ret = internal_ao2_iterator_next(a, &p);
@@ -910,7 +945,7 @@
void *__ao2_iterator_next(struct ao2_iterator *a)
{
- struct bucket_entry *p = NULL;
+ struct bucket_list *p = NULL;
void *ret = NULL;
ret = internal_ao2_iterator_next(a, &p);
@@ -949,7 +984,7 @@
__ao2_callback(c, OBJ_UNLINK, cd_cb, NULL);
for (i = 0; i < c->n_buckets; i++) {
- struct bucket_entry *current;
+ struct bucket_list *current;
while ((current = AST_LIST_REMOVE_HEAD(&c->buckets[i], entry))) {
ast_free(current);
@@ -969,7 +1004,7 @@
__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;
+ struct bucket_list *current;
while ((current = AST_LIST_REMOVE_HEAD(&c->buckets[i], entry))) {
ast_free(current);
More information about the asterisk-commits
mailing list