> Date: Sun, 9 Apr 2017 18:47:25 +0200 > From: "J. Hannken-Illjes" <hann...@eis.cs.tu-bs.de> > > > On 6. Apr 2017, at 11:44, J. Hannken-Illjes <hann...@eis.cs.tu-bs.de> wrote: > > Good hint. Prepared a partial implementation of > > > > int > > mountlist_iterate(int (*cb)(struct mount *, void *), void *arg) > > [...] > > Diffs are here: https://www.netbsd.org/~hannken/ml_iterator2a/ > > > > I prefer this API, opinions? > > If no one objects I will commit this iterator on Tuesday, April 11.
I tend to prefer an iterator-style API over a callback-style API where it works. (E.g., obviously xcall(9) can't be done with an iterator- style API.) I like to avoid writing my code upside-down unless it's really necessary. If you want a callback-style API for some reason, you can always write that in terms of an iterator-style API, but not vice versa. Note the suggestion I made earlier about mountlist_iterator_next_done isn't necessary as long as anyone trying to break the loop and keep using the mount does something extra to acquire a reference: mountlist_iterator_begin(&it); while ((mp = mountlist_iterator_next(&it)) != NULL) { dostuff(mp); if (interesting(mp)) { vfs_busy(mp); break; } } mountlist_iterator_end(&it); All you have to do to make this work is store the last mp in the iterator too, so that mountlist_iterator_next can release it before acquiring the next one. But I'm not the one doing the work here, so this is not an objection!