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

Defines

#define __container_unlink_node(node, flags)   __container_unlink_node_debug(node, flags, NULL, NULL, 0, NULL)
#define AO2_TRAVERSAL_STATE_SIZE   100

Typedefs

typedef struct ao2_container *(* ao2_container_alloc_empty_clone_debug_fn )(struct ao2_container *self, const char *tag, const char *file, int line, const char *func, int ref_debug)
 Create an empty copy of this container. (Debug version).
typedef struct ao2_container *(* ao2_container_alloc_empty_clone_fn )(struct ao2_container *self)
 Create an empty copy of this container.
typedef void(* ao2_container_destroy_fn )(struct ao2_container *self)
 Destroy this container.
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.
typedef void(* ao2_container_find_cleanup_fn )(void *v_state)
 Cleanup the container traversal state.
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.
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.
typedef int(* ao2_container_integrity )(struct ao2_container *self)
 Perform an integrity check on the specified container.
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.
typedef void(* ao2_container_statistics )(struct ao2_container *self, void *where, ao2_prnt_fn *prnt)
 Display statistics of the specified container.
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.
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)
void container_destruct_debug (void *_c)
int container_init (void)

Variables

enum ao2_container_insert(* ao2_container_insert_fn )(struct ao2_container *self, struct ao2_container_node *node)
 Insert a node into this container.


Detailed Description

Common, private definitions for astobj2 containers.

Author:
Richard Mudgett <rmudgett@digium.com>

Definition in file astobj2_container_private.h.


Define Documentation

#define __container_unlink_node ( node,
flags   )     __container_unlink_node_debug(node, flags, NULL, NULL, 0, NULL)

#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

typedef struct ao2_container*(* ao2_container_alloc_empty_clone_debug_fn)(struct ao2_container *self, const char *tag, const char *file, int line, const char *func, int ref_debug)

Create an empty copy of this container. (Debug version).

Parameters:
self Container to operate upon.
tag used for debugging.
file Debug file name invoked from
line Debug line invoked from
func Debug function name invoked from
ref_debug TRUE if to output a debug reference message.
Return values:
empty-container on success.
NULL on error.

Definition at line 109 of file astobj2_container_private.h.

Create an empty copy of this container.

Parameters:
self Container to operate upon.
Return values:
empty-container on success.
NULL on error.

Definition at line 94 of file astobj2_container_private.h.

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

Destroy this container.

Parameters:
self Container to operate upon.
Returns:
Nothing

Definition at line 84 of file astobj2_container_private.h.

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:
self Container to dump.
where User data needed by prnt to determine where to put output.
prnt Print output callback function to use.
prnt_obj Callback function to print the given object's key. (NULL if not available)
Returns:
Nothing

Definition at line 196 of file astobj2_container_private.h.

typedef void(* ao2_container_find_cleanup_fn)(void *v_state)

Cleanup the container traversal state.

Parameters:
v_state Traversal state to cleanup.
Returns:
Nothing

Definition at line 169 of file astobj2_container_private.h.

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:
self Container to operate upon.
flags search_flags to control traversing the container
arg Comparison callback arg parameter.
v_state Traversal state to restart container traversal.
Return values:
node-ptr of found node (Reffed).
NULL when no node found.

Definition at line 147 of file astobj2_container_private.h.

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:
self Container to operate upon.
v_state Traversal state to restart container traversal.
prev Previous node returned by the traversal search functions. The ref ownership is passed back to this function.
Return values:
node-ptr of found node (Reffed).
NULL when no node found.

Definition at line 160 of file astobj2_container_private.h.

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

Perform an integrity check on the specified container.

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

Definition at line 221 of file astobj2_container_private.h.

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:
self Container to operate upon.
obj_new Object to put into the node.
tag used for debugging.
file Debug file name invoked from
line Debug line invoked from
func Debug function name invoked from
Return values:
initialized-node on success.
NULL on error.

Definition at line 124 of file astobj2_container_private.h.

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

Display statistics of the specified container.

Parameters:
self Container to display statistics.
where User data needed by prnt to determine where to put output.
prnt Print output callback function to use.
Note:
The container is already locked for reading.
Returns:
Nothing

Definition at line 209 of file astobj2_container_private.h.

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:
self Container to operate upon.
prev Previous node returned by the iterator.
flags search_flags to control iterating the container. Only AO2_ITERATOR_DESCENDING is useful by the method.
Note:
The container is already locked.
Return values:
node on success.
NULL on error or no more nodes in the container.

Definition at line 184 of file astobj2_container_private.h.

Definition at line 233 of file astobj2_container_private.h.

Definition at line 245 of file astobj2_container_private.h.


Enumeration Type Documentation

Enumerator:
AO2_CALLBACK_DEFAULT 
AO2_CALLBACK_WITH_DATA 

Definition at line 45 of file astobj2_container_private.h.

00045                        {
00046    AO2_CALLBACK_DEFAULT,
00047    AO2_CALLBACK_WITH_DATA,
00048 };

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.

