From 28128dc4e3c0cd581e868404034aba120c8b56c1 Mon Sep 17 00:00:00 2001 From: Thomas Jansen Date: Sun, 28 Dec 2008 22:09:42 +0100 Subject: tag & tag_pool: migrate from pthread to glib threads --- src/main.c | 3 +++ src/tag.c | 16 ++++++++-------- src/tag_pool.c | 15 ++++++++++++++- src/tag_pool.h | 8 ++++++-- 4 files changed, 31 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 8b543801..babb17c2 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 5e2a3620..3f7720d8 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 dc2e0df2..1c7ae31a 100644 --- a/src/tag_pool.c +++ b/src/tag_pool.c @@ -21,7 +21,7 @@ #include -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 bfcce2fb..de52672b 100644 --- a/src/tag_pool.h +++ b/src/tag_pool.h @@ -21,12 +21,16 @@ #include "tag.h" -#include +#include -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); -- cgit v1.2.3