aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-08 21:01:25 +0200
committerMax Kellermann <max@duempel.org>2012-08-08 21:01:25 +0200
commitc1f90a99f4b33b3b2c05d051f19bd7ed3472c5ff (patch)
treea1eb2e93ff43309ee30fd77ec57db6d10d8fd612
parent510097cc37ffe88ddd1bf0587add83654777ded1 (diff)
tag_pool: use GStaticMutex
Eliminates explicit global initialisation.
-rw-r--r--src/main.c3
-rw-r--r--src/tag.c20
-rw-r--r--src/tag_pool.c25
-rw-r--r--src/tag_pool.h6
-rw-r--r--test/DumpDatabase.cxx4
-rw-r--r--test/dump_playlist.c3
-rw-r--r--test/dump_text_file.c3
-rw-r--r--test/run_decoder.c5
-rw-r--r--test/run_input.c4
9 files changed, 24 insertions, 49 deletions
diff --git a/src/main.c b/src/main.c
index 8b34bdad..b8823d7e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -53,7 +53,6 @@
#include "tag.h"
#include "zeroconf.h"
#include "event_pipe.h"
-#include "tag_pool.h"
#include "mpd_error.h"
#ifdef ENABLE_INOTIFY
@@ -359,7 +358,6 @@ int mpd_main(int argc, char *argv[])
io_thread_init();
winsock_init();
idle_init();
- tag_pool_init();
config_global_init();
success = parse_cmdline(argc, argv, &options, &error);
@@ -544,7 +542,6 @@ int mpd_main(int argc, char *argv[])
archive_plugin_deinit_all();
#endif
config_global_finish();
- tag_pool_deinit();
idle_deinit();
stats_global_finish();
io_thread_deinit();
diff --git a/src/tag.c b/src/tag.c
index c0faa7ab..b59c23b2 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -168,9 +168,9 @@ static void tag_delete_item(struct tag *tag, unsigned idx)
assert(idx < tag->num_items);
tag->num_items--;
- g_mutex_lock(tag_pool_lock);
+ g_static_mutex_lock(&tag_pool_lock);
tag_pool_put_item(tag->items[idx]);
- g_mutex_unlock(tag_pool_lock);
+ g_static_mutex_unlock(&tag_pool_lock);
if (tag->num_items - idx > 0) {
memmove(tag->items + idx, tag->items + idx + 1,
@@ -202,10 +202,10 @@ void tag_free(struct tag *tag)
assert(tag != NULL);
- g_mutex_lock(tag_pool_lock);
+ g_static_mutex_lock(&tag_pool_lock);
for (i = tag->num_items; --i >= 0; )
tag_pool_put_item(tag->items[i]);
- g_mutex_unlock(tag_pool_lock);
+ g_static_mutex_unlock(&tag_pool_lock);
if (tag->items == bulk.items) {
#ifndef NDEBUG
@@ -231,10 +231,10 @@ struct tag *tag_dup(const struct tag *tag)
ret->num_items = tag->num_items;
ret->items = ret->num_items > 0 ? g_malloc(items_size(tag)) : NULL;
- g_mutex_lock(tag_pool_lock);
+ g_static_mutex_lock(&tag_pool_lock);
for (unsigned i = 0; i < tag->num_items; i++)
ret->items[i] = tag_pool_dup_item(tag->items[i]);
- g_mutex_unlock(tag_pool_lock);
+ g_static_mutex_unlock(&tag_pool_lock);
return ret;
}
@@ -255,7 +255,7 @@ tag_merge(const struct tag *base, const struct tag *add)
ret->num_items = base->num_items + add->num_items;
ret->items = ret->num_items > 0 ? g_malloc(items_size(ret)) : NULL;
- g_mutex_lock(tag_pool_lock);
+ g_static_mutex_lock(&tag_pool_lock);
/* copy all items from "add" */
@@ -270,7 +270,7 @@ tag_merge(const struct tag *base, const struct tag *add)
if (!tag_has_type(add, base->items[i]->type))
ret->items[n++] = tag_pool_dup_item(base->items[i]);
- g_mutex_unlock(tag_pool_lock);
+ g_static_mutex_unlock(&tag_pool_lock);
assert(n <= ret->num_items);
@@ -502,9 +502,9 @@ tag_add_item_internal(struct tag *tag, enum tag_type type,
items_size(tag) - sizeof(struct tag_item *));
}
- g_mutex_lock(tag_pool_lock);
+ g_static_mutex_lock(&tag_pool_lock);
tag->items[i] = tag_pool_get_item(type, value, len);
- g_mutex_unlock(tag_pool_lock);
+ g_static_mutex_unlock(&tag_pool_lock);
g_free(p);
}
diff --git a/src/tag_pool.c b/src/tag_pool.c
index eabf3e36..2f9b3948 100644
--- a/src/tag_pool.c
+++ b/src/tag_pool.c
@@ -22,7 +22,17 @@
#include <assert.h>
-GMutex *tag_pool_lock = NULL;
+#if GCC_CHECK_VERSION(4, 2)
+/* workaround for a warning caused by G_STATIC_MUTEX_INIT */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#endif
+
+GStaticMutex tag_pool_lock = G_STATIC_MUTEX_INIT;
+
+#if GCC_CHECK_VERSION(4, 2)
+#pragma GCC diagnostic pop
+#endif
#define NUM_SLOTS 4096
@@ -81,19 +91,6 @@ 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, size_t length)
{
diff --git a/src/tag_pool.h b/src/tag_pool.h
index a96c00d8..a717f704 100644
--- a/src/tag_pool.h
+++ b/src/tag_pool.h
@@ -24,14 +24,10 @@
#include <glib.h>
-extern GMutex *tag_pool_lock;
+extern GStaticMutex 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, size_t length);
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx
index b0a9c933..7aa8f06f 100644
--- a/test/DumpDatabase.cxx
+++ b/test/DumpDatabase.cxx
@@ -27,7 +27,7 @@
extern "C" {
#include "conf.h"
-#include "tag_pool.h"
+#include "tag.h"
}
#include <iostream>
@@ -95,7 +95,6 @@ main(int argc, char **argv)
/* initialize MPD */
- tag_pool_init();
config_global_init();
if (!config_read_file(config_path, &error)) {
@@ -147,7 +146,6 @@ main(int argc, char **argv)
/* deinitialize everything */
config_global_finish();
- tag_pool_deinit();
return EXIT_SUCCESS;
}
diff --git a/test/dump_playlist.c b/test/dump_playlist.c
index 0570f6e4..28237a79 100644
--- a/test/dump_playlist.c
+++ b/test/dump_playlist.c
@@ -21,7 +21,6 @@
#include "io_thread.h"
#include "input_init.h"
#include "input_stream.h"
-#include "tag_pool.h"
#include "tag_save.h"
#include "conf.h"
#include "song.h"
@@ -157,7 +156,6 @@ int main(int argc, char **argv)
/* initialize MPD */
- tag_pool_init();
config_global_init();
success = config_read_file(argv[1], &error);
if (!success) {
@@ -249,7 +247,6 @@ int main(int argc, char **argv)
input_stream_global_finish();
io_thread_deinit();
config_global_finish();
- tag_pool_deinit();
return 0;
}
diff --git a/test/dump_text_file.c b/test/dump_text_file.c
index f1437144..f13e648b 100644
--- a/test/dump_text_file.c
+++ b/test/dump_text_file.c
@@ -22,7 +22,6 @@
#include "input_init.h"
#include "input_stream.h"
#include "text_input_stream.h"
-#include "tag_pool.h"
#include "conf.h"
#include "stdbin.h"
@@ -112,7 +111,6 @@ int main(int argc, char **argv)
/* initialize MPD */
- tag_pool_init();
config_global_init();
io_thread_init();
@@ -164,7 +162,6 @@ int main(int argc, char **argv)
io_thread_deinit();
config_global_finish();
- tag_pool_deinit();
return ret;
}
diff --git a/test/run_decoder.c b/test/run_decoder.c
index e6712c75..c25e727b 100644
--- a/test/run_decoder.c
+++ b/test/run_decoder.c
@@ -21,7 +21,6 @@
#include "io_thread.h"
#include "decoder_list.h"
#include "decoder_api.h"
-#include "tag_pool.h"
#include "input_init.h"
#include "input_stream.h"
#include "audio_format.h"
@@ -191,8 +190,6 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- tag_pool_init();
-
if (!input_stream_global_init(&error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -248,7 +245,5 @@ int main(int argc, char **argv)
return 1;
}
- tag_pool_deinit();
-
return 0;
}
diff --git a/test/run_input.c b/test/run_input.c
index 676e4e61..acf25a28 100644
--- a/test/run_input.c
+++ b/test/run_input.c
@@ -21,8 +21,8 @@
#include "io_thread.h"
#include "input_init.h"
#include "input_stream.h"
-#include "tag_pool.h"
#include "tag_save.h"
+#include "tag.h"
#include "conf.h"
#include "stdbin.h"
@@ -127,7 +127,6 @@ int main(int argc, char **argv)
/* initialize MPD */
- tag_pool_init();
config_global_init();
io_thread_init();
@@ -179,7 +178,6 @@ int main(int argc, char **argv)
io_thread_deinit();
config_global_finish();
- tag_pool_deinit();
return ret;
}