[asterisk-dev] Astobj2 and locks
Watkins, Bradley
Bradley.Watkins at compuware.com
Wed Sep 12 18:29:19 CDT 2007
I'm working on some pretty big changes to app_queue for internal use (if
I think it'll end up remotely useful to the community, I'll be certain
to submit a patch), and it looks like the features of astobj2 are
exactly what I need.
However, I'm trying to understand its use, and I've either found some
bugs in existing usage or I'm missing something (I don't rule out the
latter in any way).
When iterating through a container using ao2_iterator_next, it seems as
though you should need to wrap any changes to the returned object with
calls to ao2_lock() and subsequently ao2_unlock() after the changes are
complete.
But here is a snippet from app_queue.c in branches/1.4:
mem_iter = ao2_iterator_init(q->members, 0);
while ((m = ao2_iterator_next(&mem_iter))) {
q->membercount++;
if (m->realtime)
m->dead = 1;
ao2_ref(m, -1);
}
I would expect (based on my cursory glance at the implementation in
astobj2.c) that it should look something like:
mem_iter = ao2_iterator_init(q->members, 0);
while ((m = ao2_iterator_next(&mem_iter))) {
q->membercount++;
if (m->realtime) {
if(ao2_lock(m)) {
m->dead = 1;
ao2_unlock(m);
}
}
ao2_ref(m, -1);
}
Do I have it all wrong somehow? And if so, please educate me as to how
so that I may be enlightened.
Regards,
- Brad
More information about the asterisk-dev
mailing list