[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r301779 - /team/dvossel/fixt...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 13 16:21:07 CST 2011


Author: dvossel
Date: Thu Jan 13 16:21:03 2011
New Revision: 301779

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=301779
Log:
ast_cap api performance improvements

Modified:
    team/dvossel/fixtheworld_phase1_step3/main/format_cap.c

Modified: team/dvossel/fixtheworld_phase1_step3/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format_cap.c?view=diff&rev=301779&r1=301778&r2=301779
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/format_cap.c Thu Jan 13 16:21:03 2011
@@ -129,31 +129,28 @@
 	}
 }
 
-void ast_cap_append(struct ast_cap *dst, const struct ast_cap *src)
-{
-	struct ast_format tmp_fmt;
-	struct ast_cap *tmp_cap = (struct ast_cap *) src;
-
-	if (!src) {
-		return;
-	}
-	/* for every format in src that is not in dst, add that
-	 * format to dst. */
-	ast_cap_iter_start(tmp_cap);
-	while (!ast_cap_iter_next(tmp_cap, &tmp_fmt)) {
-		if (!ast_cap_iscompatible(dst, &tmp_fmt)) {
-			ast_cap_add(dst, &tmp_fmt);
-		}
-	}
-	ast_cap_iter_end(tmp_cap);
-}
-
-
-static int copy_cb(void *obj, void *arg, int flag)
+static int append_cb(void *obj, void *arg, int flag)
 {
 	struct ast_cap *result = (struct ast_cap *) arg;
 	struct ast_format *format = (struct ast_format *) obj;
 
+	if (!ast_cap_iscompatible(result, format)) {
+		ast_cap_add(result, format);
+	}
+
+	return 0;
+}
+
+void ast_cap_append(struct ast_cap *dst, const struct ast_cap *src)
+{
+	ao2_callback(src->formats, OBJ_NODATA | OBJ_NOLOCK, append_cb, dst);
+}
+
+static int copy_cb(void *obj, void *arg, int flag)
+{
+	struct ast_cap *result = (struct ast_cap *) arg;
+	struct ast_format *format = (struct ast_format *) obj;
+
 	ast_cap_add(result, format);
 	return 0;
 }
@@ -161,7 +158,7 @@
 void ast_cap_copy2(struct ast_cap *dst, const struct ast_cap *src)
 {
 	ast_cap_remove_all(dst);
-	ao2_callback(src->formats, 0, copy_cb, dst);
+	ao2_callback(src->formats, OBJ_NODATA | OBJ_NOLOCK, copy_cb, dst);
 }
 
 struct ast_cap *ast_cap_copy(struct ast_cap *cap)
@@ -170,7 +167,7 @@
 	if (!dst) {
 		return NULL;
 	}
-	ao2_callback(cap->formats, OBJ_NODATA, copy_cb, dst);
+	ao2_callback(cap->formats, OBJ_NODATA | OBJ_NOLOCK, copy_cb, dst);
 	return dst;
 }
 
@@ -233,7 +230,7 @@
 	};
 
 	ao2_callback(cap->formats,
-		OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK,
+		OBJ_NODATA | OBJ_NOLOCK | OBJ_MULTIPLE | OBJ_UNLINK,
 		multiple_by_id_cb,
 		&data);
 
@@ -252,7 +249,7 @@
 	struct ao2_iterator it;
 	struct ast_format *tmp;
 
