On 03/07/2011 06:27 AM, Jiri Denemark wrote:
And the rest of the for loops in Cleanup* is safe as well for the
reason you
already mentioned. The code moves stuff from i+1 to the end of the array one
position closer the beginning of the array and it will move the possibly added
items as well. The only thing which may happen is that if Remove* is called
while the mutex is unlocked, an item which we already went through can be
marked as deleted so we are no longer guaranteed that when Cleanup* finishes,
the array only contains items which were not deleted. But AFAICT no-one counts
with that behavior so it's safe to break it.
Actually, someone does count on it:
virEventRunOnce first runs the cleanup handlers, then calls
virEventMakePollFDs, all while holding the lock. virEventMakePollFDs
currently adds a slot in the poll fd array for every slot of the array,
because it "knows" that there are no deleted entries in the array (since
the cleanup completed without dropping lock).
Once we make the cleanup functions drop and regain lock, we also need to
teach virEventMakePollFDs to ignore deleted entries.
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org