[asterisk-commits] twilson: branch twilson/config_work r366712 - in /team/twilson/config_work: ....
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed May 16 13:24:34 CDT 2012
Author: twilson
Date: Wed May 16 13:24:29 2012
New Revision: 366712
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=366712
Log:
Merge in unarrayification of ao2_global_obj and use it properly
Modified:
team/twilson/config_work/ (props changed)
team/twilson/config_work/apps/app_skel.c
team/twilson/config_work/include/asterisk/astobj2.h
team/twilson/config_work/include/asterisk/config_options.h
team/twilson/config_work/main/astobj2.c
team/twilson/config_work/main/config_options.c
team/twilson/config_work/main/udptl.c
team/twilson/config_work/tests/test_astobj2.c
Propchange: team/twilson/config_work/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed May 16 13:24:29 2012
@@ -1,1 +1,1 @@
-/trunk:1-366645
+/trunk:1-366689
Modified: team/twilson/config_work/apps/app_skel.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/apps/app_skel.c?view=diff&rev=366712&r1=366711&r2=366712
==============================================================================
--- team/twilson/config_work/apps/app_skel.c (original)
+++ team/twilson/config_work/apps/app_skel.c Wed May 16 13:24:29 2012
@@ -161,7 +161,7 @@
.cfg_offset = offsetof(struct skel_config, cfgs),
};
-static AO2_GLOBAL_OBJ_STATIC(globals, 1);
+static AO2_GLOBAL_OBJ_STATIC(globals);
CONFIG_INFO_STANDARD(cfg_info, "app_skel.conf", globals, skel_config_alloc,
.types = { &general_options, &private_options, NULL },
@@ -175,7 +175,7 @@
static void skel_pvt_cfg_unlink(struct skel_pvt_config *pcfg)
{
- RAII_VAR(struct skel_config *, cfg, ao2_global_obj_ref(globals, 0), ao2_cleanup);
+ RAII_VAR(struct skel_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
if (cfg && cfg->cfgs) {
ao2_unlink(cfg->cfgs, pcfg);
}
@@ -183,7 +183,7 @@
static struct skel_pvt_config *skel_pvt_find_cfg(struct skel_pvt *pvt)
{
- RAII_VAR(struct skel_config *, cfg, ao2_global_obj_ref(globals, 0), ao2_cleanup);
+ RAII_VAR(struct skel_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
if (cfg && cfg->cfgs) {
return ao2_find(cfg->cfgs, pvt->name, OBJ_KEY);
}
@@ -322,7 +322,7 @@
static void *skel_find_or_create_pvt(const char *category)
{
- RAII_VAR(struct skel_config *, cfg, ao2_global_obj_ref(globals, 0), ao2_cleanup);
+ RAII_VAR(struct skel_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
void *obj;
if (!cfg || !cfg->pvts || !(obj = ao2_find(cfg->pvts, category, OBJ_KEY))) {
return skel_pvt_alloc(category);
@@ -407,7 +407,7 @@
return NULL;
}
- if (!(cfg = ao2_global_obj_ref(globals, 0)) || !cfg->general) {
+ if (!(cfg = ao2_global_obj_ref(globals)) || !cfg->general) {
return NULL;
}
@@ -438,7 +438,7 @@
return NULL;
}
- if (!(cfg = ao2_global_obj_ref(globals, 0)) || !(cfg->cfgs && cfg->pvts)) {
+ if (!(cfg = ao2_global_obj_ref(globals)) || !(cfg->cfgs && cfg->pvts)) {
return NULL;
}
Modified: team/twilson/config_work/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/include/asterisk/astobj2.h?view=diff&rev=366712&r1=366711&r2=366712
==============================================================================
--- team/twilson/config_work/include/asterisk/astobj2.h (original)
+++ team/twilson/config_work/include/asterisk/astobj2.h Wed May 16 13:24:29 2012
@@ -565,188 +565,133 @@
void *ao2_object_get_lockaddr(void *obj);
-/*! Global ao2 array container base structure. */
+/*! Global ao2 object holder structure. */
struct ao2_global_obj {
- /*! Access lock to the global ao2 array container. */
+ /*! Access lock to the held ao2 object. */
ast_rwlock_t lock;
- /*! Number of elements in the global ao2 array container. */
- unsigned int num_elements;
- /*! Global ao2 array container array. */
- void *obj[0];
+ /*! Global ao2 object. */
+ void *obj;
};
/*!
- * \brief Define a structure to be used to hold a global array of ao2 objects, statically initialized.
+ * \brief Define a global object holder to be used to hold an ao2 object, statically initialized.
* \since 11.0
*
- * \param name This will be the name of the defined structure.
- * \param num_objects Number of ao2 objects to contain.
+ * \param name This will be the name of the object holder.
*
* \details
- * This macro creates a structure definition that can be used to
- * hold an array of ao2 objects accessible using an API. The
- * structure is allocated and initialized to be empty.
+ * This macro creates a global object holder that can be used to
+ * hold an ao2 object accessible using an API. The structure is
+ * allocated and initialized to be empty.
*
* Example usage:
* \code
- * static AO2_GLOBAL_OBJ_STATIC(global_cfg, 10);
+ * static AO2_GLOBAL_OBJ_STATIC(global_cfg);
* \endcode
*
- * This would define \c struct \c global_cfg, intended to hold
- * an array of ao2 objects accessible using an API.
+ * This defines global_cfg, intended to hold an ao2 object
+ * accessible using an API.
*/
#ifndef HAVE_PTHREAD_RWLOCK_INITIALIZER
-#define AO2_GLOBAL_OBJ_STATIC(name, num_objects) \
- struct name { \
- struct ao2_global_obj global; \
- void *objs[num_objects]; \
- } name; \
+#define AO2_GLOBAL_OBJ_STATIC(name) \
+ struct ao2_global_obj name; \
static void __attribute__((constructor)) __init_##name(void) \
{ \
- unsigned int idx = (num_objects); \
- ast_rwlock_init(&name.global.lock); \
- name.global.num_elements = idx; \
- while (idx--) { \
- name.global.obj[idx] = NULL; \
- } \
+ ast_rwlock_init(&name.lock); \
+ name.obj = NULL; \
} \
static void __attribute__((destructor)) __fini_##name(void) \
{ \
- unsigned int idx = (num_objects); \
- while (idx--) { \
- if (name.global.obj[idx]) { \
- ao2_ref(name.global.obj[idx], -1); \
- name.global.obj[idx] = NULL; \
- } \
+ if (name.obj) { \
+ ao2_ref(name.obj, -1); \
+ name.obj = NULL; \
} \
- ast_rwlock_destroy(&name.global.lock); \
+ ast_rwlock_destroy(&name.lock); \
} \
struct __dummy_##name
#else
-#define AO2_GLOBAL_OBJ_STATIC(name, num_objects) \
- struct name { \
- struct ao2_global_obj global; \
- void *objs[num_objects]; \
- } name = { \
- .global.lock = AST_RWLOCK_INIT_VALUE, \
- .global.num_elements = (num_objects), \
+#define AO2_GLOBAL_OBJ_STATIC(name) \
+ struct ao2_global_obj name = { \
+ .lock = AST_RWLOCK_INIT_VALUE, \
}
#endif
/*!
- * \brief Release all global ao2 objects in the global array.
+ * \brief Release the ao2 object held in the global holder.
* \since 11.0
*
- * \param array Global ao2 object array container.
+ * \param holder Global ao2 object holder.
* \param tag used for debugging
*
* \return Nothing
*/
-#define ao2_t_global_obj_release(array, tag) \
- __ao2_global_obj_release(&array.global, (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-#define ao2_global_obj_release(array) \
- __ao2_global_obj_release(&array.global, "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-
-void __ao2_global_obj_release(struct ao2_global_obj *array, const char *tag, const char *file, int line, const char *func, const char *name);
-
-/*!
- * \brief Replace a global ao2 object in the global array.
+#define ao2_t_global_obj_release(holder, tag) \
+ __ao2_global_obj_release(&holder, (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
+#define ao2_global_obj_release(holder) \
+ __ao2_global_obj_release(&holder, "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
+
+void __ao2_global_obj_release(struct ao2_global_obj *holder, const char *tag, const char *file, int line, const char *func, const char *name);
+
+/*!
+ * \brief Replace an ao2 object in the global holder.
* \since 11.0
*
- * \param array Global ao2 object array container.
- * \param idx Index to replace in the array.
- * \param obj Object to put into the array. Can be NULL.
+ * \param holder Global ao2 object holder.
+ * \param obj Object to put into the holder. Can be NULL.
* \param tag used for debugging
*
* \note This function automatically increases the reference
- * count to account for the reference that the global array now
+ * count to account for the reference that the global holder now
* holds to the object.
*
- * \retval Reference to previous global ao2 object stored at the index.
+ * \retval Reference to previous global ao2 object stored.
* \retval NULL if no object available.
*/
-#define ao2_t_global_obj_replace(array, idx, obj, tag) \
- __ao2_global_obj_replace(&array.global, (idx), (obj), 1, (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-#define ao2_global_obj_replace(array, idx, obj) \
- __ao2_global_obj_replace(&array.global, (idx), (obj), 1, "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-
-void *__ao2_global_obj_replace(struct ao2_global_obj *array, unsigned int idx, void *obj, int lock, const char *tag, const char *file, int line, const char *func, const char *name);
-
-/*!
- * \brief Replace a global ao2 object in the global array, throwing away any old object
+#define ao2_t_global_obj_replace(holder, obj, tag) \
+ __ao2_global_obj_replace(&holder, (obj), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
+#define ao2_global_obj_replace(holder, obj) \
+ __ao2_global_obj_replace(&holder, (obj), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
+
+void *__ao2_global_obj_replace(struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name);
+
+/*!
+ * \brief Replace an ao2 object in the global holder, throwing away any old object.
* \since 11.0
*
- * \param idx Index to replace in the array.
- * \param obj Object to put into the array. Can be NULL.
+ * \param holder Global ao2 object holder.
+ * \param obj Object to put into the holder. Can be NULL.
* \param tag used for debugging
*
* \note This function automatically increases the reference
- * count to account for the reference that the global array now
- * holds to the object. It also decreases the reference count
+ * count to account for the reference that the global holder now
+ * holds to the object. It also decreases the reference count
* of any object being replaced.
*
* \retval 0 The global object was previously empty
* \retval 1 The global object was not previously empty
*/
-#define ao2_t_global_obj_replace_unref(array, idx, obj, tag) \
- __ao2_global_obj_replace_unref(&array.global, (idx), (obj), 1, (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-#define ao2_global_obj_replace_unref(array, idx, obj) \
- __ao2_global_obj_replace_unref(&array.global, (idx), (obj), 1, "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-int __ao2_global_obj_replace_unref(struct ao2_global_obj *array, unsigned int idx, void *obj, int lock, const char *tag, const char *file, int line, const char *func, const char *name);
-
-/*!
- * \brief Write-lock a global object array
+#define ao2_t_global_obj_replace_unref(holder, obj, tag) \
+ __ao2_global_obj_replace_unref(&holder, (obj), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
+#define ao2_global_obj_replace_unref(holder, obj) \
+ __ao2_global_obj_replace_unref(&holder, (obj), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
+int __ao2_global_obj_replace_unref(struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name);
+
+/*!
+ * \brief Get a reference to the object stored in the global holder.
* \since 11.0
*
- * \param array The array to lock
- *
- * \retval 0 Success
- * \retval non-zero Failure
- */
-#define ao2_global_obj_wrlock(array) __ao2_global_obj_wrlock(&array.global, __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-int __ao2_global_obj_wrlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name);
-
-/*!
- * \brief Read-lock a global object array
- * \since 11.0
- *
- * \param array The array to lock
- *
- * \retval 0 Success
- * \retval non-zero Failure
- */
-#define ao2_global_obj_rdlock(array) __ao2_global_obj_wrlock(&array.global, __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-int __ao2_global_obj_rdlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name);
-
-/*!
- * \brief Unlock a global object array
- * \since 11.0
- *
- * param array The array to unlock
- *
- * \retval 0 Success
- * \retval non-zero Failure
- */
-#define ao2_global_obj_unlock(array) __ao2_global_obj_unlock(&array.global, __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-int __ao2_global_obj_unlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name);
-
-/*!
- * \brief Get a reference to the object stored in the ao2 global array.
- * \since 11.0
- *
- * \param array Global ao2 object array container.
- * \param idx Index to get an object reference in the array.
+ * \param holder Global ao2 object holder.
* \param tag used for debugging
*
- * \retval Reference to current global ao2 object stored at the index.
+ * \retval Reference to current ao2 object stored in the holder.
* \retval NULL if no object available.
*/
-#define ao2_t_global_obj_ref(array, idx, tag) \
- __ao2_global_obj_ref(&array.global, (idx), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-#define ao2_global_obj_ref(array, idx) \
- __ao2_global_obj_ref(&array.global, (idx), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
-
-void *__ao2_global_obj_ref(struct ao2_global_obj *array, unsigned int idx, const char *tag, const char *file, int line, const char *func, const char *name);
+#define ao2_t_global_obj_ref(holder, tag) \
+ __ao2_global_obj_ref(&holder, (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
+#define ao2_global_obj_ref(holder) \
+ __ao2_global_obj_ref(&holder, "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
+
+void *__ao2_global_obj_ref(struct ao2_global_obj *holder, const char *tag, const char *file, int line, const char *func, const char *name);
/*!
Modified: team/twilson/config_work/include/asterisk/config_options.h
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/include/asterisk/config_options.h?view=diff&rev=366712&r1=366711&r2=366712
==============================================================================
--- team/twilson/config_work/include/asterisk/config_options.h (original)
+++ team/twilson/config_work/include/asterisk/config_options.h Wed May 16 13:24:29 2012
@@ -145,7 +145,7 @@
struct ao2_container *opts; /*!< Internal use - options to parse */
aco_pre_apply_config pre_apply_config; /*!< A callback called after processing, but before changes are applied */
aco_snapshot_alloc snapshot_alloc; /*!< Allocate an object to hold all global configs and private containers */
- void *global_obj; /*!< The global object array that holds the user-defined config object */
+ struct ao2_global_obj *global_obj; /*!< The global object array that holds the user-defined config object */
void *new_config; /*!< Internal use - A cache of newly created config */
const char **preload; /*!< Categories to parse first. Do something like char *arr[] = {"general", NULL}; and do .preload = arr */
struct aco_type *types[]; /*!< The list of types for this config. Required. Use a sentinel! */
@@ -176,7 +176,7 @@
static struct aco_info name = { \
.module = AST_MODULE, \
.filename = fn, \
- .global_obj = &arr.global, \
+ .global_obj = &arr, \
.snapshot_alloc = alloc, \
__VA_ARGS__ \
};
Modified: team/twilson/config_work/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/astobj2.c?view=diff&rev=366712&r1=366711&r2=366712
==============================================================================
--- team/twilson/config_work/main/astobj2.c (original)
+++ team/twilson/config_work/main/astobj2.c Wed May 16 13:24:29 2012
@@ -634,40 +634,35 @@
}
-void __ao2_global_obj_release(struct ao2_global_obj *array, const char *tag, const char *file, int line, const char *func, const char *name)
-{
- unsigned int idx;
-
- if (!array) {
+void __ao2_global_obj_release(struct ao2_global_obj *holder, const char *tag, const char *file, int line, const char *func, const char *name)
+{
+ if (!holder) {
/* For sanity */
return;
}
- if (__ao2_global_obj_wrlock(array, file, line, func, name)) {
+ if (__ast_rwlock_wrlock(file, line, func, &holder->lock, name)) {
/* Could not get the write lock. */
return;
}
- /* Release all contained ao2 objects. */
- idx = array->num_elements;
- while (idx--) {
- if (array->obj[idx]) {
- __ao2_ref_debug(array->obj[idx], -1, tag, file, line, func);
- array->obj[idx] = NULL;
- }
- }
-
- __ao2_global_obj_unlock(array, file, line, func, name);
-}
-
-void *__ao2_global_obj_replace(struct ao2_global_obj *array, unsigned int idx, void *obj, int lock, const char *tag, const char *file, int line, const char *func, const char *name)
+ /* Release the held ao2 object. */
+ if (holder->obj) {
+ __ao2_ref_debug(holder->obj, -1, tag, file, line, func);
+ holder->obj = NULL;
+ }
+
+ __ast_rwlock_unlock(file, line, func, &holder->lock, name);
+}
+
+void *__ao2_global_obj_replace(struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name)
{
void *obj_old;
- if (!array || array->num_elements <= idx) {
+ if (!holder) {
/* For sanity */
return NULL;
}
- if (lock && __ao2_global_obj_wrlock(array, file, line, func, name)) {
+ if (__ast_rwlock_wrlock(file, line, func, &holder->lock, name)) {
/* Could not get the write lock. */
return NULL;
}
@@ -675,19 +670,19 @@
if (obj) {
__ao2_ref_debug(obj, +1, tag, file, line, func);
}
- obj_old = array->obj[idx];
- array->obj[idx] = obj;
-
- if (lock) {
- __ao2_global_obj_unlock(array, file, line, func, name);
- }
+ obj_old = holder->obj;
+ holder->obj = obj;
+
+ __ast_rwlock_unlock(file, line, func, &holder->lock, name);
return obj_old;
}
-int __ao2_global_obj_replace_unref(struct ao2_global_obj *array, unsigned int idx, void *obj, int lock, const char *tag, const char *file, int line, const char *func, const char *name)
-{
- void *obj_old = __ao2_global_obj_replace(array, idx, obj, lock, tag, file, line, func, name);
+int __ao2_global_obj_replace_unref(struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name)
+{
+ void *obj_old;
+
+ obj_old = __ao2_global_obj_replace(holder, obj, tag, file, line, func, name);
if (obj_old) {
__ao2_ref_debug(obj_old, -1, tag, file, line, func);
return 1;
@@ -695,40 +690,25 @@
return 0;
}
-int __ao2_global_obj_wrlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name)
-{
- return __ast_rwlock_wrlock(file, line, func, &array->lock, name);
-}
-
-int __ao2_global_obj_rdlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name)
-{
- return __ast_rwlock_rdlock(file, line, func, &array->lock, name);
-}
-
-int __ao2_global_obj_unlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name)
-{
- return __ast_rwlock_unlock(file, line, func, &array->lock, name);
-}
-
-void *__ao2_global_obj_ref(struct ao2_global_obj *array, unsigned int idx, const char *tag, const char *file, int line, const char *func, const char *name)
+void *__ao2_global_obj_ref(struct ao2_global_obj *holder, const char *tag, const char *file, int line, const char *func, const char *name)
{
void *obj;
- if (!array || array->num_elements <= idx) {
+ if (!holder) {
/* For sanity */
return NULL;
}
- if (__ao2_global_obj_rdlock(array, file, line, func, name)) {
+ if (__ast_rwlock_rdlock(file, line, func, &holder->lock, name)) {
/* Could not get the read lock. */
return NULL;
}
- obj = array->obj[idx];
+ obj = holder->obj;
if (obj) {
__ao2_ref_debug(obj, +1, tag, file, line, func);
}
- __ao2_global_obj_unlock(array, file, line, func, name);
+ __ast_rwlock_unlock(file, line, func, &holder->lock, name);
return obj;
}
Modified: team/twilson/config_work/main/config_options.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/config_options.c?view=diff&rev=366712&r1=366711&r2=366712
==============================================================================
--- team/twilson/config_work/main/config_options.c (original)
+++ team/twilson/config_work/main/config_options.c Wed May 16 13:24:29 2012
@@ -312,7 +312,7 @@
static int apply_config(struct aco_info *info)
{
- __ao2_global_obj_replace_unref(info->global_obj, 0, info->new_config, 1, "", __FILE__, __LINE__, __PRETTY_FUNCTION__, "info->global_obj");
+ ao2_global_obj_replace_unref(*info->global_obj, info->new_config);
return 0;
}
Modified: team/twilson/config_work/main/udptl.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/udptl.c?view=diff&rev=366712&r1=366711&r2=366712
==============================================================================
--- team/twilson/config_work/main/udptl.c (original)
+++ team/twilson/config_work/main/udptl.c Wed May 16 13:24:29 2012
@@ -186,7 +186,7 @@
unsigned int use_even_ports;
};
-static AO2_GLOBAL_OBJ_STATIC(globals, 1);
+static AO2_GLOBAL_OBJ_STATIC(globals);
struct udptl_config {
struct udptl_global_options *general;
@@ -946,7 +946,7 @@
int startplace;
int i;
long int flags;
- RAII_VAR(struct udptl_config *, cfg, ao2_global_obj_ref(globals, 0), ao2_cleanup);
+ RAII_VAR(struct udptl_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
if (!cfg || !cfg->general) {
ast_log(LOG_ERROR, "Could not access global udptl options!\n");
@@ -1352,7 +1352,7 @@
return NULL;
}
- if (!(cfg = ao2_global_obj_ref(globals, 0))) {
+ if (!(cfg = ao2_global_obj_ref(globals))) {
return CLI_FAILURE;
}
Modified: team/twilson/config_work/tests/test_astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/tests/test_astobj2.c?view=diff&rev=366712&r1=366711&r2=366712
==============================================================================
--- team/twilson/config_work/tests/test_astobj2.c (original)
+++ team/twilson/config_work/tests/test_astobj2.c Wed May 16 13:24:29 2012
@@ -567,7 +567,7 @@
return res;
}
-static AO2_GLOBAL_OBJ_STATIC(astobj2_array, 2);
+static AO2_GLOBAL_OBJ_STATIC(astobj2_holder);
AST_TEST_DEFINE(astobj2_test_3)
{
@@ -582,15 +582,15 @@
case TEST_INIT:
info->name = "astobj2_test3";
info->category = "/main/astobj2/";
- info->summary = "Test global ao2 array container";
+ info->summary = "Test global ao2 holder";
info->description =
- "This test is to see if the global ao2 array container works as intended.";
+ "This test is to see if the global ao2 holder works as intended.";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
- /* Put an object in index 0 */
+ /* Put an object in the holder */
obj = ao2_alloc(sizeof(struct test_obj), test_obj_destructor);
if (!obj) {
ast_test_status_update(test, "ao2_alloc failed.\n");
@@ -599,7 +599,7 @@
}
obj->destructor_count = &destructor_count;
obj->i = ++num_objects;
- obj2 = ao2_t_global_obj_replace(astobj2_array, 0, obj, "Save object in index 0");
+ obj2 = ao2_t_global_obj_replace(astobj2_holder, obj, "Save object in the holder");
if (obj2) {
ast_test_status_update(test, "Returned object not expected.\n");
res = AST_TEST_FAIL;
@@ -608,7 +608,7 @@
/* Save object for next check. */
obj3 = obj;
- /* Replace an object in index 0 */
+ /* Replace an object in the holder */
obj = ao2_alloc(sizeof(struct test_obj), test_obj_destructor);
if (!obj) {
ast_test_status_update(test, "ao2_alloc failed.\n");
@@ -617,7 +617,7 @@
}
obj->destructor_count = &destructor_count;
obj->i = ++num_objects;
- obj2 = ao2_t_global_obj_replace(astobj2_array, 0, obj, "Replace object in index 0");
+ obj2 = ao2_t_global_obj_replace(astobj2_holder, obj, "Replace object in the holder");
if (!obj2) {
ast_test_status_update(test, "Expected an object.\n");
res = AST_TEST_FAIL;
@@ -634,7 +634,7 @@
obj2 = NULL;
ao2_ref(obj, -1);
- /* Put an object in index 1 */
+ /* Replace with unref of an object in the holder */
obj = ao2_alloc(sizeof(struct test_obj), test_obj_destructor);
if (!obj) {
ast_test_status_update(test, "ao2_alloc failed.\n");
@@ -643,25 +643,23 @@
}
obj->destructor_count = &destructor_count;
obj->i = ++num_objects;
- obj2 = ao2_t_global_obj_replace(astobj2_array, 1, obj, "Save object in index 1");
- if (obj2) {
- ao2_ref(obj2, -1);
- ast_test_status_update(test, "Returned object not expected.\n");
+ if (!ao2_t_global_obj_replace_unref(astobj2_holder, obj, "Replace w/ unref object in the holder")) {
+ ast_test_status_update(test, "Expected an object to be replaced.\n");
res = AST_TEST_FAIL;
goto cleanup;
}
/* Save object for next check. */
obj3 = obj;
- /* Get a reference to the object in index 1. */
- obj = ao2_t_global_obj_ref(astobj2_array, 1, "Get reference of index 1 object");
+ /* Get reference to held object. */
+ obj = ao2_t_global_obj_ref(astobj2_holder, "Get a held object reference");
if (!obj) {
ast_test_status_update(test, "Expected an object.\n");
res = AST_TEST_FAIL;
goto cleanup;
}
if (obj != obj3) {
- ast_test_status_update(test, "Returned object not expected.\n");
+ ast_test_status_update(test, "Referenced object not expected object.\n");
res = AST_TEST_FAIL;
goto cleanup;
}
@@ -670,8 +668,8 @@
ao2_ref(obj, -1);
obj = NULL;
- /* Release all objects in the global array. */
- ao2_t_global_obj_release(astobj2_array, "Check release all objects");
+ /* Release the object in the global holder. */
+ ao2_t_global_obj_release(astobj2_holder, "Check release all objects");
destructor_count += num_objects;
if (0 < destructor_count) {
ast_test_status_update(test,
@@ -695,7 +693,7 @@
if (obj3) {
ao2_t_ref(obj3, -1, "Test cleanup external object 3");
}
- ao2_t_global_obj_release(astobj2_array, "Test cleanup array");
+ ao2_t_global_obj_release(astobj2_holder, "Test cleanup holder");
return res;
}
More information about the asterisk-commits
mailing list