Asterisk - The Open Source Telephony Project  18.5.0
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[email protected][email protected][email protected]digiu[email protected]m.co[email protected]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__)

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

Referenced by internal_ao2_traverse().

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
Return values
empty-containeron success.
NULLon error.

Definition at line 98 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.
Returns
Nothing

Definition at line 84 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)
Returns
Nothing

Definition at line 185 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.
Returns
Nothing

Definition at line 158 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.
Return values
node-ptrof found node (Reffed).
NULLwhen no node found.

Definition at line 136 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.
Return values
node-ptrof found node (Reffed).
NULLwhen no node found.

Definition at line 149 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 123 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 210 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
Return values
initialized-nodeon success.
NULLon error.

Definition at line 113 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.
Returns
Nothing

Definition at line 198 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.
Return values
nodeon success.
NULLon error or no more nodes in the container.

Definition at line 173 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 222 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 234 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_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. */
40  AO2_UNLINK_NODE_UNREF_NODE = (1 << 2),
41  /*! Decrement the container's element count. */
42  AO2_UNLINK_NODE_DEC_COUNT = (1 << 3),
43 };

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.

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, ao2_container_node::my_container, NULL, ao2_container_node::obj, and ao2_container::v_table.

Referenced by __ao2_iterator_next(), and internal_ao2_traverse().

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 
48  if ((flags & AO2_UNLINK_NODE_UNLINK_OBJECT)
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) {
56  ast_atomic_fetchadd_int(&container->elements, -1);
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 NULL
Definition: resample.c:96
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:755
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:498
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const struct ao2_container_methods * v_table
struct ao2_container * container
Definition: res_fax.c:502
Generic container type.
struct ao2_container * my_container

◆ container_destruct()

void container_destruct ( void *  _c)

Definition at line 635 of file astobj2_container.c.

References ao2_t_callback, ast_atomic_fetchadd_int(), ao2_container_methods::destroy, ao2_container::destroying, NULL, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, and ao2_container::v_table.

Referenced by __ao2_container_alloc_hash(), and __ao2_container_alloc_rbtree().

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 }
ao2_container_destroy_fn destroy
static struct test_val c
#define NULL
Definition: resample.c:96
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:755
const struct ao2_container_methods * v_table
#define ao2_t_callback(c, flags, cb_fn, arg, tag)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
Definition: astobj2.h:1714
unsigned int destroying
TRUE if the container is being destroyed.
Generic container type.

◆ container_init()

int container_init ( void  )

Definition at line 1183 of file astobj2_container.c.

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().

1184 {
1185 #if defined(AO2_DEBUG)
1187  AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, ao2_reg_sort_cb, NULL,
1188  "Container registration container.");
1189  if (!reg_containers) {
1190  return -1;
1191  }
1192 
1193  ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
1194  ast_register_cleanup(container_cleanup);
1195 #endif /* defined(AO2_DEBUG) */
1196 
1197  return 0;
1198 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define ao2_t_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn, tag)
Allocate and initialize a list container.
Definition: astobj2.h:1333
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define NULL
Definition: resample.c:96
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
Replace objects with duplicate keys in container.
Definition: astobj2.h:1215