diff options
author | Rob Clark <rob@ti.com> | 2010-03-15 17:29:36 -0500 |
---|---|---|
committer | Felipe Contreras <felipe.contreras@nokia.com> | 2010-04-16 17:26:08 +0300 |
commit | 30f3679d309b3ea91c9ca385a5d026abf97ec5a2 (patch) | |
tree | 7713117465db304bf34af225ea89b56b56727b50 /omx | |
parent | be97f6edbfdccfe37227361ea089aecdef7905ff (diff) |
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@nokia.com>
Diffstat (limited to 'omx')
-rw-r--r-- | 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) |