Newer
Older
}
/* Check total obj count. */
if (count_obj != ao2_container_count(&self->common)) {
ast_log(LOG_ERROR, "Total object count does not match ao2_container_count()!\n");
return -1;
}
/* Check total node count. */
if (count_node != self->common.nodes) {
ast_log(LOG_ERROR, "Total node count of %d does not match stat of %d!\n",
count_node, self->common.nodes);
return -1;
}
return res;
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
/*! rbtree container virtual method table. */
static const struct ao2_container_methods v_table_rbtree = {
.alloc_empty_clone = (ao2_container_alloc_empty_clone_fn) rb_ao2_alloc_empty_clone,
.alloc_empty_clone_debug =
(ao2_container_alloc_empty_clone_debug_fn) rb_ao2_alloc_empty_clone_debug,
.new_node = (ao2_container_new_node_fn) rb_ao2_new_node,
.insert = (ao2_container_insert_fn) rb_ao2_insert_node,
.traverse_first = (ao2_container_find_first_fn) rb_ao2_find_first,
.traverse_next = (ao2_container_find_next_fn) rb_ao2_find_next,
.iterator_next = (ao2_iterator_next_fn) rb_ao2_iterator_next,
.destroy = (ao2_container_destroy_fn) rb_ao2_destroy,
George Joseph
committed
#if defined(AO2_DEBUG)
.dump = (ao2_container_display) rb_ao2_dump,
.stats = (ao2_container_statistics) rb_ao2_stats,
.integrity = (ao2_container_integrity) rb_ao2_integrity,
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
};
/*!
* \brief Initialize a rbtree container.
*
* \param self Container to initialize.
* \param options Container behaviour options (See enum ao2_container_opts)
* \param sort_fn Pointer to a sort function.
* \param cmp_fn Pointer to a compare function used by ao2_find.
*
* \return A pointer to a struct container.
*/
static struct ao2_container *rb_ao2_container_init(struct ao2_container_rbtree *self,
unsigned int options, ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn)
{
if (!self) {
return NULL;
}
self->common.v_table = &v_table_rbtree;
self->common.sort_fn = sort_fn;
self->common.cmp_fn = cmp_fn;
self->common.options = options;
#ifdef AO2_DEBUG
ast_atomic_fetchadd_int(&ao2.total_containers, 1);
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
return (struct ao2_container *) self;
}
struct ao2_container *__ao2_container_alloc_rbtree(unsigned int ao2_options, unsigned int container_options,
ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn)
{
struct ao2_container_rbtree *self;
if (!sort_fn) {
/* Sanity checks. */
ast_log(LOG_ERROR, "Missing sort_fn()!\n");
return NULL;
}
self = ao2_t_alloc_options(sizeof(*self), container_destruct, ao2_options,
"New rbtree container");
return rb_ao2_container_init(self, container_options, sort_fn, cmp_fn);
}
struct ao2_container *__ao2_container_alloc_rbtree_debug(unsigned int ao2_options, unsigned int container_options,
ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn,
const char *tag, const char *file, int line, const char *func, int ref_debug)
{
struct ao2_container_rbtree *self;
if (!sort_fn) {
/* Sanity checks. */
ast_log(__LOG_ERROR, file, line, func, "Missing sort_fn()!\n");
return NULL;
}
self = __ao2_alloc_debug(sizeof(*self),
ref_debug ? container_destruct_debug : container_destruct, ao2_options,
tag, file, line, func, ref_debug);
return rb_ao2_container_init(self, container_options, sort_fn, cmp_fn);
}