tag & tag_pool: migrate from pthread to glib threads

This commit is contained in:
Thomas Jansen 2008-12-28 22:09:42 +01:00
parent ce5c22f4f4
commit 28128dc4e3
4 changed files with 31 additions and 11 deletions

View File

@ -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();

View File

@ -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);
}

View File

@ -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)
{

View File

@ -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);