summaryrefslogtreecommitdiff
path: root/main/astobj2_hash.c
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2015-04-17 03:16:59 -0400
committerCorey Farrell <git@cfware.com>2015-04-27 18:37:26 -0400
commit5c1d07baf083fd791c8f717209551d9227413ef7 (patch)
tree7eff8c651efb82e89fd7918038102b84fe888ced /main/astobj2_hash.c
parentd7f4788341f08f386341416aa3944c7f9bc0dc1b (diff)
Astobj2: Allow reference debugging to be enabled/disabled by config.
* The REF_DEBUG compiler flag no longer has any effect on code that uses Astobj2. It is used to determine if reference debugging is enabled by default. Reference debugging can be enabled or disabled in asterisk.conf. * Caller information is provided in logger errors for ao2 bad magic numbers. * Optimizes AO2 by merging internal functions with the public counterpart. This was possible now that we no longer require a dual ABI. ASTERISK-24974 #close Reported by: Corey Farrell Change-Id: Icf3552721fe999365ba8a8cf00a965aa6b897cc1
Diffstat (limited to 'main/astobj2_hash.c')
-rw-r--r--main/astobj2_hash.c93
1 files changed, 21 insertions, 72 deletions
diff --git a/main/astobj2_hash.c b/main/astobj2_hash.c
index 110dd1602..91ad2d2d0 100644
--- a/main/astobj2_hash.c
+++ b/main/astobj2_hash.c
@@ -104,47 +104,27 @@ struct hash_traversal_state_check {
/*!
* \internal
* \brief Create an empty copy of this container.
- * \since 12.0.0
- *
- * \param self Container to operate upon.
- *
- * \retval empty-clone-container on success.
- * \retval NULL on error.
- */
-static struct ao2_container *hash_ao2_alloc_empty_clone(struct ao2_container_hash *self)
-{
- if (!is_ao2_object(self)) {
- return NULL;
- }
-
- return ao2_t_container_alloc_hash(ao2_options_get(self), self->common.options, self->n_buckets,
- self->hash_fn, self->common.sort_fn, self->common.cmp_fn, "Clone hash container");
-}
-
-/*!
- * \internal
- * \brief Create an empty copy of this container. (Debug version)
- * \since 12.0.0
+ * \since 14.0.0
*
* \param self Container to operate upon.
* \param tag used for debugging.
* \param file Debug file name invoked from
* \param line Debug line invoked from
* \param func Debug function name invoked from
- * \param ref_debug TRUE if to output a debug reference message.
*
* \retval empty-clone-container on success.
* \retval NULL on error.
*/
-static struct ao2_container *hash_ao2_alloc_empty_clone_debug(struct ao2_container_hash *self, const char *tag, const char *file, int line, const char *func, int ref_debug)
+static struct ao2_container *hash_ao2_alloc_empty_clone(struct ao2_container_hash *self,
+ const char *tag, const char *file, int line, const char *func)
{
- if (!is_ao2_object(self)) {
+ if (!__is_ao2_object(self, file, line, func)) {
return NULL;
}
- return __ao2_container_alloc_hash_debug(ao2_options_get(self), self->common.options,
+ return __ao2_container_alloc_hash(ao2_options_get(self), self->common.options,
self->n_buckets, self->hash_fn, self->common.sort_fn, self->common.cmp_fn,
- tag, file, line, func, ref_debug);
+ tag, file, line, func);
}
/*!
@@ -230,7 +210,7 @@ static struct hash_bucket_node *hash_ao2_new_node(struct ao2_container_hash *sel
struct hash_bucket_node *node;
int i;
- node = __ao2_alloc(sizeof(*node), hash_ao2_node_destructor, AO2_ALLOC_OPT_LOCK_NOLOCK);
+ node = ao2_t_alloc_options(sizeof(*node), hash_ao2_node_destructor, AO2_ALLOC_OPT_LOCK_NOLOCK, NULL);
if (!node) {
return NULL;
}
@@ -238,11 +218,7 @@ static struct hash_bucket_node *hash_ao2_new_node(struct ao2_container_hash *sel
i = abs(self->hash_fn(obj_new, OBJ_SEARCH_OBJECT));
i %= self->n_buckets;
- if (tag) {
- __ao2_ref_debug(obj_new, +1, tag, file, line, func);
- } else {
- ao2_t_ref(obj_new, +1, "Container node creation");
- }
+ __ao2_ref(obj_new, +1, tag ?: "Container node creation", file, line, func);
node->common.obj = obj_new;
node->common.my_container = (struct ao2_container *) self;
node->my_bucket = i;
@@ -440,7 +416,7 @@ static struct hash_bucket_node *hash_ao2_find_first(struct ao2_container_hash *s
}
/* We have the first traversal node */
- __ao2_ref(node, +1);
+ ao2_t_ref(node, +1, NULL);
return node;
}
}
@@ -482,7 +458,7 @@ static struct hash_bucket_node *hash_ao2_find_first(struct ao2_container_hash *s
}
/* We have the first traversal node */
- __ao2_ref(node, +1);
+ ao2_t_ref(node, +1, NULL);
return node;
}
}
@@ -551,7 +527,7 @@ static struct hash_bucket_node *hash_ao2_find_next(struct ao2_container_hash *se
}
/* We have the next traversal node */
- __ao2_ref(node, +1);
+ ao2_t_ref(node, +1, NULL);
/*
* Dereferencing the prev node may result in our next node
@@ -559,7 +535,7 @@ static struct hash_bucket_node *hash_ao2_find_next(struct ao2_container_hash *se
* the container uses RW locks and the container was read
* locked.
*/
- __ao2_ref(prev, -1);
+ ao2_t_ref(prev, -1, NULL);
if (node->common.obj) {
return node;
}
@@ -595,7 +571,7 @@ hash_descending_resume:;
}
/* We have the next traversal node */
- __ao2_ref(node, +1);
+ ao2_t_ref(node, +1, NULL);
/*
* Dereferencing the prev node may result in our next node
@@ -603,7 +579,7 @@ hash_descending_resume:;
* the container uses RW locks and the container was read
* locked.
*/
- __ao2_ref(prev, -1);
+ ao2_t_ref(prev, -1, NULL);
if (node->common.obj) {
return node;
}
@@ -615,7 +591,7 @@ hash_ascending_resume:;
}
/* No more nodes in the container left to traverse. */
- __ao2_ref(prev, -1);
+ ao2_t_ref(prev, -1, NULL);
return NULL;
}
@@ -1037,8 +1013,6 @@ static int hash_ao2_integrity(struct ao2_container_hash *self)
/*! Hash container virtual method table. */
static const struct ao2_container_methods v_table_hash = {
.alloc_empty_clone = (ao2_container_alloc_empty_clone_fn) hash_ao2_alloc_empty_clone,
- .alloc_empty_clone_debug =
- (ao2_container_alloc_empty_clone_debug_fn) hash_ao2_alloc_empty_clone_debug,
.new_node = (ao2_container_new_node_fn) hash_ao2_new_node,
.insert = (ao2_container_insert_fn) hash_ao2_insert_node,
.traverse_first = (ao2_container_find_first_fn) hash_ao2_find_first,
@@ -1104,25 +1078,8 @@ static struct ao2_container *hash_ao2_container_init(
struct ao2_container *__ao2_container_alloc_hash(unsigned int ao2_options,
unsigned int container_options, unsigned int n_buckets, ao2_hash_fn *hash_fn,
- ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn)
-{
- unsigned int num_buckets;
- size_t container_size;
- struct ao2_container_hash *self;
-
- num_buckets = hash_fn ? n_buckets : 1;
- container_size = sizeof(struct ao2_container_hash) + num_buckets * sizeof(struct hash_bucket);
-
- self = ao2_t_alloc_options(container_size, container_destruct, ao2_options,
- "New hash container");
- return hash_ao2_container_init(self, container_options, num_buckets,
- hash_fn, sort_fn, cmp_fn);
-}
-
-struct ao2_container *__ao2_container_alloc_hash_debug(unsigned int ao2_options,
- unsigned int container_options, unsigned int n_buckets, ao2_hash_fn *hash_fn,
ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn,
- const char *tag, const char *file, int line, const char *func, int ref_debug)
+ const char *tag, const char *file, int line, const char *func)
{
unsigned int num_buckets;
size_t container_size;
@@ -1131,25 +1088,17 @@ struct ao2_container *__ao2_container_alloc_hash_debug(unsigned int ao2_options,
num_buckets = hash_fn ? n_buckets : 1;
container_size = sizeof(struct ao2_container_hash) + num_buckets * sizeof(struct hash_bucket);
- self = __ao2_alloc_debug(container_size,
- ref_debug ? container_destruct_debug : container_destruct, ao2_options,
- tag, file, line, func, ref_debug);
+ self = __ao2_alloc(container_size, container_destruct, ao2_options,
+ tag ?: __PRETTY_FUNCTION__, file, line, func);
return hash_ao2_container_init(self, container_options, num_buckets, hash_fn,
sort_fn, cmp_fn);
}
struct ao2_container *__ao2_container_alloc_list(unsigned int ao2_options,
- unsigned int container_options, ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn)
-{
- return __ao2_container_alloc_hash(ao2_options, container_options, 1, NULL, sort_fn,
- cmp_fn);
-}
-
-struct ao2_container *__ao2_container_alloc_list_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)
+ const char *tag, const char *file, int line, const char *func)
{
- return __ao2_container_alloc_hash_debug(ao2_options, container_options, 1, NULL,
- sort_fn, cmp_fn, tag, file, line, func, ref_debug);
+ return __ao2_container_alloc_hash(ao2_options, container_options, 1, NULL,
+ sort_fn, cmp_fn, tag, file, line, func);
}