[gst-cvs] gst-plugins-base: rtsp: make public _get_type() functions thread-safe

Tim Müller tpm at kemper.freedesktop.org
Fri Oct 8 03:40:47 PDT 2010


Module: gst-plugins-base
Branch: master
Commit: 6f87bc2307f49d0736dde9d7291003d68ff46880
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-base/commit/?id=6f87bc2307f49d0736dde9d7291003d68ff46880

Author: Tim-Philipp Müller <tim.muller at collabora.co.uk>
Date:   Fri Oct  8 11:23:33 2010 +0100

rtsp: make public _get_type() functions thread-safe

---

 gst-libs/gst/rtsp/gstrtspextension.c |   32 ++++++++++++++++----------------
 gst-libs/gst/rtsp/gstrtsptransport.c |   11 ++++++-----
 gst-libs/gst/rtsp/gstrtspurl.c       |   19 ++++++++-----------
 3 files changed, 30 insertions(+), 32 deletions(-)

diff --git a/gst-libs/gst/rtsp/gstrtspextension.c b/gst-libs/gst/rtsp/gstrtspextension.c
index 716df04..cef7a70 100644
--- a/gst-libs/gst/rtsp/gstrtspextension.c
+++ b/gst-libs/gst/rtsp/gstrtspextension.c
@@ -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
diff --git a/gst-libs/gst/rtsp/gstrtsptransport.c b/gst-libs/gst/rtsp/gstrtsptransport.c
index 2d4a3c6..ad1b8e2 100644
--- a/gst-libs/gst/rtsp/gstrtsptransport.c
+++ b/gst-libs/gst/rtsp/gstrtsptransport.c
@@ -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) \
diff --git a/gst-libs/gst/rtsp/gstrtspurl.c b/gst-libs/gst/rtsp/gstrtspurl.c
index bba6f25..0a71091 100644
--- a/gst-libs/gst/rtsp/gstrtspurl.c
+++ b/gst-libs/gst/rtsp/gstrtspurl.c
@@ -54,21 +54,18 @@
 
 #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





More information about the Gstreamer-commits mailing list