diff options
-rw-r--r-- | src/dirvec.c | 6 | ||||
-rw-r--r-- | src/songvec.c | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/dirvec.c b/src/dirvec.c index 91b371b8a..a5eb6d54e 100644 --- a/src/dirvec.c +++ b/src/dirvec.c @@ -88,16 +88,20 @@ int dirvec_for_each(const struct dirvec *dv, int (*fn)(struct directory *, void *), void *arg) { size_t i; + size_t prev_nr; pthread_mutex_lock(&nr_lock); - for (i = 0; i < dv->nr; ++i) { + for (i = 0; i < dv->nr; ) { struct directory *dir = dv->base[i]; assert(dir); + prev_nr = dv->nr; pthread_mutex_unlock(&nr_lock); if (fn(dir, arg) < 0) return -1; pthread_mutex_lock(&nr_lock); /* dv->nr may change in fn() */ + if (prev_nr == dv->nr) + ++i; } pthread_mutex_unlock(&nr_lock); diff --git a/src/songvec.c b/src/songvec.c index 1a9635044..19433a222 100644 --- a/src/songvec.c +++ b/src/songvec.c @@ -87,18 +87,22 @@ int songvec_for_each(const struct songvec *sv, int (*fn)(struct mpd_song *, void *), void *arg) { size_t i; + size_t prev_nr; pthread_mutex_lock(&nr_lock); - for (i = 0; i < sv->nr; ++i) { + for (i = 0; i < sv->nr; ) { struct mpd_song *song = sv->base[i]; assert(song); assert(*song->url); + prev_nr = sv->nr; pthread_mutex_unlock(&nr_lock); /* fn() may block */ if (fn(song, arg) < 0) return -1; pthread_mutex_lock(&nr_lock); /* sv->nr may change in fn() */ + if (prev_nr == sv->nr) + ++i; } pthread_mutex_unlock(&nr_lock); |