From f0a68935f9da6a77cd4688fc5836b2ce8f058041 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 5 Sep 2008 00:10:48 -0700 Subject: tag: lock all accesses to tag_pool The tag pool is a shared global resource that is infrequently modified. However, it can occasionally be modified by several threads, especially by the metadata_pipe for streaming metadata (both reading/writing). The bulk tag_item pool is NOT locked as currently only the update thread uses it. --- src/tag.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/tag.c') diff --git a/src/tag.c b/src/tag.c index dc2bab2d6..8208eb965 100644 --- a/src/tag.c +++ b/src/tag.c @@ -267,8 +267,9 @@ static void deleteItem(struct mpd_tag *tag, int idx) assert(idx < tag->numOfItems); tag->numOfItems--; + pthread_mutex_lock(&tag_pool_lock); tag_pool_put_item(tag->items[idx]); - /* free(tag->items[idx].value); */ + pthread_mutex_unlock(&tag_pool_lock); if (tag->numOfItems - idx > 0) { memmove(tag->items + idx, tag->items + idx + 1, @@ -300,10 +301,10 @@ static void clearMpdTag(struct mpd_tag *tag) { int i; - for (i = 0; i < tag->numOfItems; i++) { - /* free(tag->items[i].value); */ + pthread_mutex_lock(&tag_pool_lock); + for (i = 0; i < tag->numOfItems; i++) tag_pool_put_item(tag->items[i]); - } + pthread_mutex_unlock(&tag_pool_lock); if (tag->items == bulk.items) { #ifndef NDEBUG @@ -340,9 +341,10 @@ struct mpd_tag *tag_dup(const struct mpd_tag *tag) ret->numOfItems = tag->numOfItems; ret->items = ret->numOfItems > 0 ? xmalloc(items_size(tag)) : NULL; - for (i = 0; i < tag->numOfItems; i++) { + pthread_mutex_lock(&tag_pool_lock); + for (i = 0; i < tag->numOfItems; i++) ret->items[i] = tag_pool_dup_item(tag->items[i]); - } + pthread_mutex_unlock(&tag_pool_lock); return ret; } @@ -451,7 +453,9 @@ static void appendToTagItems(struct mpd_tag *tag, enum tag_type type, items_size(tag) - sizeof(struct tag_item)); } + pthread_mutex_lock(&tag_pool_lock); tag->items[i] = tag_pool_get_item(type, p, len); + pthread_mutex_unlock(&tag_pool_lock); if (p != value) free(deconst_ptr(p)); -- cgit v1.2.3