tag_pool: use GStaticMutex
Eliminates explicit global initialisation.
This commit is contained in:
parent
510097cc37
commit
c1f90a99f4
@ -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();
|
||||
|
20
src/tag.c
20
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);
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user