diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-05 21:00:39 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-05 22:50:31 -0700 |
commit | 36c0254a850bf3b24cfd67175cd17bc6afa6035b (patch) | |
tree | aac1ff334bad059a50162532f42c132de2cdf23d | |
parent | a5f8bb82300d08568180482c93e8b9a067cc715d (diff) | |
download | mpd-36c0254a850bf3b24cfd67175cd17bc6afa6035b.tar.gz mpd-36c0254a850bf3b24cfd67175cd17bc6afa6035b.tar.xz mpd-36c0254a850bf3b24cfd67175cd17bc6afa6035b.zip |
songvec: add songvec_for_each iterator
This is so we can more consistently deal with locking
needed for thread-safety in iterator functions.
-rw-r--r-- | src/songvec.c | 13 | ||||
-rw-r--r-- | src/songvec.h | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/songvec.c b/src/songvec.c index 969e67220..50694c68a 100644 --- a/src/songvec.c +++ b/src/songvec.c @@ -68,6 +68,19 @@ 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; +} + int songvec_write(struct songvec *sv, int fd, int extra) { int i; diff --git a/src/songvec.h b/src/songvec.h index fb5c38c8b..adfdeccfb 100644 --- a/src/songvec.h +++ b/src/songvec.h @@ -19,6 +19,8 @@ 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); + int songvec_write(struct songvec *sv, int fd, int extra); #endif /* SONGVEC_H */ |