Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Macros | Typedefs | Enumerations | Functions
astobj2_container_private.h File Reference

Common, private definitions for astobj2 containers. More...

#include "asterisk/astobj2.h"
Include dependency graph for astobj2_container_private.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ao2_container
 Generic container type. More...
 
struct  ao2_container_methods
 
struct  ao2_container_node
 Generic container node. More...
 

Macros

#define __container_unlink_node(node, flags)    __container_unlink_node_debug(node, flags, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 
#define AO2_TRAVERSAL_STATE_SIZE   100
 

Typedefs

typedef 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. More...
 
typedef void(* ao2_container_destroy_fn) (struct ao2_container *self)
 Destroy this container. More...
 
typedef 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. More...
 
typedef void(* ao2_container_find_cleanup_fn) (void *v_state)
 Cleanup the container traversal state. More...
 
typedef 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. More...
 
typedef 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. More...
 
typedef enum ao2_container_insert(* ao2_container_insert_fn) (struct ao2_container *self, struct ao2_container_node *node)
 Insert a node into this container. More...
 
typedef int(* ao2_container_integrity) (struct ao2_container *self)
 Perform an integrity check on the specified container. More...
 
typedef 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. More...
 
typedef void(* ao2_container_statistics) (struct ao2_container *self, void *where, ao2_prnt_fn *prnt)
 Display statistics of the specified container. More...
 
typedef 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. More...
 
typedef void(* ao2_link_node_stat_fn) (struct ao2_container *container, struct ao2_container_node *node)
 
typedef void(* ao2_unlink_node_stat_fn) (struct ao2_container *container, struct ao2_container_node *node)
 

Enumerations

enum  ao2_callback_type { AO2_CALLBACK_DEFAULT , AO2_CALLBACK_WITH_DATA }
 
enum  ao2_container_insert { AO2_CONTAINER_INSERT_NODE_INSERTED , AO2_CONTAINER_INSERT_NODE_OBJ_REPLACED , AO2_CONTAINER_INSERT_NODE_REJECTED }
 
enum  ao2_unlink_node_flags { AO2_UNLINK_NODE_UNLINK_OBJECT = (1 << 0) , AO2_UNLINK_NODE_NOUNREF_OBJECT = (1 << 1) , AO2_UNLINK_NODE_UNREF_NODE = (1 << 2) , AO2_UNLINK_NODE_DEC_COUNT = (1 << 3) }
 

Functions

int __container_unlink_node_debug (struct ao2_container_node *node, uint32_t flags, const char *tag, const char *file, int line, const char *func)
 
void container_destruct (void *_c)
 
int container_init (void)
 

Detailed Description

Common, private definitions for astobj2 containers.

Author
Richard Mudgett rmudg.nosp@m.ett@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file astobj2_container_private.h.

Macro Definition Documentation

◆ __container_unlink_node

