tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Add a mountlist iterator (round 2)

> Date: Sun, 9 Apr 2017 18:47:25 +0200
> From: "J. Hannken-Illjes" <>
> > On 6. Apr 2017, at 11:44, J. Hannken-Illjes <> wrote:
> > Good hint.  Prepared a partial implementation of
> > 
> > int
> > mountlist_iterate(int (*cb)(struct mount *, void *), void *arg)
> > [...]
> > Diffs are here:
> > 
> > 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:

while ((mp = mountlist_iterator_next(&it)) != NULL) {
	if (interesting(mp)) {

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!

Home | Main Index | Thread Index | Old Index