On Fri, Oct 20, 2017 at 09:10:38 +0200, Paolo Bonzini wrote: > >> 2) in tb_for_each_tagged_safe, could the "prev" argument instead be > >> "next", like > > > > Is this just to make them closer to the macros in queue.h? > > > > In this case tracking *prev in the loop (rather than next) is > > useful because it makes removing the "current" element very simple: > > This actually makes a lot of sense. Maybe we should change queue.h the > other way. ;)
Turns out this works here but it isn't as general-purpose as it might look. In this case it works because we don't free the tb. If we did, then we'd either need a branch in the iterator or a third *next pointer. In fact, the macro wouldn't be safe even if it tracked *next, since on a removal *pprev must not be updated to the removed item. IOW, the caller must be the one keeping track of *pprev, for otherwise things break after the first removal. (Again, this doesn't affect this particular instance, because its only caller stops iterating after a removal.) I have therefore given up on the macro and changed its only caller to update *pprev. IMO it's less pretty, but more robust. The updated branch with the changes you suggested (plus the above) is available at: https://github.com/cota/qemu/tree/multi-tcg-v6-plus2 Thanks, Emilio