diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-13 09:55:07 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-13 09:55:07 +0200 |
commit | 313405edb6bcd83d0a45338d8419fb7065cb565b (patch) | |
tree | f371afc72e6233a433f9cd527271a2cceec6a26d /src | |
parent | 3035a3303d8b5696542012e0e05b75daf9601f9b (diff) | |
download | mpd-313405edb6bcd83d0a45338d8419fb7065cb565b.tar.gz mpd-313405edb6bcd83d0a45338d8419fb7065cb565b.tar.xz mpd-313405edb6bcd83d0a45338d8419fb7065cb565b.zip |
songvec: avoid holding nr_lock during free(3)
We only need to lock sv->nr changes to prevent traversals ( why
it's called "nr_lock"). free(3) is a "slow" function on my
system; so we can avoid unnecessarily holding a lock long for
longer than needed.
Diffstat (limited to 'src')
-rw-r--r-- | src/songvec.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/songvec.c b/src/songvec.c index 46c81a82a..80954643e 100644 --- a/src/songvec.c +++ b/src/songvec.c @@ -53,10 +53,12 @@ songvec_delete(struct songvec *sv, const struct song *del) for (i = sv->nr; --i >= 0; ) { if (sv->base[i] != del) continue; - /* we _don't_ call freeSong() here */ + /* we _don't_ call song_free() here */ if (!--sv->nr) { + pthread_mutex_unlock(&nr_lock); free(sv->base); sv->base = NULL; + return i; } else { memmove(&sv->base[i], &sv->base[i + 1], (sv->nr - i + 1) * sizeof(struct song *)); @@ -82,12 +84,12 @@ songvec_add(struct songvec *sv, struct song *add) void songvec_destroy(struct songvec *sv) { pthread_mutex_lock(&nr_lock); + sv->nr = 0; + pthread_mutex_unlock(&nr_lock); if (sv->base) { free(sv->base); sv->base = NULL; } - sv->nr = 0; - pthread_mutex_unlock(&nr_lock); } int |