[asterisk-commits] rmudgett: branch rmudgett/ao2_enhancements r342600 - /team/rmudgett/ao2_enhan...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Oct 27 12:18:08 CDT 2011
Author: rmudgett
Date: Thu Oct 27 12:18:05 2011
New Revision: 342600
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=342600
Log:
Simplify struct ast_format_cap code to take advantage of ao2 objects without a lock.
Modified:
team/rmudgett/ao2_enhancements/main/format_cap.c
Modified: team/rmudgett/ao2_enhancements/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ao2_enhancements/main/format_cap.c?view=diff&rev=342600&r1=342599&r2=342600
==============================================================================
--- team/rmudgett/ao2_enhancements/main/format_cap.c (original)
+++ team/rmudgett/ao2_enhancements/main/format_cap.c Thu Oct 27 12:18:05 2011
@@ -40,6 +40,7 @@
/* The capabilities structure is just an ao2 container of ast_formats */
struct ao2_container *formats;
struct ao2_iterator it;
+ /*! TRUE if the formats container created without a lock. */
int nolock;
};
@@ -70,8 +71,11 @@
if (!cap) {
return NULL;
}
- cap->nolock = nolock ? OBJ_NOLOCK : 0;
- if (!(cap->formats = ao2_container_alloc(283, hash_cb, cmp_cb))) {
+ cap->nolock = nolock;
+ cap->formats = ao2_container_alloc_options(
+ nolock ? AO2_ALLOC_OPT_LOCK_NOLOCK : AO2_ALLOC_OPT_LOCK_MUTEX,
+ 283, hash_cb, cmp_cb);
+ if (!cap->formats) {
ast_free(cap);
return NULL;
}
@@ -110,11 +114,7 @@
return;
}
ast_format_copy(fnew, format);
- if (cap->nolock) {
- ao2_link_nolock(cap->formats, fnew);
- } else {
- ao2_link(cap->formats, fnew);
- }
+ ao2_link(cap->formats, fnew);
ao2_ref(fnew, -1);
}
@@ -158,7 +158,7 @@
void ast_format_cap_append(struct ast_format_cap *dst, const struct ast_format_cap *src)
{
- ao2_callback(src->formats, OBJ_NODATA | src->nolock, append_cb, dst);
+ ao2_callback(src->formats, OBJ_NODATA, append_cb, dst);
}
static int copy_cb(void *obj, void *arg, int flag)
@@ -173,7 +173,7 @@
void ast_format_cap_copy(struct ast_format_cap *dst, const struct ast_format_cap *src)
{
ast_format_cap_remove_all(dst);
- ao2_callback(src->formats, OBJ_NODATA | src->nolock, copy_cb, dst);
+ ao2_callback(src->formats, OBJ_NODATA, copy_cb, dst);
}
struct ast_format_cap *ast_format_cap_dup(const struct ast_format_cap *cap)
@@ -187,7 +187,7 @@
if (!dst) {
return NULL;
}
- ao2_callback(cap->formats, OBJ_NODATA | cap->nolock, copy_cb, dst);
+ ao2_callback(cap->formats, OBJ_NODATA, copy_cb, dst);
return dst;
}
@@ -210,8 +210,8 @@
int ast_format_cap_remove(struct ast_format_cap *cap, struct ast_format *format)
{
struct ast_format *fremove;
- fremove = ao2_callback(cap->formats, OBJ_POINTER | OBJ_UNLINK | cap->nolock, find_exact_cb, format);
-
+
+ fremove = ao2_callback(cap->formats, OBJ_POINTER | OBJ_UNLINK, find_exact_cb, format);
if (fremove) {
ao2_ref(fremove, -1);
return 0;
@@ -250,7 +250,7 @@
};
ao2_callback(cap->formats,
- OBJ_NODATA | cap->nolock | OBJ_MULTIPLE | OBJ_UNLINK,
+ OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK,
multiple_by_id_cb,
&data);
@@ -272,14 +272,14 @@
void ast_format_cap_remove_bytype(struct ast_format_cap *cap, enum ast_format_type type)
{
ao2_callback(cap->formats,
- OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE | cap->nolock,
+ OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE,
multiple_by_type_cb,
&type);
}
void ast_format_cap_remove_all(struct ast_format_cap *cap)
{
- ao2_callback(cap->formats, OBJ_NODATA | cap->nolock | OBJ_MULTIPLE | OBJ_UNLINK, NULL, NULL);
+ ao2_callback(cap->formats, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, NULL, NULL);
}
void ast_format_cap_set(struct ast_format_cap *cap, struct ast_format *format)
@@ -292,8 +292,8 @@
{
struct ast_format *f;
struct ast_format_cap *tmp_cap = (struct ast_format_cap *) cap;
- f = ao2_find(tmp_cap->formats, (struct ast_format *) format, OBJ_POINTER | tmp_cap->nolock);
-
+
+ f = ao2_find(tmp_cap->formats, format, OBJ_POINTER);
if (f) {
ast_format_copy(result, f);
ao2_ref(f, -1);
@@ -311,7 +311,8 @@
if (!tmp_cap) {
return 0;
}
- f = ao2_find(tmp_cap->formats, (struct ast_format *) format, OBJ_POINTER | tmp_cap->nolock);
+
+ f = ao2_find(tmp_cap->formats, format, OBJ_POINTER);
if (f) {
ao2_ref(f, -1);
return 1;
@@ -346,7 +347,7 @@
ast_format_clear(result);
ao2_callback(cap->formats,
- OBJ_MULTIPLE | OBJ_NODATA | cap->nolock,
+ OBJ_MULTIPLE | OBJ_NODATA,
find_best_byid_cb,
&data);
return result->id ? 1 : 0;
@@ -390,11 +391,11 @@
.joint_cap = NULL,
};
- it = ao2_iterator_init(cap1->formats, cap1->nolock ? AO2_ITERATOR_DONTLOCK : 0);
+ it = ao2_iterator_init(cap1->formats, 0);
while ((tmp = ao2_iterator_next(&it))) {
data.format = tmp;
ao2_callback(cap2->formats,
- OBJ_MULTIPLE | OBJ_NODATA | cap2->nolock,
+ OBJ_MULTIPLE | OBJ_NODATA,
find_joint_cb,
&data);
ao2_ref(tmp, -1);
@@ -413,7 +414,7 @@
return 0; /* if they are not the same size, they are not identical */
}
- it = ao2_iterator_init(cap1->formats, cap1->nolock ? AO2_ITERATOR_DONTLOCK : 0);
+ it = ao2_iterator_init(cap1->formats, 0);
while ((tmp = ao2_iterator_next(&it))) {
if (!ast_format_cap_iscompatible(cap2, tmp)) {
ao2_ref(tmp, -1);
@@ -440,11 +441,11 @@
return NULL;
}
- it = ao2_iterator_init(cap1->formats, cap1->nolock ? AO2_ITERATOR_DONTLOCK : 0);
+ it = ao2_iterator_init(cap1->formats, 0);
while ((tmp = ao2_iterator_next(&it))) {
data.format = tmp;
ao2_callback(cap2->formats,
- OBJ_MULTIPLE | OBJ_NODATA | cap2->nolock,
+ OBJ_MULTIPLE | OBJ_NODATA,
find_joint_cb,
&data);
ao2_ref(tmp, -1);
@@ -470,11 +471,11 @@
if (!append) {
ast_format_cap_remove_all(result);
}
- it = ao2_iterator_init(cap1->formats, cap2->nolock ? AO2_ITERATOR_DONTLOCK : 0);
+ it = ao2_iterator_init(cap1->formats, 0);
while ((tmp = ao2_iterator_next(&it))) {
data.format = tmp;
ao2_callback(cap2->formats,
- OBJ_MULTIPLE | OBJ_NODATA | cap2->nolock,
+ OBJ_MULTIPLE | OBJ_NODATA,
find_joint_cb,
&data);
ao2_ref(tmp, -1);
@@ -506,7 +507,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, cap->nolock ? AO2_ITERATOR_DONTLOCK : 0);
+ it = ao2_iterator_init(cap->formats, 0);
while ((tmp = ao2_iterator_next(&it))) {
if (AST_FORMAT_GET_TYPE(tmp->id) == ftype) {
/* copy format */
@@ -530,7 +531,7 @@
struct ao2_iterator it;
struct ast_format *tmp;
- it = ao2_iterator_init(cap->formats, cap->nolock ? AO2_ITERATOR_DONTLOCK : 0);
+ it = ao2_iterator_init(cap->formats, 0);
while ((tmp = ao2_iterator_next(&it))) {
if (AST_FORMAT_GET_TYPE(tmp->id) == type) {
ao2_ref(tmp, -1);
@@ -546,18 +547,16 @@
void ast_format_cap_iter_start(struct ast_format_cap *cap)
{
- if (!cap->nolock) {
- ao2_lock(cap->formats);
- }
- cap->it = ao2_iterator_init(cap->formats, cap->nolock ? AO2_ITERATOR_DONTLOCK : 0);
+ /* We can unconditionally lock even if the container has no lock. */
+ ao2_lock(cap->formats);
+ cap->it = ao2_iterator_init(cap->formats, AO2_ITERATOR_DONTLOCK);
}
void ast_format_cap_iter_end(struct ast_format_cap *cap)
{
ao2_iterator_destroy(&cap->it);
- if (!cap->nolock) {
- ao2_unlock(cap->formats);
- }
+ /* We can unconditionally unlock even if the container has no lock. */
+ ao2_unlock(cap->formats);
}
int ast_format_cap_iter_next(struct ast_format_cap *cap, struct ast_format *format)
@@ -615,7 +614,7 @@
struct ao2_iterator it;
struct ast_format *tmp;
- it = ao2_iterator_init(cap->formats, cap->nolock ? AO2_ITERATOR_DONTLOCK : 0);
+ it = ao2_iterator_init(cap->formats, 0);
while ((tmp = ao2_iterator_next(&it))) {
res |= ast_format_to_old_bitfield(tmp);
ao2_ref(tmp, -1);
More information about the asterisk-commits
mailing list