00050                           {
00051    /*! The node was inserted into the container. */
00052    AO2_CONTAINER_INSERT_NODE_INSERTED,
00053    /*! The node object replaced an existing node object. */
00054    AO2_CONTAINER_INSERT_NODE_OBJ_REPLACED,
00055    /*! The node was rejected (duplicate). */
00056    AO2_CONTAINER_INSERT_NODE_REJECTED,
00057 };

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.

00033                            {
00034    /*! Remove the node from the object's weak link list
00035     * OR unref the object if it's a strong reference. */
00036    AO2_UNLINK_NODE_UNLINK_OBJECT = (1 << 0),
00037    /*! Modified unlink_object to skip the unref of the object. */
00038    AO2_UNLINK_NODE_NOUNREF_OBJECT = (1 << 1),
00039    /*! Unref the node. */
00040    AO2_UNLINK_NODE_UNREF_NODE = (1 << 2),
00041    /*! Decrement the container's element count. */
00042    AO2_UNLINK_NODE_DEC_COUNT = (1 << 3),
00043 };


Function Documentation

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 41 of file astobj2_container.c.

References __ao2_ref(), __ao2_ref_debug(), ao2_t_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, empty, ao2_container_node::my_container, NULL, ao2_container_node::obj, and ao2_container::v_table.

Referenced by internal_ao2_iterator_next(), and internal_ao2_traverse().

00043 {
00044    struct ao2_container *container = node->my_container;
00045 
00046    if (container == NULL && (flags & AO2_UNLINK_NODE_DEC_COUNT)) {
00047       return 0;
00048    }
00049 
00050    if ((flags & AO2_UNLINK_NODE_UNLINK_OBJECT)
00051       && !(flags & AO2_UNLINK_NODE_NOUNREF_OBJECT)) {
00052       if (tag) {
00053          __ao2_ref_debug(node->obj, -1, tag, file, line, func);
00054       } else {
00055          ao2_t_ref(node->obj, -1, "Remove obj from container");
00056       }
00057    }
00058 
00059    node->obj = NULL;
00060 
00061    if (flags & AO2_UNLINK_NODE_DEC_COUNT) {
00062       ast_atomic_fetchadd_int(&container->elements, -1);
00063 #if defined(AO2_DEBUG)
00064       {
00065          int empty = container->nodes - container->elements;
00066 
00067          if (container->max_empty_nodes < empty) {
00068             container->max_empty_nodes = empty;
00069          }
00070          if (container->v_table->unlink_stat) {
00071             container->v_table->unlink_stat(container, node);
00072          }
00073       }
00074 #endif   /* defined(AO2_DEBUG) */
00075    }
00076 
00077    if (flags & AO2_UNLINK_NODE_UNREF_NODE) {
00078       /* Remove node from container */
00079       __ao2_ref(node, -1);
00080    }
00081 
00082    return 1;
00083 }

void container_destruct ( void *  _c  ) 

Definition at line 656 of file astobj2_container.c.

References __ao2_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(), __ao2_container_alloc_hash_debug(), __ao2_container_alloc_rbtree(), and __ao2_container_alloc_rbtree_debug().

00657 {
00658    struct ao2_container *c = _c;
00659 
00660    /* Unlink any stored objects in the container. */
00661    c->destroying = 1;
00662    __ao2_callback(c, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL);
00663 
00664    /* Perform any extra container cleanup. */
00665    if (c->v_table && c->v_table->destroy) {
00666       c->v_table->destroy(c);
00667    }
00668 
00669 #if defined(AO2_DEBUG)
00670    ast_atomic_fetchadd_int(&ao2.total_containers, -1);
00671 #endif
00672 }

void container_destruct_debug ( void *  _c  ) 

Definition at line 674 of file astobj2_container.c.

References __ao2_callback_debug(), 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_debug(), and __ao2_container_alloc_rbtree_debug().

00675 {
00676    struct ao2_container *c = _c;
00677 
00678    /* Unlink any stored objects in the container. */
00679    c->destroying = 1;
00680    __ao2_callback_debug(c, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL,
00681       "container_destruct_debug called", __FILE__, __LINE__, __PRETTY_FUNCTION__);
00682 
00683    /* Perform any extra container cleanup. */
00684    if (c->v_table && c->v_table->destroy) {
00685       c->v_table->destroy(c);
00686    }
00687 
00688 #if defined(AO2_DEBUG)
00689    ast_atomic_fetchadd_int(&ao2.total_containers, -1);
00690 #endif
00691 }

int container_init ( void   ) 

Definition at line 1203 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().

01204 {
01205 #if defined(AO2_DEBUG)
01206    reg_containers = ao2_t_container_alloc_list(AO2_ALLOC_OPT_LOCK_RWLOCK,
01207       AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, ao2_reg_sort_cb, NULL,
01208       "Container registration container.");
01209    if (!reg_containers) {
01210       return -1;
01211    }
01212 
01213    ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
01214    ast_register_cleanup(container_cleanup);
01215 #endif   /* defined(AO2_DEBUG) */
01216 
01217    return 0;
01218 }


Variable Documentation

Insert a node into this container.

Parameters:
self Container to operate upon.
node Container node to insert into the container.
Returns:
enum ao2_container_insert value.


Generated on Thu Apr 16 06:29:01 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6