#define __container_unlink_node (   node,
  flags 
)     __container_unlink_node_debug(node, flags, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Definition at line 310 of file astobj2_container_private.h.

◆ AO2_TRAVERSAL_STATE_SIZE

#define AO2_TRAVERSAL_STATE_SIZE   100

Allow enough room for container specific traversal state structs

Definition at line 60 of file astobj2_container_private.h.

Typedef Documentation

◆ ao2_container_alloc_empty_clone_fn

typedef 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.

Parameters
selfContainer to operate upon.
tagused for debugging.
fileDebug file name invoked from
lineDebug line invoked from
funcDebug function name invoked from
Returns
empty-container on success.
Return values
NULLon error.

Definition at line 82 of file astobj2_container_private.h.

◆ ao2_container_destroy_fn

typedef void(* ao2_container_destroy_fn) (struct ao2_container *self)

Destroy this container.

Parameters
selfContainer to operate upon.

Definition at line 82 of file astobj2_container_private.h.

◆ ao2_container_display

typedef 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.

Parameters
selfContainer to dump.
whereUser data needed by prnt to determine where to put output.
prntPrint output callback function to use.
prnt_objCallback function to print the given object's key. (NULL if not available)

Definition at line 179 of file astobj2_container_private.h.

◆ ao2_container_find_cleanup_fn

typedef void(* ao2_container_find_cleanup_fn) (void *v_state)

Cleanup the container traversal state.

Parameters
v_stateTraversal state to cleanup.

Definition at line 154 of file astobj2_container_private.h.

◆ ao2_container_find_first_fn

typedef 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.

Parameters
selfContainer to operate upon.
flagssearch_flags to control traversing the container
argComparison callback arg parameter.
v_stateTraversal state to restart container traversal.
Returns
node-ptr of found node (Reffed).
Return values
NULLwhen no node found.

Definition at line 82 of file astobj2_container_private.h.

◆ ao2_container_find_next_fn

typedef 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.

Parameters
selfContainer to operate upon.
v_stateTraversal state to restart container traversal.
prevPrevious node returned by the traversal search functions. The ref ownership is passed back to this function.
Returns
node-ptr of found node (Reffed).
Return values
NULLwhen no node found.

Definition at line 82 of file astobj2_container_private.h.

◆ ao2_container_insert_fn

typedef enum ao2_container_insert(* ao2_container_insert_fn) (struct ao2_container *self, struct ao2_container_node *node)

Insert a node into this container.

Parameters
selfContainer to operate upon.
nodeContainer node to insert into the container.
Returns
enum ao2_container_insert value.

Definition at line 82 of file astobj2_container_private.h.

◆ ao2_container_integrity

typedef int(* ao2_container_integrity) (struct ao2_container *self)

Perform an integrity check on the specified container.

Parameters
selfContainer to check integrity.
Note
The container is already locked for reading.
Return values
0on success.
-1on error.

Definition at line 202 of file astobj2_container_private.h.

◆ ao2_container_new_node_fn

typedef 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.

Parameters
selfContainer to operate upon.
obj_newObject to put into the node.
tagused for debugging.
fileDebug file name invoked from
lineDebug line invoked from
funcDebug function name invoked from
Returns
initialized-node on success.
Return values
NULLon error.

Definition at line 82 of file astobj2_container_private.h.

◆ ao2_container_statistics

typedef void(* ao2_container_statistics) (struct ao2_container *self, void *where, ao2_prnt_fn *prnt)

Display statistics of the specified container.

Parameters
selfContainer to display statistics.
whereUser data needed by prnt to determine where to put output.
prntPrint output callback function to use.
Note
The container is already locked for reading.

Definition at line 190 of file astobj2_container_private.h.

◆ ao2_iterator_next_fn

typedef 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.

Parameters
selfContainer to operate upon.
prevPrevious node returned by the iterator.
flagssearch_flags to control iterating the container. Only AO2_ITERATOR_DESCENDING is useful by the method.
Note
The container is already locked.
Returns
node on success.
Return values
NULLon error or no more nodes in the container.

Definition at line 154 of file astobj2_container_private.h.

◆ ao2_link_node_stat_fn

typedef void(* ao2_link_node_stat_fn) (struct ao2_container *container, struct ao2_container_node *node)

Definition at line 212 of file astobj2_container_private.h.

◆ ao2_unlink_node_stat_fn

typedef void(* ao2_unlink_node_stat_fn) (struct ao2_container *container, struct ao2_container_node *node)

Definition at line 222 of file astobj2_container_private.h.

Enumeration Type Documentation

◆ ao2_callback_type

Enumerator
AO2_CALLBACK_DEFAULT 
AO2_CALLBACK_WITH_DATA 

Definition at line 45 of file astobj2_container_private.h.

◆ ao2_container_insert

Enumerator
AO2_CONTAINER_INSERT_NODE_INSERTED 

The node was inserted into the container.

AO2_CONTAINER_INSERT_NODE_OBJ_REPLACED 

The node object replaced an existing node object.

AO2_CONTAINER_INSERT_NODE_REJECTED 

The node was rejected (duplicate).

Definition at line 50 of file astobj2_container_private.h.

50 {
51 /*! The node was inserted into the container. */
53 /*! The node object replaced an existing node object. */
55 /*! The node was rejected (duplicate). */
57};
@ AO2_CONTAINER_INSERT_NODE_OBJ_REPLACED
@ AO2_CONTAINER_INSERT_NODE_REJECTED
@ AO2_CONTAINER_INSERT_NODE_INSERTED

◆ ao2_unlink_node_flags

Enumerator
AO2_UNLINK_NODE_UNLINK_OBJECT 

Remove the node from the object's weak link list OR unref the object if it's a strong reference.

AO2_UNLINK_NODE_NOUNREF_OBJECT 

Modified unlink_object to skip the unref of the object.

AO2_UNLINK_NODE_UNREF_NODE 

Unref the node.

AO2_UNLINK_NODE_DEC_COUNT 

Decrement the container's element count.

Definition at line 33 of file astobj2_container_private.h.

33 {
34 /*! Remove the node from the object's weak link list
35 * OR unref the object if it's a strong reference. */
37 /*! Modified unlink_object to skip the unref of the object. */
39 /*! Unref the node. */
41 /*! Decrement the container's element count. */
43};
@ AO2_UNLINK_NODE_UNREF_NODE
@ AO2_UNLINK_NODE_UNLINK_OBJECT
@ AO2_UNLINK_NODE_DEC_COUNT
@ AO2_UNLINK_NODE_NOUNREF_OBJECT

Function Documentation

◆ __container_unlink_node_debug()

int __container_unlink_node_debug ( struct ao2_container_node node,
uint32_t  flags,
const char *  tag,
const char *  file,
int  line,
const char *  func 
)

Definition at line 39 of file astobj2_container.c.

41{
42 struct ao2_container *container = node->my_container;
43
44 if (container == NULL && (flags & AO2_UNLINK_NODE_DEC_COUNT)) {
45 return 0;
46 }
47
49 && !(flags & AO2_UNLINK_NODE_NOUNREF_OBJECT)) {
50 __ao2_ref(node->obj, -1, tag ?: "Remove obj from container", file, line, func);
51 }
52
53 node->obj = NULL;
54
55 if (flags & AO2_UNLINK_NODE_DEC_COUNT) {
57#if defined(AO2_DEBUG)
58 {
59 int empty = container->nodes - container->elements;
60
61 if (container->max_empty_nodes < empty) {
62 container->max_empty_nodes = empty;
63 }
64 if (container->v_table->unlink_stat) {
65 container->v_table->unlink_stat(container, node);
66 }
67 }
68#endif /* defined(AO2_DEBUG) */
69 }
70
71 if (flags & AO2_UNLINK_NODE_UNREF_NODE) {
72 /* Remove node from container */
73 ao2_ref(node, -1);
74 }
75
76 return 1;
77}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:498
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:757
struct ao2_container * container
Definition: res_fax.c:501
#define NULL
Definition: resample.c:96
Generic container type.
const struct ao2_container_methods * v_table
Definition: test_heap.c:38

