rtsp: make public _get_type() functions thread-safe
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 8 Oct 2010 10:23:33 +0000 (11:23 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 8 Oct 2010 10:34:59 +0000 (11:34 +0100)
gst-libs/gst/rtsp/gstrtspextension.c
gst-libs/gst/rtsp/gstrtsptransport.c
gst-libs/gst/rtsp/gstrtspurl.c

index 716df04..cef7a70 100644 (file)
@@ -54,25 +54,25 @@ static guint gst_rtsp_extension_signals[LAST_SIGNAL] = { 0 };
 GType
 gst_rtsp_extension_get_type (void)
 {
-  static GType gst_rtsp_extension_type = 0;
-
-  if (!gst_rtsp_extension_type) {
-    static const GTypeInfo gst_rtsp_extension_info = {
-      sizeof (GstRTSPExtensionInterface),
-      (GBaseInitFunc) gst_rtsp_extension_iface_init,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      0,
-      0,
-      NULL,
-    };
-
-    gst_rtsp_extension_type = g_type_register_static (G_TYPE_INTERFACE,
+  static volatile gsize gst_rtsp_extension_type = 0;
+  static const GTypeInfo gst_rtsp_extension_info = {
+    sizeof (GstRTSPExtensionInterface),
+    (GBaseInitFunc) gst_rtsp_extension_iface_init,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    0,
+    0,
+    NULL,
+  };
+
+  if (g_once_init_enter (&gst_rtsp_extension_type)) {
+    GType tmp = g_type_register_static (G_TYPE_INTERFACE,
         "GstRTSPExtension", &gst_rtsp_extension_info, 0);
+    g_once_init_leave (&gst_rtsp_extension_type, tmp);
   }
-  return gst_rtsp_extension_type;
+  return (GType) gst_rtsp_extension_type;
 }
 
 static void
index 2d4a3c6..ad1b8e2 100644 (file)
@@ -117,7 +117,7 @@ static const RTSPLTransMap ltrans[] = {
 GType
 gst_rtsp_lower_trans_get_type (void)
 {
-  static GType rtsp_lower_trans_type = 0;
+  static volatile gsize rtsp_lower_trans_type = 0;
   static const GFlagsValue rtsp_lower_trans[] = {
     {GST_RTSP_LOWER_TRANS_UDP, "GST_RTSP_LOWER_TRANS_UDP", "udp-unicast"},
     {GST_RTSP_LOWER_TRANS_UDP_MCAST, "GST_RTSP_LOWER_TRANS_UDP_MCAST",
@@ -127,11 +127,12 @@ gst_rtsp_lower_trans_get_type (void)
     {0, NULL, NULL},
   };
 
-  if (!rtsp_lower_trans_type) {
-    rtsp_lower_trans_type =
-        g_flags_register_static ("GstRTSPLowerTrans", rtsp_lower_trans);
+  if (g_once_init_enter (&rtsp_lower_trans_type)) {
+    GType tmp = g_flags_register_static ("GstRTSPLowerTrans", rtsp_lower_trans);
+    g_once_init_leave (&rtsp_lower_trans_type, tmp);
   }
-  return rtsp_lower_trans_type;
+
+  return (GType) rtsp_lower_trans_type;
 }
 
 #define RTSP_TRANSPORT_PARAMETER_IS_UNIQUE(param) \
index bba6f25..0a71091 100644 (file)
 
 #include "gstrtspurl.h"
 
-static void
-register_rtsp_url_type (GType * id)
-{
-  *id = g_boxed_type_register_static ("GstRTSPUrl",
-      (GBoxedCopyFunc) gst_rtsp_url_copy, (GBoxedFreeFunc) gst_rtsp_url_free);
-}
-
 GType
 gst_rtsp_url_get_type (void)
 {
-  static GType id;
-  static GOnce once = G_ONCE_INIT;
+  static volatile gsize url_type = 0;
+
+  if (g_once_init_enter (&url_type)) {
+    GType tmp = g_boxed_type_register_static ("GstRTSPUrl",
+        (GBoxedCopyFunc) gst_rtsp_url_copy, (GBoxedFreeFunc) gst_rtsp_url_free);
+    g_once_init_leave (&url_type, tmp);
+  }
 
-  g_once (&once, (GThreadFunc) register_rtsp_url_type, &id);
-  return id;
+  return (GType) url_type;
 }
 
 static const struct