aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-08-27 22:35:21 -0700
committerEric Wong <normalperson@yhbt.net>2008-08-27 22:40:41 -0700
commitcc602b252fe83219c927d0c0a272e8e5cc9f0fc2 (patch)
tree45c1b77e688348d99e357822b7f9cfecc31f9ae6
parentdb0df3a3bd59a3c943a81f17567fef4fcb4cc215 (diff)
downloadmpd-cc602b252fe83219c927d0c0a272e8e5cc9f0fc2.tar.gz
mpd-cc602b252fe83219c927d0c0a272e8e5cc9f0fc2.tar.xz
mpd-cc602b252fe83219c927d0c0a272e8e5cc9f0fc2.zip
tagTracker: locks around {get,remove}TagItemString
Hopefully this fixes a segfault I experienced inside freeMpdTag earlier with the metadata_pipe. I could not reproduce the segfault again, however. Regardless, if multiple threads rely on this, we need to atomically increment/decrement these counters.
Diffstat (limited to '')
-rw-r--r--src/tagTracker.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/tagTracker.c b/src/tagTracker.c
index c44ce8199..acc8a4d2e 100644
--- a/src/tagTracker.c
+++ b/src/tagTracker.c
@@ -22,6 +22,7 @@
#include "tree.h"
#include "utils.h"
#include "myfprintf.h"
+#include "os_compat.h"
static Tree *tagTrees[TAG_NUM_OF_ITEM_TYPES];
@@ -30,9 +31,14 @@ typedef struct tagTrackerItem {
mpd_sint8 visited;
} TagTrackerItem;
+static pthread_mutex_t tag_item_lock = PTHREAD_MUTEX_INITIALIZER;
+
char *getTagItemString(int type, char *string)
{
TreeIterator iter;
+ char *ret;
+
+ pthread_mutex_lock(&tag_item_lock);
if (tagTrees[type] == NULL)
{
@@ -44,7 +50,7 @@ char *getTagItemString(int type, char *string)
if (FindInTree(tagTrees[type], string, &iter))
{
((TagTrackerItem *)GetTreeKeyData(&iter)->data)->count++;
- return (char *)GetTreeKeyData(&iter)->key;
+ ret = (char *)GetTreeKeyData(&iter)->key;
}
else
{
@@ -53,8 +59,11 @@ char *getTagItemString(int type, char *string)
item->count = 1;
item->visited = 0;
InsertInTree(tagTrees[type], key, item);
- return key;
+ ret = key;
}
+
+ pthread_mutex_unlock(&tag_item_lock);
+ return ret;
}
void removeTagItemString(int type, char *string)
@@ -67,6 +76,7 @@ void removeTagItemString(int type, char *string)
if (tagTrees[type] == NULL)
return;
+ pthread_mutex_lock(&tag_item_lock);
if (FindInTree(tagTrees[type], string, &iter))
{
TagTrackerItem * item =
@@ -81,6 +91,7 @@ void removeTagItemString(int type, char *string)
FreeTree(tagTrees[type]);
tagTrees[type] = NULL;
}
+ pthread_mutex_unlock(&tag_item_lock);
}
int getNumberOfTagItems(int type)