aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-10-08 01:49:39 -0700
committerEric Wong <normalperson@yhbt.net>2008-10-12 05:27:33 -0700
commit7284123e3555159c6550d5ac57b8334bdd1af5c1 (patch)
tree6a6792b7abd2d3cdaf7c2bf0f99b9a95525e0019 /src
parentafef3a6e68f4007f8e087b6ae359518ff59b04ef (diff)
downloadmpd-7284123e3555159c6550d5ac57b8334bdd1af5c1.tar.gz
mpd-7284123e3555159c6550d5ac57b8334bdd1af5c1.tar.xz
mpd-7284123e3555159c6550d5ac57b8334bdd1af5c1.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.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/songvec.c b/src/songvec.c
index ce04a4373..3d512e917 100644
--- a/src/songvec.c
+++ b/src/songvec.c
@@ -48,10 +48,12 @@ int songvec_delete(struct songvec *sv, const struct mpd_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 mpd_song *));
@@ -76,12 +78,12 @@ void songvec_add(struct songvec *sv, struct mpd_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 songvec_for_each(const struct songvec *sv,