-	it = ao2_iterator_init(cap->formats, 0);
+	it = ao2_iterator_init(cap->formats, AO2_ITERATOR_DONTLOCK);
 	while ((tmp = ao2_iterator_next(&it))) {
 		if (AST_FORMAT_GET_TYPE(tmp->id) == type) {
 			ao2_unlink(cap->formats, tmp);
@@ -264,7 +261,7 @@
 
 void ast_cap_remove_all(struct ast_cap *cap)
 {
-	ao2_callback(cap->formats, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, NULL, NULL);
+	ao2_callback(cap->formats, OBJ_NODATA | OBJ_NOLOCK | OBJ_MULTIPLE | OBJ_UNLINK, NULL, NULL);
 }
 
 int ast_cap_iscompatible(const struct ast_cap *cap, const struct ast_format *format)
@@ -318,11 +315,11 @@
 	data.joint_found = 0;
 	data.joint_cap = NULL;
 
-	it = ao2_iterator_init(cap1->formats, 0);
+	it = ao2_iterator_init(cap1->formats, AO2_ITERATOR_DONTLOCK);
 	while ((tmp = ao2_iterator_next(&it))) {
 		data.format = tmp;
 		ao2_callback(cap2->formats,
-			OBJ_MULTIPLE | OBJ_NODATA,
+			OBJ_MULTIPLE | OBJ_NODATA | OBJ_NOLOCK,
 			find_joint_cb,
 			&data);
 		ao2_ref(tmp, -1);
@@ -341,7 +338,7 @@
 		return 0; /* if they are not the same size, they are not identical */
 	}
 
-	it = ao2_iterator_init(cap1->formats, 0);
+	it = ao2_iterator_init(cap1->formats, AO2_ITERATOR_DONTLOCK);
 	while ((tmp = ao2_iterator_next(&it))) {
 		if (!ast_cap_iscompatible(cap2, tmp)) {
 			ao2_ref(tmp, -1);
@@ -367,11 +364,11 @@
 	data.joint_cap = result;
 	data.joint_found = 0;
 
-	it = ao2_iterator_init(cap1->formats, 0);
+	it = ao2_iterator_init(cap1->formats, AO2_ITERATOR_DONTLOCK);
 	while ((tmp = ao2_iterator_next(&it))) {
 		data.format = tmp;
 		ao2_callback(cap2->formats,
-			OBJ_MULTIPLE | OBJ_NODATA,
+			OBJ_MULTIPLE | OBJ_NODATA | OBJ_NOLOCK,
 			find_joint_cb,
 			&data);
 		ao2_ref(tmp, -1);
@@ -395,11 +392,11 @@
 		.joint_found = 0,
 	};
 
-	it = ao2_iterator_init(cap1->formats, 0);
+	it = ao2_iterator_init(cap1->formats, AO2_ITERATOR_DONTLOCK);
 	while ((tmp = ao2_iterator_next(&it))) {
 		data.format = tmp;
 		ao2_callback(cap2->formats,
-			OBJ_MULTIPLE | OBJ_NODATA,
+			OBJ_MULTIPLE | OBJ_NODATA | OBJ_NOLOCK,
 			find_joint_cb,
 			&data);
 		ao2_ref(tmp, -1);
@@ -421,7 +418,7 @@
 
 	/* for each format in cap1, see if that format is
 	 * compatible with cap2. If so copy it to the result */
-	it = ao2_iterator_init(cap->formats, 0);
+	it = ao2_iterator_init(cap->formats, AO2_ITERATOR_DONTLOCK);
 	while ((tmp = ao2_iterator_next(&it))) {
 		if (AST_FORMAT_GET_TYPE(tmp->id) == ftype) {
 			/* copy format */
@@ -447,7 +444,7 @@
 	struct ao2_iterator it;
 	struct ast_format *tmp;
 
-	it = ao2_iterator_init(cap->formats, 0);
+	it = ao2_iterator_init(cap->formats, AO2_ITERATOR_DONTLOCK);
 	while ((tmp = ao2_iterator_next(&it))) {
 		if (AST_FORMAT_GET_TYPE(tmp->id) == type) {
 			ao2_ref(tmp, -1);
@@ -463,7 +460,7 @@
 
 void ast_cap_iter_start(struct ast_cap *cap)
 {
-	cap->it = ao2_iterator_init(cap->formats, 0);
+	cap->it = ao2_iterator_init(cap->formats, AO2_ITERATOR_DONTLOCK);
 }
 
 void ast_cap_iter_end(struct ast_cap *cap)
@@ -490,7 +487,7 @@
 	struct ao2_iterator it;
 	struct ast_format *tmp;
 
-	it = ao2_iterator_init(cap->formats, 0);
+	it = ao2_iterator_init(cap->formats, AO2_ITERATOR_DONTLOCK);
 	while ((tmp = ao2_iterator_next(&it))) {
 		res |= ast_format_to_iax2(tmp);
 		ao2_ref(tmp, -1);




More information about the asterisk-commits mailing list