[asterisk-commits] twilson: branch twilson/config_work r362141 - in /team/twilson/config_work: a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Apr 14 20:27:38 CDT 2012


Author: twilson
Date: Sat Apr 14 20:27:33 2012
New Revision: 362141

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=362141
Log:
Make aco_type opaque, simplify apply callback

Adds ao2_global_obj_replace_unref to throw away/unref any replaced
object.

Modified:
    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

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=362141&r1=362140&r2=362141
==============================================================================
--- team/twilson/config_work/apps/app_skel.c (original)
+++ team/twilson/config_work/apps/app_skel.c Sat Apr 14 20:27:33 2012
@@ -265,30 +265,17 @@
 
 static int skel_apply_config(void)
 {
-	void *old;
-	void *array[NUM_GLOBAL_OBJECTS];
-	int i;
-	RAII_VAR(struct aco_type *, glob, NULL, ao2_cleanup);
-	RAII_VAR(struct aco_type *, priv, NULL, ao2_cleanup);
-
-	if (!(glob = aco_type_find(&cfg_info, "global"))) {
+	RAII_VAR(void *, new_global, aco_info_new_global_get(&cfg_info, "global"), ao2_cleanup);
+	RAII_VAR(struct ao2_container *, new_pvts, aco_info_new_privates_get(&cfg_info, "private"), ao2_cleanup);
+	RAII_VAR(struct ao2_container *, new_cfgs, aco_info_new_configs_get(&cfg_info, "private"), ao2_cleanup);
+
+	if (!(new_global && new_pvts && new_cfgs)) {
 		return -1;
 	}
-	if (!(priv = aco_type_find(&cfg_info, "private"))) {
-		return -1;
-	}
-
-	array[GLOBAL_OPTIONS] = glob->new_global_cfg;
-	array[PVT_CONTAINER] = priv->new_pvts;
-	array[PVT_CFG_CONTAINER] = priv->new_cfgs;
-
-	for (i = 0; i < NUM_GLOBAL_OBJECTS; i++) {
-		if ((old = ao2_global_obj_replace(global_config, i, array[i]))) {
-			/* There was an existing config */
-			ao2_ref(old, -1);
-		}
-		/* the "alloc" ref will be cleaned up by the caller */
-	}
+
+	ao2_global_obj_replace_unref(global_config, GLOBAL_OPTIONS, new_global);
+	ao2_global_obj_replace_unref(global_config, PVT_CONTAINER, new_pvts);
+	ao2_global_obj_replace_unref(global_config, PVT_CFG_CONTAINER, new_cfgs);
 
 	return 0;
 }

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=362141&r1=362140&r2=362141
==============================================================================
--- team/twilson/config_work/include/asterisk/astobj2.h (original)
+++ team/twilson/config_work/include/asterisk/astobj2.h Sat Apr 14 20:27:33 2012
@@ -671,6 +671,28 @@
 	__ao2_global_obj_replace(&array.global, (idx), (obj), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
 
 void *__ao2_global_obj_replace(struct ao2_global_obj *array, unsigned int idx, void *obj, 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
+ * \since 11.0
+ *
+ * \param idx Index to replace in the array.
+ * \param obj Object to put into the array.  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
+ * 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), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
+#define ao2_global_obj_replace_unref(array, idx, obj)	\
+	__ao2_global_obj_replace_unref(&array.global, (idx), (obj), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
+int __ao2_global_obj_replace_unref(struct ao2_global_obj *array, unsigned int idx, 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 ao2 global array.

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=362141&r1=362140&r2=362141
==============================================================================
--- team/twilson/config_work/include/asterisk/config_options.h (original)
+++ team/twilson/config_work/include/asterisk/config_options.h Sat Apr 14 20:27:33 2012
@@ -53,32 +53,7 @@
 typedef int (*aco_type_post_cfg_init)(void *newcfg);
 typedef int (*aco_type_prelink)(void *newcfg);
 
-/* ao2 lookup by context, OBJ_KEY, only access with a global reload lock held */
-struct aco_type {
-	/* common stuff */
-	enum aco_type_t type;
-	const char *name;
-	const char *context;
-	const char *matchfield;
-	const char *matchvalue;
-	regex_t *regex;
-	enum aco_context_op context_allow;
-	aco_type_alloc cfg_alloc;
-
-	/* non-global callbacks */
-	aco_type_containers_alloc containers_alloc; /* required. cfgs required, pvts if non-config-related state */
-	aco_type_find_or_create_pvt find_or_create_pvt; /* required if there is non-config-related state */
-	aco_type_find_pvt find_pvt; /* required if there is non-config-related state */
-	aco_type_post_cfg_init post_cfg_init; /*!< Filter global options done if necessary */
-	aco_type_prelink prelink; /* optional, can be used to do additional checks on a config */
-
-	/* global cached object */
-	void *new_global_cfg; /* This is a cache and the reason we need locks */
-
-	/* non-global cached objects */
-	struct ao2_container *new_pvts; /* required if there is non-config-related state */
-	struct ao2_container *new_cfgs; /* required */
-};
+struct aco_type;
 
 struct ao2_container *aco_type_container_new(void);
 struct aco_type *aco_type_global_alloc(const char *name, enum aco_context_op op, const char *context, aco_type_alloc alloc);
@@ -101,6 +76,10 @@
 void aco_info_destroy(struct aco_info *info);
 int aco_type_register(struct aco_info *info, struct aco_type *obj);
 struct aco_type *aco_type_find(struct aco_info *info, const char *name); 
+
+void *aco_info_new_global_get(struct aco_info *info, const char *name);
+struct ao2_container *aco_info_new_privates_get(struct aco_info *info, const char *name);
+struct ao2_container *aco_info_new_configs_get(struct aco_info *info, const char *name);
 
 /*! \brief The option types with default handlers
  *

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=362141&r1=362140&r2=362141
==============================================================================
--- team/twilson/config_work/main/astobj2.c (original)
+++ team/twilson/config_work/main/astobj2.c Sat Apr 14 20:27:33 2012
@@ -686,6 +686,16 @@
 	__ast_rwlock_unlock(file, line, func, &array->lock, name);
 
 	return obj_old;
+}
+
+int __ao2_global_obj_replace_unref(struct ao2_global_obj *array, unsigned int idx, void *obj, const char *tag, const char *file, int line, const char *func, const char *name)
+{
+	void *obj_old = __ao2_global_obj_replace(array, idx, obj, tag, file, line, func, name);
+	if (obj_old) {
+		__ao2_ref_debug(obj_old, -1, tag, file, line, func);
+		return 1;
+	}
+	return 0;
 }
 
 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)

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=362141&r1=362140&r2=362141
==============================================================================
--- team/twilson/config_work/main/config_options.c (original)
+++ team/twilson/config_work/main/config_options.c Sat Apr 14 20:27:33 2012
@@ -39,6 +39,35 @@
 #define CONFIG_OPT_BUCKETS 53
 #endif /* LOW_MEMORY */
 
+/*! \struct aco_type
+ * \brief Type information about a category-level configurable object
+ */
+struct aco_type {
+	/* common stuff */
+	enum aco_type_t type;
+	const char *name;
+	const char *context;
+	const char *matchfield;
+	const char *matchvalue;
+	regex_t *regex;
+	enum aco_context_op context_allow;
+	aco_type_alloc cfg_alloc;
+
+	/* non-global callbacks */
+	aco_type_containers_alloc containers_alloc; /* required. cfgs required, pvts if non-config-related state */
+	aco_type_find_or_create_pvt find_or_create_pvt; /* required if there is non-config-related state */
+	aco_type_find_pvt find_pvt; /* required if there is non-config-related state */
+	aco_type_post_cfg_init post_cfg_init; /*!< Filter global options done if necessary */
+	aco_type_prelink prelink; /* optional, can be used to do additional checks on a config */
+
+	/* global cached object */
+	void *new_global_cfg; /* This is a cache and the reason we need locks */
+
+	/* non-global cached objects */
+	struct ao2_container *new_pvts; /* required if there is non-config-related state */
+	struct ao2_container *new_cfgs; /* required */
+};
+
 struct aco_option {
 	const char *name;
 	const char *default_val;
@@ -593,12 +622,54 @@
 
 int aco_type_register(struct aco_info *info, struct aco_type *obj)
 {
+	if (!info->objs) {
+		return -1;
+	}
 	return !ao2_link(info->objs, obj);
 }
 
 struct aco_type *aco_type_find(struct aco_info *info, const char *name)
 {
+	if (!info->objs) {
+		return NULL;
+	}
 	return ao2_find(info->objs, name, OBJ_KEY);
+}
+
+void *aco_info_new_global_get(struct aco_info *info, const char *name)
+{
+	RAII_VAR(struct aco_type *, type, aco_type_find(info, name), ao2_cleanup); 
+	if (!type) {
+		return NULL;
+	}
+	if (type->new_global_cfg) {
+		ao2_ref(type->new_global_cfg, +1);
+	}
+	return type->new_global_cfg;
+}
+
+struct ao2_container *aco_info_new_privates_get(struct aco_info *info, const char *name)
+{
+	RAII_VAR(struct aco_type *, type, aco_type_find(info, name), ao2_cleanup); 
+	if (!type) {
+		return NULL;
+	}
+	if (type->new_pvts) {
+		ao2_ref(type->new_pvts, +1);
+	}
+	return type->new_pvts;
+}
+
+struct ao2_container *aco_info_new_configs_get(struct aco_info *info, const char *name)
+{
+	RAII_VAR(struct aco_type *, type, aco_type_find(info, name), ao2_cleanup); 
+	if (!type) {
+		return NULL;
+	}
+	if (type->new_cfgs) {
+		ao2_ref(type->new_cfgs, +1);
+	}
+	return type->new_cfgs;
 }
 
 /* default config option handlers */




More information about the asterisk-commits mailing list