[gst-cvs] gst-plugins-base: audio: make public get_type() functions thread-safe

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


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

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

audio: make public get_type() functions thread-safe

---

 gst-libs/gst/audio/gstaudioclock.c    |   38 ++++++++++++++++----------------
 gst-libs/gst/audio/gstbaseaudiosink.c |   10 +++++---
 gst-libs/gst/audio/gstbaseaudiosrc.c  |    9 ++++---
 3 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/gst-libs/gst/audio/gstaudioclock.c b/gst-libs/gst/audio/gstaudioclock.c
index 95a8a0d..9d6e485 100644
--- a/gst-libs/gst/audio/gstaudioclock.c
+++ b/gst-libs/gst/audio/gstaudioclock.c
@@ -56,28 +56,28 @@ static GstSystemClockClass *parent_class = NULL;
 GType
 gst_audio_clock_get_type (void)
 {
-  static GType clock_type = 0;
-
-  if (!clock_type) {
-    static const GTypeInfo clock_info = {
-      sizeof (GstAudioClockClass),
-      NULL,
-      NULL,
-      (GClassInitFunc) gst_audio_clock_class_init,
-      NULL,
-      NULL,
-      sizeof (GstAudioClock),
-      4,
-      (GInstanceInitFunc) gst_audio_clock_init,
-      NULL
-    };
-
-    clock_type = g_type_register_static (GST_TYPE_SYSTEM_CLOCK, "GstAudioClock",
+  static volatile gsize clock_type = 0;
+  static const GTypeInfo clock_info = {
+    sizeof (GstAudioClockClass),
+    NULL,
+    NULL,
+    (GClassInitFunc) gst_audio_clock_class_init,
+    NULL,
+    NULL,
+    sizeof (GstAudioClock),
+    4,
+    (GInstanceInitFunc) gst_audio_clock_init,
+    NULL
+  };
+
+  if (g_once_init_enter (&clock_type)) {
+    GType tmp = g_type_register_static (GST_TYPE_SYSTEM_CLOCK, "GstAudioClock",
         &clock_info, 0);
+    g_once_init_leave (&clock_type, tmp);
   }
-  return clock_type;
-}
 
+  return (GType) clock_type;
+}
 
 static void
 gst_audio_clock_class_init (GstAudioClockClass * klass)
diff --git a/gst-libs/gst/audio/gstbaseaudiosink.c b/gst-libs/gst/audio/gstbaseaudiosink.c
index 21117f2..8e7760b 100644
--- a/gst-libs/gst/audio/gstbaseaudiosink.c
+++ b/gst-libs/gst/audio/gstbaseaudiosink.c
@@ -110,7 +110,7 @@ enum
 GType
 gst_base_audio_sink_slave_method_get_type (void)
 {
-  static GType slave_method_type = 0;
+  static volatile gsize slave_method_type = 0;
   static const GEnumValue slave_method[] = {
     {GST_BASE_AUDIO_SINK_SLAVE_RESAMPLE, "GST_BASE_AUDIO_SINK_SLAVE_RESAMPLE",
         "resample"},
@@ -119,11 +119,13 @@ gst_base_audio_sink_slave_method_get_type (void)
     {0, NULL, NULL},
   };
 
-  if (!slave_method_type) {
-    slave_method_type =
+  if (g_once_init_enter (&slave_method_type)) {
+    GType tmp =
         g_enum_register_static ("GstBaseAudioSinkSlaveMethod", slave_method);
+    g_once_init_leave (&slave_method_type, tmp);
   }
-  return slave_method_type;
+
+  return (GType) slave_method_type;
 }
 
 
diff --git a/gst-libs/gst/audio/gstbaseaudiosrc.c b/gst-libs/gst/audio/gstbaseaudiosrc.c
index 1eb0a89..8953370 100644
--- a/gst-libs/gst/audio/gstbaseaudiosrc.c
+++ b/gst-libs/gst/audio/gstbaseaudiosrc.c
@@ -48,7 +48,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_base_audio_src_debug);
 GType
 gst_base_audio_src_slave_method_get_type (void)
 {
-  static GType slave_method_type = 0;
+  static volatile gsize slave_method_type = 0;
   /* FIXME 0.11: nick should be "retimestamp" not "re-timestamp" */
   static const GEnumValue slave_method[] = {
     {GST_BASE_AUDIO_SRC_SLAVE_RESAMPLE,
@@ -60,11 +60,12 @@ gst_base_audio_src_slave_method_get_type (void)
     {0, NULL, NULL},
   };
 
-  if (!slave_method_type) {
-    slave_method_type =
+  if (g_once_init_enter (&slave_method_type)) {
+    GType tmp =
         g_enum_register_static ("GstBaseAudioSrcSlaveMethod", slave_method);
+    g_once_init_leave (&slave_method_type, tmp);
   }
-  return slave_method_type;
+  return (GType) slave_method_type;
 }
 
 #define GST_BASE_AUDIO_SRC_GET_PRIVATE(obj)  \





More information about the Gstreamer-commits mailing list