tagsetter: update for thread API deprecations in glib master

This commit is contained in:
Tim-Philipp Müller 2011-12-03 16:02:36 +00:00
parent 4b18f0a5c3
commit ff96aeee84

View file

@ -83,9 +83,21 @@ typedef struct
{ {
GstTagMergeMode mode; GstTagMergeMode mode;
GstTagList *list; GstTagList *list;
#if !GLIB_CHECK_VERSION (2, 31, 0)
GStaticMutex lock; GStaticMutex lock;
#else
GMutex lock;
#endif
} GstTagData; } GstTagData;
#if !GLIB_CHECK_VERSION (2, 31, 0)
#define GST_TAG_DATA_LOCK(data) g_static_mutex_lock(&data->lock)
#define GST_TAG_DATA_UNLOCK(data) g_static_mutex_unlock(&data->lock)
#else
#define GST_TAG_DATA_LOCK(data) g_mutex_lock(&data->lock)
#define GST_TAG_DATA_UNLOCK(data) g_mutex_unlock(&data->lock)
#endif
GType GType
gst_tag_setter_get_type (void) gst_tag_setter_get_type (void)
{ {
@ -125,7 +137,11 @@ gst_tag_data_free (gpointer p)
if (data->list) if (data->list)
gst_tag_list_free (data->list); gst_tag_list_free (data->list);
#if !GLIB_CHECK_VERSION (2, 31, 0)
g_static_mutex_free (&data->lock); g_static_mutex_free (&data->lock);
#else
g_mutex_clear (&data->lock);
#endif
g_slice_free (GstTagData, data); g_slice_free (GstTagData, data);
} }
@ -137,20 +153,35 @@ gst_tag_setter_get_data (GstTagSetter * setter)
data = g_object_get_qdata (G_OBJECT (setter), gst_tag_key); data = g_object_get_qdata (G_OBJECT (setter), gst_tag_key);
if (!data) { if (!data) {
/* make sure no other thread is creating a GstTagData at the same time */
#if !GLIB_CHECK_VERSION (2, 31, 0)
static GStaticMutex create_mutex = G_STATIC_MUTEX_INIT; static GStaticMutex create_mutex = G_STATIC_MUTEX_INIT;
/* make sure no other thread is creating a GstTagData at the same time */
g_static_mutex_lock (&create_mutex); g_static_mutex_lock (&create_mutex);
#else
static GMutex create_mutex; /* no initialisation required */
g_mutex_lock (&create_mutex);
#endif
data = g_object_get_qdata (G_OBJECT (setter), gst_tag_key); data = g_object_get_qdata (G_OBJECT (setter), gst_tag_key);
if (!data) { if (!data) {
data = g_slice_new (GstTagData); data = g_slice_new (GstTagData);
#if !GLIB_CHECK_VERSION (2, 31, 0)
g_static_mutex_init (&data->lock); g_static_mutex_init (&data->lock);
#else
g_mutex_init (&data->lock);
#endif
data->list = NULL; data->list = NULL;
data->mode = GST_TAG_MERGE_KEEP; data->mode = GST_TAG_MERGE_KEEP;
g_object_set_qdata_full (G_OBJECT (setter), gst_tag_key, data, g_object_set_qdata_full (G_OBJECT (setter), gst_tag_key, data,
gst_tag_data_free); gst_tag_data_free);
} }
#if !GLIB_CHECK_VERSION (2, 31, 0)
g_static_mutex_unlock (&create_mutex); g_static_mutex_unlock (&create_mutex);
#else
g_mutex_unlock (&create_mutex);
#endif
} }
return data; return data;
@ -174,12 +205,12 @@ gst_tag_setter_reset_tags (GstTagSetter * setter)
data = gst_tag_setter_get_data (setter); data = gst_tag_setter_get_data (setter);
g_static_mutex_lock (&data->lock); GST_TAG_DATA_LOCK (data);
if (data->list) { if (data->list) {
gst_tag_list_free (data->list); gst_tag_list_free (data->list);
data->list = NULL; data->list = NULL;
} }
g_static_mutex_unlock (&data->lock); GST_TAG_DATA_UNLOCK (data);
} }
/** /**
@ -202,14 +233,14 @@ gst_tag_setter_merge_tags (GstTagSetter * setter, const GstTagList * list,
data = gst_tag_setter_get_data (setter); data = gst_tag_setter_get_data (setter);
g_static_mutex_lock (&data->lock); GST_TAG_DATA_LOCK (data);
if (data->list == NULL) { if (data->list == NULL) {
if (mode != GST_TAG_MERGE_KEEP_ALL) if (mode != GST_TAG_MERGE_KEEP_ALL)
data->list = gst_tag_list_copy (list); data->list = gst_tag_list_copy (list);
} else { } else {
gst_tag_list_insert (data->list, list, mode); gst_tag_list_insert (data->list, list, mode);
} }
g_static_mutex_unlock (&data->lock); GST_TAG_DATA_UNLOCK (data);
} }
/** /**
@ -281,13 +312,13 @@ gst_tag_setter_add_tag_valist (GstTagSetter * setter, GstTagMergeMode mode,
data = gst_tag_setter_get_data (setter); data = gst_tag_setter_get_data (setter);
g_static_mutex_lock (&data->lock); GST_TAG_DATA_LOCK (data);
if (!data->list) if (!data->list)
data->list = gst_tag_list_new (); data->list = gst_tag_list_new ();
gst_tag_list_add_valist (data->list, mode, tag, var_args); gst_tag_list_add_valist (data->list, mode, tag, var_args);
g_static_mutex_unlock (&data->lock); GST_TAG_DATA_UNLOCK (data);
} }
/** /**
@ -311,14 +342,14 @@ gst_tag_setter_add_tag_valist_values (GstTagSetter * setter,
data = gst_tag_setter_get_data (setter); data = gst_tag_setter_get_data (setter);
g_static_mutex_lock (&data->lock); GST_TAG_DATA_LOCK (data);
if (!data->list) if (!data->list)
data->list = gst_tag_list_new (); data->list = gst_tag_list_new ();
gst_tag_list_add_valist_values (data->list, mode, tag, var_args); gst_tag_list_add_valist_values (data->list, mode, tag, var_args);
g_static_mutex_unlock (&data->lock); GST_TAG_DATA_UNLOCK (data);
} }
/** /**
@ -343,14 +374,14 @@ gst_tag_setter_add_tag_value (GstTagSetter * setter,
data = gst_tag_setter_get_data (setter); data = gst_tag_setter_get_data (setter);
g_static_mutex_lock (&data->lock); GST_TAG_DATA_LOCK (data);
if (!data->list) if (!data->list)
data->list = gst_tag_list_new (); data->list = gst_tag_list_new ();
gst_tag_list_add_value (data->list, mode, tag, value); gst_tag_list_add_value (data->list, mode, tag, value);
g_static_mutex_unlock (&data->lock); GST_TAG_DATA_UNLOCK (data);
} }
/** /**
@ -392,9 +423,9 @@ gst_tag_setter_set_tag_merge_mode (GstTagSetter * setter, GstTagMergeMode mode)
data = gst_tag_setter_get_data (setter); data = gst_tag_setter_get_data (setter);
g_static_mutex_lock (&data->lock); GST_TAG_DATA_LOCK (data);
data->mode = mode; data->mode = mode;
g_static_mutex_unlock (&data->lock); GST_TAG_DATA_UNLOCK (data);
} }
/** /**
@ -416,9 +447,9 @@ gst_tag_setter_get_tag_merge_mode (GstTagSetter * setter)
data = gst_tag_setter_get_data (setter); data = gst_tag_setter_get_data (setter);
g_static_mutex_lock (&data->lock); GST_TAG_DATA_LOCK (data);
mode = data->mode; mode = data->mode;
g_static_mutex_unlock (&data->lock); GST_TAG_DATA_UNLOCK (data);
return mode; return mode;
} }