References __ao2_ref(), ao2_ref, AO2_UNLINK_NODE_DEC_COUNT, AO2_UNLINK_NODE_NOUNREF_OBJECT, AO2_UNLINK_NODE_UNLINK_OBJECT, AO2_UNLINK_NODE_UNREF_NODE, ast_atomic_fetchadd_int(), container, ao2_container::elements, make_ari_stubs::file, NULL, and ao2_container::v_table.

Referenced by __ao2_iterator_next(), and internal_ao2_traverse().

◆ container_destruct()

void container_destruct ( void *  _c)

Definition at line 635 of file astobj2_container.c.

636{
637 struct ao2_container *c = _c;
638
639 /* Unlink any stored objects in the container. */
640 c->destroying = 1;
642 "container_destruct called");
643
644 /* Perform any extra container cleanup. */
645 if (c->v_table && c->v_table->destroy) {
646 c->v_table->destroy(c);
647 }
648
649#if defined(AO2_DEBUG)
650 ast_atomic_fetchadd_int(&ao2.total_containers, -1);
651#endif
652}
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_MULTIPLE
Definition: astobj2.h:1049
@ OBJ_UNLINK
Definition: astobj2.h:1039
#define ao2_t_callback(c, flags, cb_fn, arg, tag)
Definition: astobj2.h:1696
static struct test_val c

References ao2_t_callback, ast_atomic_fetchadd_int(), c, NULL, OBJ_MULTIPLE, OBJ_NODATA, and OBJ_UNLINK.

Referenced by __ao2_container_alloc_hash(), and __ao2_container_alloc_rbtree().

◆ container_init()

int container_init ( void  )

Definition at line 1181 of file astobj2_container.c.

1182{
1183#if defined(AO2_DEBUG)
1186 "Container registration container.");
1187 if (!reg_containers) {
1188 return -1;
1189 }
1190
1191 ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
1192 ast_register_cleanup(container_cleanup);
1193#endif /* defined(AO2_DEBUG) */
1194
1195 return 0;
1196}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
@ AO2_ALLOC_OPT_LOCK_RWLOCK
Definition: astobj2.h:365
#define ao2_t_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn, tag)
Definition: astobj2.h:1330
@ AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE
Replace objects with duplicate keys in container.
Definition: astobj2.h:1211
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define ARRAY_LEN(a)
Definition: utils.h:666

References AO2_ALLOC_OPT_LOCK_RWLOCK, AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, ao2_t_container_alloc_list, ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), and NULL.

Referenced by astobj2_init().