[asterisk-commits] rmudgett: branch rmudgett/ao2_enhancements r342601 - in /team/rmudgett/ao2_en...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Oct 27 13:12:02 CDT 2011


Author: rmudgett
Date: Thu Oct 27 13:11:58 2011
New Revision: 342601

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=342601
Log:
Add non-t version of ao2_t_container_alloc_options()

Modified:
    team/rmudgett/ao2_enhancements/include/asterisk/astobj2.h
    team/rmudgett/ao2_enhancements/main/format.c

Modified: team/rmudgett/ao2_enhancements/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ao2_enhancements/include/asterisk/astobj2.h?view=diff&rev=342601&r1=342600&r2=342601
==============================================================================
--- team/rmudgett/ao2_enhancements/include/asterisk/astobj2.h (original)
+++ team/rmudgett/ao2_enhancements/include/asterisk/astobj2.h Thu Oct 27 13:11:58 2011
@@ -420,6 +420,9 @@
 
 #define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg) \
 	__ao2_alloc_debug((data_size), (destructor_fn), (options), (debug_msg),  __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
+#define ao2_alloc_options(data_size, destructor_fn, options) \
+	__ao2_alloc_debug((data_size), (destructor_fn), (options), "",  __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
+
 #define ao2_t_alloc(data_size, destructor_fn, debug_msg) \
 	__ao2_alloc_debug((data_size), (destructor_fn), AO2_ALLOC_OPT_LOCK_MUTEX, (debug_msg),  __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
 #define ao2_alloc(data_size, destructor_fn) \
@@ -429,6 +432,9 @@
 
 #define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg) \
 	__ao2_alloc_debug((data_size), (destructor_fn), (options), (debug_msg),  __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
+#define ao2_alloc_options(data_size, destructor_fn, options) \
+	__ao2_alloc_debug((data_size), (destructor_fn), (options), "",  __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
+
 #define ao2_t_alloc(data_size, destructor_fn, debug_msg) \
 	__ao2_alloc_debug((data_size), (destructor_fn), AO2_ALLOC_OPT_LOCK_MUTEX, (debug_msg),  __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
 #define ao2_alloc(data_size, destructor_fn) \
@@ -438,6 +444,9 @@
 
 #define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg) \
 	__ao2_alloc((data_size), (destructor_fn), (options))
+#define ao2_alloc_options(data_size, destructor_fn, options) \
+	__ao2_alloc((data_size), (destructor_fn), (options))
+
 #define ao2_t_alloc(data_size, destructor_fn, debug_msg) \
 	__ao2_alloc((data_size), (destructor_fn), AO2_ALLOC_OPT_LOCK_MUTEX)
 #define ao2_alloc(data_size, destructor_fn) \
@@ -780,10 +789,11 @@
 
 #define ao2_t_container_alloc_options(options, n_buckets, hash_fn, cmp_fn, tag) \
 	__ao2_container_alloc_debug((options), (n_buckets), (hash_fn), (cmp_fn), (tag),  __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
+#define ao2_container_alloc_options(options, n_buckets, hash_fn, cmp_fn) \
+	__ao2_container_alloc_debug((options), (n_buckets), (hash_fn), (cmp_fn), "",  __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
+
 #define ao2_t_container_alloc(n_buckets, hash_fn, cmp_fn, tag) \
 	__ao2_container_alloc_debug(AO2_ALLOC_OPT_LOCK_MUTEX, (n_buckets), (hash_fn), (cmp_fn), (tag),  __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
-#define ao2_container_alloc_options(options, n_buckets, hash_fn, cmp_fn) \
-	__ao2_container_alloc_debug((options), (n_buckets), (hash_fn), (cmp_fn), "",  __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
 #define ao2_container_alloc(n_buckets, hash_fn, cmp_fn) \
 	__ao2_container_alloc_debug(AO2_ALLOC_OPT_LOCK_MUTEX, (n_buckets), (hash_fn), (cmp_fn), "",  __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
 
@@ -791,10 +801,11 @@
 
 #define ao2_t_container_alloc_options(options, n_buckets, hash_fn, cmp_fn, tag) \
 	__ao2_container_alloc_debug((options), (n_buckets), (hash_fn), (cmp_fn), (tag),  __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
+#define ao2_container_alloc_options(options, n_buckets, hash_fn, cmp_fn) \
+	__ao2_container_alloc_debug((options), (n_buckets), (hash_fn), (cmp_fn), "",  __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
+
 #define ao2_t_container_alloc(n_buckets, hash_fn, cmp_fn, tag) \
 	__ao2_container_alloc_debug(AO2_ALLOC_OPT_LOCK_MUTEX, (n_buckets), (hash_fn), (cmp_fn), (tag),  __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
-#define ao2_container_alloc_options(options, n_buckets, hash_fn, cmp_fn) \
-	__ao2_container_alloc_debug((options), (n_buckets), (hash_fn), (cmp_fn), "",  __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
 #define ao2_container_alloc(n_buckets, hash_fn, cmp_fn) \
 	__ao2_container_alloc_debug(AO2_ALLOC_OPT_LOCK_MUTEX, (n_buckets), (hash_fn), (cmp_fn), "",  __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
 
@@ -802,10 +813,11 @@
 
 #define ao2_t_container_alloc_options(options, n_buckets, hash_fn, cmp_fn, tag) \
 	__ao2_container_alloc((options), (n_buckets), (hash_fn), (cmp_fn))
+#define ao2_container_alloc_options(options, n_buckets, hash_fn, cmp_fn) \
+	__ao2_container_alloc((options), (n_buckets), (hash_fn), (cmp_fn))
+
 #define ao2_t_container_alloc(n_buckets, hash_fn, cmp_fn, tag) \
 	__ao2_container_alloc(AO2_ALLOC_OPT_LOCK_MUTEX, (n_buckets), (hash_fn), (cmp_fn))
-#define ao2_container_alloc_options(options, n_buckets, hash_fn, cmp_fn) \
-	__ao2_container_alloc((options), (n_buckets), (hash_fn), (cmp_fn))
 #define ao2_container_alloc(n_buckets, hash_fn, cmp_fn) \
 	__ao2_container_alloc(AO2_ALLOC_OPT_LOCK_MUTEX, (n_buckets), (hash_fn), (cmp_fn))
 
@@ -853,6 +865,7 @@
 
 #define ao2_t_link(container, obj, tag)        __ao2_link_debug((container), (obj), 0, (tag),  __FILE__, __LINE__, __PRETTY_FUNCTION__)
 #define ao2_link(container, obj)               __ao2_link_debug((container), (obj), 0, "",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
 #define ao2_t_link_nolock(container, obj, tag) __ao2_link_debug((container), (obj), OBJ_NOLOCK, (tag),  __FILE__, __LINE__, __PRETTY_FUNCTION__)
 #define ao2_link_nolock(container, obj)        __ao2_link_debug((container), (obj), OBJ_NOLOCK, "",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
 
@@ -860,6 +873,7 @@
 
 #define ao2_t_link(container, obj, tag)        __ao2_link((container), (obj), 0)
 #define ao2_link(container, obj)               __ao2_link((container), (obj), 0)
+
 #define ao2_t_link_nolock(container, obj, tag) __ao2_link((container), (obj), OBJ_NOLOCK)
 #define ao2_link_nolock(container, obj)        __ao2_link((container), (obj), OBJ_NOLOCK)
 
@@ -889,6 +903,7 @@
 
 #define ao2_t_unlink(container, obj, tag)        __ao2_unlink_debug((container), (obj), 0, (tag),  __FILE__, __LINE__, __PRETTY_FUNCTION__)
 #define ao2_unlink(container, obj)               __ao2_unlink_debug((container), (obj), 0, "",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
 #define ao2_t_unlink_nolock(container, obj, tag) __ao2_unlink_debug((container), (obj), OBJ_NOLOCK, (tag),  __FILE__, __LINE__, __PRETTY_FUNCTION__)
 #define ao2_unlink_nolock(container, obj)        __ao2_unlink_debug((container), (obj), OBJ_NOLOCK, "",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
 
@@ -896,6 +911,7 @@
 
 #define ao2_t_unlink(container, obj, tag)        __ao2_unlink((container), (obj), 0)
 #define ao2_unlink(container, obj)               __ao2_unlink((container), (obj), 0)
+
 #define ao2_t_unlink_nolock(container, obj, tag) __ao2_unlink((container), (obj), OBJ_NOLOCK)
 #define ao2_unlink_nolock(container, obj)        __ao2_unlink((container), (obj), OBJ_NOLOCK)
 

Modified: team/rmudgett/ao2_enhancements/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ao2_enhancements/main/format.c?view=diff&rev=342601&r1=342600&r2=342601
==============================================================================
--- team/rmudgett/ao2_enhancements/main/format.c (original)
+++ team/rmudgett/ao2_enhancements/main/format.c Thu Oct 27 13:11:58 2011
@@ -53,10 +53,6 @@
 struct interface_ao2_wrapper {
 	enum ast_format_id id;
 	const struct ast_format_attr_interface *interface;
-/* BUGBUG wrapper can be created with RWLOCKs now */
-	/*! a read write lock must be used to protect the wrapper instead
-	 * of the ao2 lock. */
-	ast_rwlock_t wraplock;
 };
 
 /* BUGBUG v--- This may benefit from the global ao2 object enhancements. */
@@ -86,12 +82,6 @@
 	return wrapper->id;
 }
 
-static void interface_destroy_cb(void *obj)
-{
-	struct interface_ao2_wrapper *wrapper = obj;
-	ast_rwlock_destroy(&wrapper->wraplock);
-}
-
 void ast_format_copy(struct ast_format *dst, const struct ast_format *src)
 {
 	memcpy(dst, src, sizeof(struct ast_format));
@@ -140,16 +130,16 @@
 		return -1;
 	}
 
-	ast_rwlock_rdlock(&wrapper->wraplock);
+	ao2_rdlock(wrapper);
 	if (!wrapper->interface || !wrapper->interface->format_attr_set) {
-		ast_rwlock_unlock(&wrapper->wraplock);
+		ao2_unlock(wrapper);
 		ao2_ref(wrapper, -1);
 		return -1;
 	}
 
 	wrapper->interface->format_attr_set(&format->fattr, ap);
 
-	ast_rwlock_unlock(&wrapper->wraplock);
+	ao2_unlock(wrapper);
 	ao2_ref(wrapper, -1);
 
 	return 0;
@@ -204,12 +194,12 @@
 		return -1;
 	}
 
-	ast_rwlock_rdlock(&wrapper->wraplock);
+	ao2_rdlock(wrapper);
 	if (!wrapper->interface ||
 		!wrapper->interface->format_attr_set ||
 		!wrapper->interface->format_attr_cmp) {
 
-		ast_rwlock_unlock(&wrapper->wraplock);
+		ao2_unlock(wrapper);
 		ao2_ref(wrapper, -1);
 		return -1;
 	}
@@ -225,7 +215,7 @@
 		res = (res == AST_FORMAT_CMP_NOT_EQUAL) ? -1 : 0;
 	}
 
-	ast_rwlock_unlock(&wrapper->wraplock);
+	ao2_unlock(wrapper);
 	ao2_ref(wrapper, -1);
 
 	return res;
@@ -246,21 +236,22 @@
 {
 	int res = 0;
 	struct interface_ao2_wrapper *wrapper;
+
 	if (!(wrapper = find_interface(format))) {
 		return -1;
 	}
-	ast_rwlock_rdlock(&wrapper->wraplock);
+	ao2_rdlock(wrapper);
 	if (!wrapper->interface ||
 		!wrapper->interface->format_attr_get_val) {
 
-		ast_rwlock_unlock(&wrapper->wraplock);
+		ao2_unlock(wrapper);
 		ao2_ref(wrapper, -1);
 		return -1;
 	}
 
 	res = wrapper->interface->format_attr_get_val(&format->fattr, key, value);
 
-	ast_rwlock_unlock(&wrapper->wraplock);
+	ao2_unlock(wrapper);
 	ao2_ref(wrapper, -1);
 
 	return res;
@@ -278,16 +269,16 @@
 		return res;
 	}
 
-	ast_rwlock_rdlock(&wrapper->wraplock);
+	ao2_rdlock(wrapper);
 	if (!wrapper->interface || !wrapper->interface->format_attr_cmp) {
-		ast_rwlock_unlock(&wrapper->wraplock);
+		ao2_unlock(wrapper);
 		ao2_ref(wrapper, -1);
 		return res;
 	}
 
 	res = wrapper->interface->format_attr_cmp(&format1->fattr, &format2->fattr);
 
-	ast_rwlock_unlock(&wrapper->wraplock);
+	ao2_unlock(wrapper);
 	ao2_ref(wrapper, -1);
 
 	return res;
@@ -315,11 +306,11 @@
 		return res;
 	}
 
-	ast_rwlock_rdlock(&wrapper->wraplock);
+	ao2_rdlock(wrapper);
 	if (wrapper->interface && wrapper->interface->format_attr_get_joint) {
 		res = wrapper->interface->format_attr_get_joint(&format1->fattr, &format2->fattr, &result->fattr);
 	}
-	ast_rwlock_unlock(&wrapper->wraplock);
+	ao2_unlock(wrapper);
 
 	ao2_ref(wrapper, -1);
 
@@ -1310,15 +1301,14 @@
 		return -1;
 	}
 
-/* BUGBUG wrapper can be created with RWLOCKs now */
-	if (!(wrapper = ao2_alloc(sizeof(*wrapper), interface_destroy_cb))) {
+	wrapper = ao2_alloc_options(sizeof(*wrapper), NULL, AO2_ALLOC_OPT_LOCK_RWLOCK);
+	if (!wrapper) {
 		ao2_unlock(interfaces);
 		return -1;
 	}
 
 	wrapper->interface = interface;
 	wrapper->id = interface->id;
-	ast_rwlock_init(&wrapper->wraplock);
 
 	/* The write lock is already held. */
 	ao2_link_nolock(interfaces, wrapper);
@@ -1354,9 +1344,9 @@
 		return -1;
 	}
 
-	ast_rwlock_wrlock(&wrapper->wraplock);
+	ao2_wrlock(wrapper);
 	wrapper->interface = NULL;
-	ast_rwlock_unlock(&wrapper->wraplock);
+	ao2_unlock(wrapper);
 
 	ao2_ref(wrapper, -1);
 




More information about the asterisk-commits mailing list