Use macros to register boxed types thread safely
authorOlivier Crête <olivier.crete@collabora.com>
Sat, 28 Jan 2012 14:35:51 +0000 (14:35 +0000)
committerOlivier Crête <olivier.crete@collabora.com>
Sat, 28 Jan 2012 16:42:38 +0000 (16:42 +0000)
gst/gstcaps.c
gst/gstiterator.c
gst/gstpadtemplate.c
gst/gstparse.c
gst/gstsegment.c
gst/gsttaglist.c
gst/gsttypefind.c
gst/gstvalue.c
libs/gst/base/gstbaseparse.c
libs/gst/base/gstindex.c

index 2ada66f..922c77c 100644 (file)
@@ -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:
index 6940349..99369df 100644 (file)
@@ -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,
index c9b375a..d7fe0a5 100644 (file)
@@ -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:
index ef8dcd5..3e6714d 100644 (file)
@@ -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:
index 84e217a..64aa09d 100644 (file)
@@ -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:
index b6af6e1..c1a2ab0 100644 (file)
@@ -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)
index d635388..bc4f85b 100644 (file)
 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:
index 3caa2e4..fc292ae 100644 (file)
@@ -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,
index 767a15d..adc33e8 100644 (file)
@@ -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:
index 8d69b06..9e44317 100644 (file)
@@ -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 \