[asterisk-commits] akshayb: branch akshayb/ao2_containers_review r282976 - in /team/akshayb/ao2_...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Aug 20 06:01:28 CDT 2010
Author: akshayb
Date: Fri Aug 20 06:01:25 2010
New Revision: 282976
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=282976
Log:
Adding files
Modified:
team/akshayb/ao2_containers_review/include/asterisk/astobj2_btree.h
team/akshayb/ao2_containers_review/include/asterisk/btree.h
team/akshayb/ao2_containers_review/main/astobj2_btree.c
team/akshayb/ao2_containers_review/main/btree.c
Modified: team/akshayb/ao2_containers_review/include/asterisk/astobj2_btree.h
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers_review/include/asterisk/astobj2_btree.h?view=diff&rev=282976&r1=282975&r2=282976
==============================================================================
--- team/akshayb/ao2_containers_review/include/asterisk/astobj2_btree.h (original)
+++ team/akshayb/ao2_containers_review/include/asterisk/astobj2_btree.h Fri Aug 20 06:01:25 2010
@@ -759,18 +759,18 @@
*/
#ifdef REF_DEBUG
-#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__)
+#define ao2_t_link(arg1, arg2, arg3) __ao2_link_debug_btree((arg1), (arg2), (arg3), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define ao2_link(arg1, arg2) __ao2_link_debug_btree((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))
+#define ao2_t_link(arg1, arg2, arg3) __ao2_link_btree((arg1), (arg2))
+#define ao2_link(arg1, arg2) __ao2_link_btree((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);
+void *__ao2_link_debug_btree(struct ao2_container *c, void *new_obj, char *tag, char *file, int line, const char *funcname);
+void *__ao2_link_btree(struct ao2_container *c, void *newobj);
/*!
* \brief Remove an object from a container
Modified: team/akshayb/ao2_containers_review/include/asterisk/btree.h
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers_review/include/asterisk/btree.h?view=diff&rev=282976&r1=282975&r2=282976
==============================================================================
--- team/akshayb/ao2_containers_review/include/asterisk/btree.h (original)
+++ team/akshayb/ao2_containers_review/include/asterisk/btree.h Fri Aug 20 06:01:25 2010
@@ -42,6 +42,7 @@
void btree_destroy(struct btree * btree);
void * btree_get_max_key(struct btree * btree);
void * btree_get_min_key(struct btree * btree);
+struct node_pos node_pos_default(void);
#ifdef DEBUG
void print_subtree(struct btree * btree,struct bt_node * node);
Modified: team/akshayb/ao2_containers_review/main/astobj2_btree.c
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers_review/main/astobj2_btree.c?view=diff&rev=282976&r1=282975&r2=282976
==============================================================================
--- team/akshayb/ao2_containers_review/main/astobj2_btree.c (original)
+++ team/akshayb/ao2_containers_review/main/astobj2_btree.c Fri Aug 20 06:01:25 2010
@@ -159,7 +159,7 @@
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, ao2_callback_fn *cmp_fn, int order);
+//static struct ao2_container *internal_ao2_container_alloc(struct ao2_container *c, ao2_callback_fn *cmp_fn, int order);
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,
@@ -483,6 +483,60 @@
};
+static struct bucket_entry *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 astobj2 *obj = INTERNAL_OBJ(user_data);
+
+ if (obj == NULL)
+ return NULL;
+
+ if (INTERNAL_OBJ(c) == NULL)
+ return NULL;
+
+ p = ast_calloc(1, sizeof(*p));
+ if (!p)
+ return NULL;
+
+// i = abs(c->hash_fn(user_data, OBJ_POINTER));
+
+ ao2_lock(c);
+// i %= c->n_buckets;
+ p->astobj = obj;
+ p->version = ast_atomic_fetchadd_int(&c->version, 1);
+// AST_LIST_INSERT_TAIL(&c->buckets[i], p, entry);
+ ast_atomic_fetchadd_int(&c->elements, 1);
+
+ /* the last two operations (ao2_ref, ao2_unlock) must be done by the calling func */
+ return p;
+}
+
+void *__ao2_link_debug_btree(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);
+
+ if (p) {
+ __ao2_ref_debug_btree(user_data, +1, tag, file, line, funcname);
+ ao2_unlock_btree(c);
+ }
+ return p;
+}
+
+void *__ao2_link_btree(struct ao2_container *c, void *user_data)
+{
+ struct bucket_entry *p = internal_ao2_link(c, user_data, __FILE__, __LINE__, __PRETTY_FUNCTION__);
+
+ if (p) {
+ __ao2_ref_btree(user_data, +1);
+ ao2_unlock_btree(c);
+ }
+ return p;
+}
+
+
+
/*!
* \brief another convenience function is a callback that matches on address
*/
@@ -606,7 +660,7 @@
*/
if (ret && (multi_container != NULL)) {
//__ao2_link(multi_container, ret);
- __ao2_link(multi_container, ret);
+ __ao2_link_btree(multi_container, ret);
ret = NULL;
}
@@ -949,9 +1003,10 @@
* No hash means everything goes in the same bucket.
*/
// c1 = ao2_t_container_alloc_btree(100, NULL /* no callback */, NULL /* no hash */,"test");
- c1 = ao2_t_container_alloc_btree(NULL,5,"test");
- ast_cli(a->fd, "container allocated as %p\n", c1);
-
+// c1 = (struct ao2_container *)ao2_t_container_alloc_btree(NULL,5,"test");
+c1 = __ao2_container_alloc_btree(NULL,5);
+ast_cli(a->fd, "container allocated as %p\n", c1);
+
/*
* fill the container with objects.
* ao2_alloc() gives us a reference which we pass to the
Modified: team/akshayb/ao2_containers_review/main/btree.c
URL: http://svnview.digium.com/svn/asterisk/team/akshayb/ao2_containers_review/main/btree.c?view=diff&rev=282976&r1=282975&r2=282976
==============================================================================
--- team/akshayb/ao2_containers_review/main/btree.c (original)
+++ team/akshayb/ao2_containers_review/main/btree.c Fri Aug 20 06:01:25 2010
@@ -7,7 +7,10 @@
unsigned int index;
};
+#ifdef DEBUG
static void print_single_node(struct btree *btree, struct bt_node * node);
+#endif
+
static struct bt_node * allocate_btree_node (unsigned int order);
static int free_btree_node (struct bt_node * node);
@@ -21,6 +24,17 @@
static struct bt_node * merge_siblings(struct btree * btree, struct bt_node * parent,unsigned int index,
position_t pos);
static void copy_key_val(struct btree * btree,struct bt_key_val * src, struct bt_key_val * dst);
+struct node_pos node_pos_default()
+{
+ struct node_pos temp;
+ struct bt_node *temp_node;
+ temp_node = allocate_btree_node(0);
+ temp.index = 0;
+ temp.node = temp_node;
+ return temp;
+}
+
+
/**
* Used to create a btree with just the root node
@@ -212,9 +226,9 @@
* @return The node containing the key and position of the key
*/
static struct node_pos get_max_key_pos(struct btree * btree, struct bt_node * subtree) {
- struct node_pos node_pos;
+ struct node_pos node_pos = node_pos_default();
struct bt_node * node = subtree;
-
+
while(true) {
if(node == NULL) {
break;
@@ -240,7 +254,7 @@
* @return The node containing the key and position of the key
*/
static struct node_pos get_min_key_pos(struct btree * btree, struct bt_node * subtree) {
- struct node_pos node_pos;
+ struct node_pos node_pos = node_pos_default();
struct bt_node * node = subtree;
while(true) {
@@ -652,8 +666,8 @@
unsigned int key_val = btree->value(key);
struct bt_node * node;
unsigned int i = 0;
-
node = btree->root;
+ kp = node_pos_default();
for (;;i = 0) {
@@ -735,8 +749,9 @@
*/
struct bt_key_val * btree_search(struct btree *btree,void * key) {
struct bt_key_val * key_val;
+ struct node_pos kp;
key_val = NULL;
- struct node_pos kp = get_btree_node(btree, key);
+ kp = get_btree_node(btree, key);
if(kp.node) {
key_val = kp.node->key_vals[kp.index];
@@ -796,7 +811,7 @@
* @return none
*/
-static void print_single_node(btree *btree, bt_node * node) {
+static void print_single_node(struct btree *btree, struct bt_node * node) {
int i = 0;
@@ -864,40 +879,7 @@
print("} (0x%x,%d) ", node,node->leaf);
}
-/*This function is for traversing through the tree */
-void traverse_subtree(struct btree *btree,struct bt_node * node) {
-
- int i = 0;
- unsigned int current_level;
-
- struct bt_node * head, * tail;
- struct bt_node * child;
-
- current_level = node->level;
- head = node;
- tail = node;
-
- while(true) {
- if(head == NULL) {
- break;
- }
- if (head->level < current_level) {
- current_level = head->level;
- print("\n");
- }
- print_single_node(btree,head);
-
- if(head->leaf == false) {
- for(i = 0 ; i < head->nr_active + 1; i++) {
- child = head->children[i];
- tail->next = child;
- tail = child;
- child->next = NULL;
- }
- }
- head = head->next;
- }
- print("\n");
-}
+
+
#endif
More information about the asterisk-commits
mailing list