From e234a10c635cb290fbab1284b3a86202e9fc124c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Sat, 28 Jan 2012 14:35:51 +0000 Subject: [PATCH] Use macros to register boxed types thread safely --- gst/gstcaps.c | 11 +---------- gst/gstiterator.c | 12 ++---------- gst/gstpadtemplate.c | 12 +----------- gst/gstparse.c | 16 +++------------- gst/gstsegment.c | 14 ++------------ gst/gsttaglist.c | 22 ++++++---------------- gst/gsttypefind.c | 11 +---------- gst/gstvalue.c | 15 ++------------- libs/gst/base/gstbaseparse.c | 18 +++--------------- libs/gst/base/gstindex.c | 15 +++------------ 10 files changed, 24 insertions(+), 122 deletions(-) diff --git a/gst/gstcaps.c b/gst/gstcaps.c index 2ada66f..922c77c 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -351,16 +351,7 @@ gst_caps_new_full_valist (GstStructure * structure, va_list var_args) return caps; } -GType -gst_static_caps_get_type (void) -{ - static GType staticcaps_type = 0; - - if (G_UNLIKELY (staticcaps_type == 0)) { - staticcaps_type = g_pointer_type_register_static ("GstStaticCaps"); - } - return staticcaps_type; -} +G_DEFINE_POINTER_TYPE (GstStaticCaps, gst_static_caps); /** * gst_static_caps_get: diff --git a/gst/gstiterator.c b/gst/gstiterator.c index 6940349..99369df 100644 --- a/gst/gstiterator.c +++ b/gst/gstiterator.c @@ -85,16 +85,8 @@ gst_iterator_copy (const GstIterator * it) return copy; } -GType -gst_iterator_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) - type = g_boxed_type_register_static ("GstIterator", - (GBoxedCopyFunc) gst_iterator_copy, (GBoxedFreeFunc) gst_iterator_free); - return type; -} +G_DEFINE_BOXED_TYPE (GstIterator, gst_iterator, + (GBoxedCopyFunc) gst_iterator_copy, (GBoxedFreeFunc) gst_iterator_free); static void gst_iterator_init (GstIterator * it, diff --git a/gst/gstpadtemplate.c b/gst/gstpadtemplate.c index c9b375a..d7fe0a5 100644 --- a/gst/gstpadtemplate.c +++ b/gst/gstpadtemplate.c @@ -272,17 +272,7 @@ name_is_valid (const gchar * name, GstPadPresence presence) return TRUE; } -GType -gst_static_pad_template_get_type (void) -{ - static GType staticpadtemplate_type = 0; - - if (G_UNLIKELY (staticpadtemplate_type == 0)) { - staticpadtemplate_type = - g_pointer_type_register_static ("GstStaticPadTemplate"); - } - return staticpadtemplate_type; -} +G_DEFINE_POINTER_TYPE (GstStaticPadTemplate, gst_static_pad_template); /** * gst_static_pad_template_get: diff --git a/gst/gstparse.c b/gst/gstparse.c index ef8dcd5..3e6714d 100644 --- a/gst/gstparse.c +++ b/gst/gstparse.c @@ -64,19 +64,9 @@ gst_parse_context_copy (const GstParseContext * context) return ret; } -GType -gst_parse_context_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) { - type = g_boxed_type_register_static ("GstParseContext", - (GBoxedCopyFunc) gst_parse_context_copy, - (GBoxedFreeFunc) gst_parse_context_free); - } - - return type; -} +G_DEFINE_BOXED_TYPE (GstParseContext, gst_parse_context, + (GBoxedCopyFunc) gst_parse_context_copy, + (GBoxedFreeFunc) gst_parse_context_free); /** * gst_parse_error_quark: diff --git a/gst/gstsegment.c b/gst/gstsegment.c index 84e217a..64aa09d 100644 --- a/gst/gstsegment.c +++ b/gst/gstsegment.c @@ -113,18 +113,8 @@ gst_segment_copy_into (const GstSegment * src, GstSegment * dest) memcpy (dest, src, sizeof (GstSegment)); } -GType -gst_segment_get_type (void) -{ - static GType gst_segment_type = 0; - - if (G_UNLIKELY (gst_segment_type == 0)) { - gst_segment_type = g_boxed_type_register_static ("GstSegment", - (GBoxedCopyFunc) gst_segment_copy, (GBoxedFreeFunc) gst_segment_free); - } - - return gst_segment_type; -} +G_DEFINE_BOXED_TYPE (GstSegment, gst_segment, + (GBoxedCopyFunc) gst_segment_copy, (GBoxedFreeFunc) gst_segment_free); /** * gst_segment_new: diff --git a/gst/gsttaglist.c b/gst/gsttaglist.c index b6af6e1..c1a2ab0 100644 --- a/gst/gsttaglist.c +++ b/gst/gsttaglist.c @@ -82,23 +82,13 @@ static GMutex __tag_mutex; /* tags hash table: maps tag name string => GstTagInfo */ static GHashTable *__tags; -GType -gst_tag_list_get_type (void) -{ - static GType _gst_tag_list_type = 0; - - if (G_UNLIKELY (_gst_tag_list_type == 0)) { - _gst_tag_list_type = g_boxed_type_register_static ("GstTagList", - (GBoxedCopyFunc) gst_tag_list_copy, (GBoxedFreeFunc) gst_tag_list_free); - -#if 0 - g_value_register_transform_func (_gst_tag_list_type, G_TYPE_STRING, - _gst_structure_transform_to_string); -#endif - } +G_DEFINE_BOXED_TYPE (GstTagList, gst_tag_list, + (GBoxedCopyFunc) gst_tag_list_copy, (GBoxedFreeFunc) gst_tag_list_free); - return _gst_tag_list_type; -} +/* FIXME: had code: + * g_value_register_transform_func (_gst_tag_list_type, G_TYPE_STRING, + * _gst_structure_transform_to_string); + */ void _priv_gst_tag_initialize (void) diff --git a/gst/gsttypefind.c b/gst/gsttypefind.c index d635388..bc4f85b 100644 --- a/gst/gsttypefind.c +++ b/gst/gsttypefind.c @@ -38,16 +38,7 @@ GST_DEBUG_CATEGORY_EXTERN (type_find_debug); #define GST_CAT_DEFAULT type_find_debug -GType -gst_type_find_get_type (void) -{ - static GType typefind_type = 0; - - if (G_UNLIKELY (typefind_type == 0)) { - typefind_type = g_pointer_type_register_static ("GstTypeFind"); - } - return typefind_type; -} +G_DEFINE_POINTER_TYPE (GstTypeFind, gst_type_find); /** * gst_type_find_register: diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 3caa2e4..fc292ae 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -5508,19 +5508,8 @@ static const GTypeValueTable _gst_fraction_value_table = { FUNC_VALUE_GET_TYPE (fraction, "GstFraction"); -GType -gst_date_time_get_type (void) -{ - static GType gst_date_time_type = 0; - - if (G_UNLIKELY (gst_date_time_type == 0)) { - gst_date_time_type = g_boxed_type_register_static ("GstDateTime", - (GBoxedCopyFunc) gst_date_time_ref, - (GBoxedFreeFunc) gst_date_time_unref); - } - - return gst_date_time_type; -} +G_DEFINE_BOXED_TYPE (GstDateTime, gst_date_time, + (GBoxedCopyFunc) gst_date_time_ref, (GBoxedFreeFunc) gst_date_time_unref); static const GTypeValueTable _gst_bitmask_value_table = { gst_value_init_bitmask, diff --git a/libs/gst/base/gstbaseparse.c b/libs/gst/base/gstbaseparse.c index 767a15d..adc33e8 100644 --- a/libs/gst/base/gstbaseparse.c +++ b/libs/gst/base/gstbaseparse.c @@ -611,21 +611,9 @@ gst_base_parse_frame_free (GstBaseParseFrame * frame) } } -GType -gst_base_parse_frame_get_type (void) -{ - static volatile gsize frame_type = 0; - - if (g_once_init_enter (&frame_type)) { - GType _type; - - _type = g_boxed_type_register_static ("GstBaseParseFrame", - (GBoxedCopyFunc) gst_base_parse_frame_copy, - (GBoxedFreeFunc) gst_base_parse_frame_free); - g_once_init_leave (&frame_type, _type); - } - return (GType) frame_type; -} +G_DEFINE_BOXED_TYPE (GstBaseParseFrame, gst_base_parse_frame, + (GBoxedCopyFunc) gst_base_parse_frame_copy, + (GBoxedFreeFunc) gst_base_parse_frame_free); /** * gst_base_parse_frame_init: diff --git a/libs/gst/base/gstindex.c b/libs/gst/base/gstindex.c index 8d69b06..9e44317 100644 --- a/libs/gst/base/gstindex.c +++ b/libs/gst/base/gstindex.c @@ -131,18 +131,9 @@ gst_index_resolver_get_type (void) return index_resolver_type; } -GType -gst_index_entry_get_type (void) -{ - static GType index_entry_type = 0; - - if (!index_entry_type) { - index_entry_type = g_boxed_type_register_static ("GstIndexEntry", - (GBoxedCopyFunc) gst_index_entry_copy, - (GBoxedFreeFunc) gst_index_entry_free); - } - return index_entry_type; -} +G_DEFINE_BOXED_TYPE (GstIndexEntry, gst_index_entry, + (GBoxedCopyFunc) gst_index_entry_copy, + (GBoxedFreeFunc) gst_index_entry_free); #if 0 #define _do_init \ -- 2.7.4