songvec: add songvec_for_each iterator

This is so we can more consistently deal with locking
needed for thread-safety in iterator functions.
This commit is contained in:
Eric Wong 2008-10-07 22:07:29 +02:00 committed by Max Kellermann
parent e19f6905d9
commit bb04c6342e
2 changed files with 15 additions and 0 deletions

View File

@ -66,3 +66,16 @@ void songvec_destroy(struct songvec *sv)
}
sv->nr = 0;
}
int songvec_for_each(struct songvec *sv, int (*fn)(Song *, void *), void *arg)
{
int i;
Song **sp = sv->base;
for (i = sv->nr; --i >= 0; ) {
if (fn(*sp++, arg) < 0)
return -1;
}
return 0;
}

View File

@ -19,4 +19,6 @@ void songvec_add(struct songvec *sv, Song *add);
void songvec_destroy(struct songvec *sv);
int songvec_for_each(struct songvec *sv, int (*fn)(Song *, void *), void *arg);
#endif /* SONGVEC_H */