[gst-cvs] gst-openmax: util: thread safety for _get_type() functions
Felipe Contreras
felipec at kemper.freedesktop.org
Fri Apr 16 08:20:27 PDT 2010
Module: gst-openmax
Branch: master
Commit: 30f3679d309b3ea91c9ca385a5d026abf97ec5a2
URL: http://cgit.freedesktop.org/gstreamer/gst-openmax/commit/?id=30f3679d309b3ea91c9ca385a5d026abf97ec5a2
Author: Rob Clark <rob at ti.com>
Date: Mon Mar 15 17:29:36 2010 -0500
util: thread safety for _get_type() functions
Reading and writing an int is not sufficient synchronization without
barrier instructions. Using g_once_init_enter() (which uses
g_atomic_pointer_get()) provides SMP safety.
Signed-off-by: Felipe Contreras <felipe.contreras at nokia.com>
---
omx/gstomx_util.h | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/omx/gstomx_util.h b/omx/gstomx_util.h
index 593b491..6450c0d 100644
--- a/omx/gstomx_util.h
+++ b/omx/gstomx_util.h
@@ -169,9 +169,12 @@ static void type_class_init_trampoline (gpointer g_class, gpointer class_data)\
} \
GType type_as_function ## _get_type (void) \
{ \
- static GType _type = 0; \
- if (G_UNLIKELY (_type == 0)) \
- { \
+ /* The typedef for GType may be gulong or gsize, depending on the \
+ * system and whether the compiler is c++ or not. The g_once_init_* \
+ * functions always take a gsize * though ... */ \
+ static volatile gsize gonce_data = 0; \
+ if (g_once_init_enter (&gonce_data)) { \
+ GType _type; \
GTypeInfo *type_info; \
type_info = g_new0 (GTypeInfo, 1); \
type_info->class_size = sizeof (type ## Class); \
@@ -182,9 +185,11 @@ GType type_as_function ## _get_type (void) \
_type = g_type_register_static (parent_type_macro, #type, type_info, 0);\
g_free (type_info); \
additional_initializations (_type); \
+ g_once_init_leave (&gonce_data, (gsize) _type); \
} \
- return _type; \
+ return (GType) gonce_data; \
}
+
#define GSTOMX_BOILERPLATE(type,type_as_function,parent_type,parent_type_macro) \
GSTOMX_BOILERPLATE_FULL (type, type_as_function, parent_type, parent_type_macro, \
__GST_DO_NOTHING)
More information about the Gstreamer-commits
mailing list