On 09/09/2015 10:49, Fam Zheng wrote:
>> > + qemu_lockcnt_inc(&io_handlers_lockcnt);
>> > + QLIST_FOREACH_RCU(ioh, &io_handlers, pioh) {
>> > + if (ioh->revents & G_IO_OUT) {
>> > + ioh->fd_write(ioh->opaque);
>> > + }
>> > + }
> I'm confused, the comment of QLIST_FOREACH_RCU says "list traversal
> must occur within an RCU critical section.", but there is not rcu_read_lock
> here. Why?
Right, the comment should be updated.
RCU can be seen as a "global reference count" that prevents freeing an
object between rcu_read_lock and rcu_read_unlock. Here the reference
count is provided by the LockCnt.
The difference between QLIST_FOREACH and QLIST_FOREACH_RCU is just that
the latter has an extra smp_read_barrier_depends. The barrier is needed
for all lockless visits. I think QLIST_FOREACH_RCU is more expressive
than QLIST_FOREACH_LOCKLESS or something like that.
Paolo