aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.c3
-rw-r--r--src/tag.c16
-rw-r--r--src/tag_pool.c15
-rw-r--r--src/tag_pool.h8
4 files changed, 31 insertions, 11 deletions
diff --git a/src/main.c b/src/main.c
index 8b5438011..babb17c25 100644
--- a/src/main.c
+++ b/src/main.c
@@ -52,6 +52,7 @@
#include "os_compat.h"
#include "dirvec.h"
#include "songvec.h"
+#include "tag_pool.h"
#ifdef ENABLE_ARCHIVE
#include "archive_list.h"
@@ -273,6 +274,7 @@ int main(int argc, char *argv[])
idle_init();
dirvec_init();
songvec_init();
+ tag_pool_init();
initConf();
parseOptions(argc, argv, &options);
@@ -387,6 +389,7 @@ int main(int argc, char *argv[])
music_pipe_free();
cleanUpPidFile();
finishConf();
+ tag_pool_deinit();
songvec_deinit();
dirvec_deinit();
idle_deinit();
diff --git a/src/tag.c b/src/tag.c
index 5e2a3620e..3f7720d88 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -247,9 +247,9 @@ static void deleteItem(struct tag *tag, int idx)
assert(idx < tag->numOfItems);
tag->numOfItems--;
- pthread_mutex_lock(&tag_pool_lock);
+ g_mutex_lock(tag_pool_lock);
tag_pool_put_item(tag->items[idx]);
- pthread_mutex_unlock(&tag_pool_lock);
+ g_mutex_unlock(tag_pool_lock);
if (tag->numOfItems - idx > 0) {
memmove(tag->items + idx, tag->items + idx + 1,
@@ -281,10 +281,10 @@ void tag_free(struct tag *tag)
{
int i;
- pthread_mutex_lock(&tag_pool_lock);
+ g_mutex_lock(tag_pool_lock);
for (i = tag->numOfItems; --i >= 0; )
tag_pool_put_item(tag->items[i]);
- pthread_mutex_unlock(&tag_pool_lock);
+ g_mutex_unlock(tag_pool_lock);
if (tag->items == bulk.items) {
#ifndef NDEBUG
@@ -311,10 +311,10 @@ struct tag *tag_dup(const struct tag *tag)
ret->numOfItems = tag->numOfItems;
ret->items = ret->numOfItems > 0 ? g_malloc(items_size(tag)) : NULL;
- pthread_mutex_lock(&tag_pool_lock);
+ g_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);
+ g_mutex_unlock(tag_pool_lock);
return ret;
}
@@ -444,9 +444,9 @@ static void appendToTagItems(struct tag *tag, enum tag_type type,
items_size(tag) - sizeof(struct tag_item *));
}
- pthread_mutex_lock(&tag_pool_lock);
+ g_mutex_lock(tag_pool_lock);
tag->items[i] = tag_pool_get_item(type, p, len);
- pthread_mutex_unlock(&tag_pool_lock);
+ g_mutex_unlock(tag_pool_lock);
g_free(duplicated);
}
diff --git a/src/tag_pool.c b/src/tag_pool.c
index dc2e0df2b..1c7ae31ab 100644
--- a/src/tag_pool.c
+++ b/src/tag_pool.c
@@ -21,7 +21,7 @@
#include <assert.h>
-pthread_mutex_t tag_pool_lock = PTHREAD_MUTEX_INITIALIZER;
+GMutex *tag_pool_lock = NULL;
#define NUM_SLOTS 4096
@@ -80,6 +80,19 @@ static struct slot *slot_alloc(struct slot *next,
return slot;
}
+void tag_pool_init(void)
+{
+ g_assert(tag_pool_lock == NULL);
+ tag_pool_lock = g_mutex_new();
+}
+
+void tag_pool_deinit(void)
+{
+ g_assert(tag_pool_lock != NULL);
+ g_mutex_free(tag_pool_lock);
+ tag_pool_lock = NULL;
+}
+
struct tag_item *tag_pool_get_item(enum tag_type type,
const char *value, int length)
{
diff --git a/src/tag_pool.h b/src/tag_pool.h
index bfcce2fbf..de52672bd 100644
--- a/src/tag_pool.h
+++ b/src/tag_pool.h
@@ -21,12 +21,16 @@
#include "tag.h"
-#include <pthread.h>
+#include <glib.h>
-extern pthread_mutex_t tag_pool_lock;
+extern GMutex *tag_pool_lock;
struct tag_item;
+void tag_pool_init(void);
+
+void tag_pool_deinit(void);
+
struct tag_item *tag_pool_get_item(enum tag_type type,
const char *value, int length);