52 #if defined(AO2_DEBUG) 117 const char *tag,
const char *
file,
int line,
const char *func)
124 self->n_buckets, self->hash_fn, self->common.sort_fn, self->common.cmp_fn,
125 tag, file, line, func);
173 #if defined(AO2_DEBUG) 221 __ao2_ref(obj_new, +1, tag ?:
"Container node creation", file, line, func);
248 bucket = &
self->buckets[node->
my_bucket];
249 sort_fn =
self->common.sort_fn;
250 options =
self->common.options;
341 memset(state, 0,
sizeof(*state));
343 state->
flags = flags;
365 bucket_cur =
abs(self->hash_fn(arg, flags & OBJ_SEARCH_MASK)
367 state->
sort_fn =
self->common.sort_fn;
372 state->
sort_fn =
self->common.sort_fn;
387 if (bucket_cur < 0) {
388 bucket_cur =
self->n_buckets - 1;
396 for (; state->
bucket_last <= bucket_cur; --bucket_cur) {
429 if (bucket_cur < 0) {
438 for (; bucket_cur < state->
bucket_last; ++bucket_cur) {
492 flags = state->
flags;
504 goto hash_descending_resume;
507 for (; state->
bucket_last <= bucket_cur; --bucket_cur) {
544 hash_descending_resume:;
548 goto hash_ascending_resume;
551 for (; bucket_cur < state->
bucket_last; ++bucket_cur) {
588 hash_ascending_resume:;
634 cur_bucket =
self->n_buckets;
638 while (0 <= --cur_bucket) {
669 while (++cur_bucket < self->n_buckets) {
685 #if defined(AO2_DEBUG) 702 ++
self->buckets[i].elements;
703 if (self->buckets[i].max_elements < self->buckets[i].elements) {
704 self->buckets[i].max_elements =
self->buckets[i].elements;
709 #if defined(AO2_DEBUG) 725 --
self->buckets[node->
my_bucket].elements;
744 for (idx = self->n_buckets; idx--;) {
753 #if defined(AO2_DEBUG) 768 #define FORMAT "%6s, %16s, %16s, %16s, %16s, %s\n" 769 #define FORMAT2 "%6d, %16p, %16p, %16p, %16p, " 772 int suppressed_buckets = 0;
775 prnt(where,
"Number of buckets: %d\n\n", self->n_buckets);
777 prnt(where,
FORMAT,
"Bucket",
"Node",
"Prev",
"Next",
"Obj",
"Key");
778 for (bucket = 0; bucket <
self->n_buckets; ++bucket) {
781 suppressed_buckets = 0;
796 }
else if (!suppressed_buckets) {
797 suppressed_buckets = 1;
798 prnt(where,
"...\n");
807 #if defined(AO2_DEBUG) 823 #define FORMAT "%10.10s %10.10s %10.10s\n" 824 #define FORMAT2 "%10d %10d %10d\n" 827 int suppressed_buckets = 0;
829 prnt(where,
"Number of buckets: %d\n\n", self->n_buckets);
831 prnt(where,
FORMAT,
"Bucket",
"Objects",
"Max");
832 for (bucket = 0; bucket <
self->n_buckets; ++bucket) {
833 if (self->buckets[bucket].max_elements) {
834 suppressed_buckets = 0;
835 prnt(where,
FORMAT2, bucket, self->buckets[bucket].elements,
836 self->buckets[bucket].max_elements);
837 }
else if (!suppressed_buckets) {
838 suppressed_buckets = 1;
839 prnt(where,
"...\n");
848 #if defined(AO2_DEBUG) 867 int count_total_node;
874 count_total_node = 0;
877 for (bucket = 0; bucket <
self->n_buckets; ++bucket) {
910 for (; node; node = next) {
915 ast_log(
LOG_ERROR,
"Bucket %d list node's prev pointer points to itself!\n",
934 ast_log(
LOG_ERROR,
"Bucket %d list node's next pointer points to itself!\n",
965 if (bucket != bucket_exp) {
972 if (self->common.sort_fn) {
984 if (count_obj != self->buckets[bucket].elements) {
985 ast_log(
LOG_ERROR,
"Bucket %d object count of %d does not match stat of %d!\n",
986 bucket, count_obj, self->buckets[bucket].elements);
991 count_total_obj += count_obj;
997 "Total object count of %d does not match ao2_container_count() of %d!\n",
1003 if (count_total_node != self->common.nodes) {
1005 count_total_node, self->common.nodes);
1022 #
if defined(AO2_DEBUG)
1023 .link_stat = hash_ao2_link_node_stat,
1024 .unlink_stat = hash_ao2_unlink_node_stat,
1066 self->common.sort_fn =
sort_fn;
1067 self->common.cmp_fn =
cmp_fn;
1068 self->common.options =
options;
1069 self->hash_fn = hash_fn ? hash_fn :
hash_zero;
1070 self->n_buckets = n_buckets;
1080 unsigned int container_options,
unsigned int n_buckets,
ao2_hash_fn *hash_fn,
1082 const char *tag,
const char *
file,
int line,
const char *func)
1084 unsigned int num_buckets;
1085 size_t container_size;
1092 tag ?: __PRETTY_FUNCTION__, file, line, func);
1099 const char *tag,
const char *
file,
int line,
const char *func)
1102 sort_fn, cmp_fn, tag, file, line, func);
#define AST_DLLIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
struct ao2_container common
Items common to all containers.
struct ao2_container_node *(* ao2_iterator_next_fn)(struct ao2_container *self, struct ao2_container_node *prev, enum ao2_iterator_flags flags)
Find the next non-empty iteration node in the container.
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define __is_ao2_object(user_data, file, line, func)
#define AST_DLLIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
The arg parameter is a search key, but is not an object.
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, const char *tag, const char *file, int line, const char *func)
#define __container_unlink_node(node, flags)
void container_destruct(void *_c)
Common, private definitions for astobj2.
static void hash_ao2_destroy(struct ao2_container_hash *self)
Allow objects with duplicate keys in container.
enum ao2_container_insert(* ao2_container_insert_fn)(struct ao2_container *self, struct ao2_container_node *node)
Insert a node into this container.
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, const char *tag, const char *file, int line, const char *func)
static struct hash_bucket_node * hash_ao2_new_node(struct ao2_container_hash *self, void *obj_new, const char *tag, const char *file, int line, const char *func)
void * __ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
int() ao2_sort_fn(const void *obj_left, const void *obj_right, int flags)
Type of generic container sort function.
#define AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Assume that the ao2_container is already locked.
int(* ao2_container_integrity)(struct ao2_container *self)
Perform an integrity check on the specified container.
#define ao2_alloc_options(data_size, destructor_fn, options)
static void hash_ao2_node_destructor(void *v_doomed)
ao2_container_find_first_fn traverse_first
static enum ao2_container_insert hash_ao2_insert_node(struct ao2_container_hash *self, struct hash_bucket_node *node)
search_flags
Flags passed to ao2_callback_fn(), ao2_hash_fn(), and ao2_sort_fn() to modify behaviour.
#define AST_DLLIST_INSERT_AFTER_CURRENT(elm, field)
Inserts a list node after the current node during a traversal.
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Insert objects at the beginning of the container. (Otherwise it is the opposite; insert at the end...
void() ao2_prnt_fn(void *where, const char *fmt,...)
Print output.
#define is_ao2_object(user_data)
Traverse in ascending order (First to last container object)
int ao2_container_check(struct ao2_container *self, enum search_flags flags)
Perform an integrity check on the specified container.
static struct ao2_container * hash_ao2_container_init(struct ao2_container_hash *self, unsigned int options, unsigned int n_buckets, ao2_hash_fn *hash_fn, ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn)
Initialize a hash container with the desired number of buckets.
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
#define AST_DLLIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
int() ao2_callback_fn(void *obj, void *arg, int flags)
Type of a generic callback function.
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
#define AST_DLLIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
A set of macros to manage doubly-linked lists.
#define AST_DLLIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
static int hash_zero(const void *user_obj, const int flags)
always zero hash function
struct ao2_container_node *(* ao2_container_find_first_fn)(struct ao2_container *self, enum search_flags flags, void *arg, void *v_state)
Find the first container node in a traversal.
The ao2 container objects with duplicate keys option field mask.
#define ao2_ref(o, delta)
#define AO2_DEVMODE_STAT(stat)
Traverse in descending order (Last to first container object)
#define AST_DLLIST_INSERT_BEFORE_CURRENT(elm, field)
Inserts a list node before the current node during a traversal.
struct ao2_container_node common
Items common to all container nodes.
void(* ao2_container_destroy_fn)(struct ao2_container *self)
Destroy this container.
void(* ao2_container_statistics)(struct ao2_container *self, void *where, ao2_prnt_fn *prnt)
Display statistics of the specified container.
struct hash_bucket_node::@340 links
int() ao2_hash_fn(const void *obj, int flags)
static struct hash_bucket_node * hash_ao2_iterator_next(struct ao2_container_hash *self, struct hash_bucket_node *node, enum ao2_iterator_flags flags)
ao2_iterator_next_fn iterator_next
Traverse in pre-order (Node then children, for tree container)
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)
static const struct ao2_container_methods v_table_hash
unsigned int destroying
TRUE if the container is being destroyed.
#define AST_DLLIST_EMPTY(head)
Checks whether the specified list contains any entries.
Prototypes for public functions only of internal interest,.
#define AO2_TRAVERSAL_STATE_SIZE
#define AST_DLLIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
The arg parameter is an object of the same type.
Replace objects with duplicate keys in container.
#define AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END
Closes a safe loop traversal block.
struct hash_bucket::@341 list
Traverse in post-order (Children then node, for tree container)
unsigned int ao2_options_get(void *obj)
Retrieve the ao2 options used to create the object.
#define AST_DLLIST_PREV(elm, field)
Returns the previous entry in the list before the given entry.
Common, private definitions for astobj2 containers.
struct ao2_container *(* ao2_container_alloc_empty_clone_fn)(struct ao2_container *self, const char *tag, const char *file, int line, const char *func)
Create an empty copy of this container.
enum ao2_lock_req __adjust_lock(void *user_data, enum ao2_lock_req lock_how, int keep_stronger)
#define AST_DLLIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Reject objects with duplicate keys in container.
Search option field mask.
static struct hash_bucket_node * hash_ao2_find_first(struct ao2_container_hash *self, enum search_flags flags, void *arg, struct hash_traversal_state *state)
void() ao2_prnt_obj_fn(void *v_obj, void *where, ao2_prnt_fn *prnt)
Print object key.
struct ao2_container * my_container
struct hash_bucket buckets[0]
static struct hash_bucket_node * hash_ao2_find_next(struct ao2_container_hash *self, struct hash_traversal_state *state, struct hash_bucket_node *prev)
struct ao2_container_node *(* ao2_container_new_node_fn)(struct ao2_container *self, void *obj_new, const char *tag, const char *file, int line, const char *func)
Create a new container node.
#define AST_DLLIST_FIRST(head)
Returns the first entry contained in a list.
ao2_container_alloc_empty_clone_fn alloc_empty_clone
Create an empty copy of this container.
Reject duplicate objects in container.
ao2_container_new_node_fn new_node
Traverse order option field mask.
#define AST_DLLIST_LAST(head)
Returns the last entry contained in a list.
struct ao2_container_node *(* ao2_container_find_next_fn)(struct ao2_container *self, void *v_state, struct ao2_container_node *prev)
Find the next container node in a traversal.
#define AST_DLLIST_ENTRY(type)
Declare previous/forward links inside a list entry.
void(* ao2_container_display)(struct ao2_container *self, void *where, ao2_prnt_fn *prnt, ao2_prnt_obj_fn *prnt_obj)
Display contents of the specified container.