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:
parent
e19f6905d9
commit
bb04c6342e
@ -66,3 +66,16 @@ void songvec_destroy(struct songvec *sv)
|
|||||||
}
|
}
|
||||||
sv->nr = 0;
|
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;
|
||||||
|
}
|
||||||
|
@ -19,4 +19,6 @@ void songvec_add(struct songvec *sv, Song *add);
|
|||||||
|
|
||||||
void songvec_destroy(struct songvec *sv);
|
void songvec_destroy(struct songvec *sv);
|
||||||
|
|
||||||
|
int songvec_for_each(struct songvec *sv, int (*fn)(Song *, void *), void *arg);
|
||||||
|
|
||||||
#endif /* SONGVEC_H */
|
#endif /* SONGVEC_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user