gst/gstutils.h: Make GST_BOILERPLATE thread-safe if building with GLib 2.14 or newer.

Original commit message from CVS:
* gst/gstutils.h:
Make GST_BOILERPLATE thread-safe if building with GLib 2.14 or newer.
This commit is contained in:
Sebastian Dröge 2008-05-08 11:27:56 +00:00
parent 849c17d326
commit 4cfe6ec1b9
2 changed files with 21 additions and 5 deletions

View file

@ -1,3 +1,8 @@
2008-05-08 Sebastian Dröge <slomo@circular-chaos.org>
* gst/gstutils.h:
Make GST_BOILERPLATE thread-safe if building with GLib 2.14 or newer.
2008-05-08 Sebastian Dröge <slomo@circular-chaos.org> 2008-05-08 Sebastian Dröge <slomo@circular-chaos.org>
Based on a patch by: Sjoerd Simons <sjoerd at luon dot net> Based on a patch by: Sjoerd Simons <sjoerd at luon dot net>

View file

@ -88,6 +88,15 @@ GType gst_type_register_static_full (GType parent_type,
/* Macros for defining classes. Ideas taken from Bonobo, which took theirs /* Macros for defining classes. Ideas taken from Bonobo, which took theirs
from Nautilus and GOB. */ from Nautilus and GOB. */
/* FIXME: Use g_once_init_* unconditionally once we depend on glib 2.14 */
#if GLIB_CHECK_VERSION (2, 14, 0)
#define __gst_once_init_enter(val) (g_once_init_enter (val))
#define __gst_once_init_leave(val,newval) (g_once_init_leave (val, newval))
#else
#define __gst_once_init_enter(val) (G_UNLIKELY (*(val) == 0))
#define __gst_once_init_leave(val,newval) (*(val) = newval)
#endif
/** /**
* GST_BOILERPLATE_FULL: * GST_BOILERPLATE_FULL:
* @type: the name of the type struct * @type: the name of the type struct
@ -128,10 +137,11 @@ GType type_as_function ## _get_type (void); \
GType \ GType \
type_as_function ## _get_type (void) \ type_as_function ## _get_type (void) \
{ \ { \
static GType object_type = 0; \ static volatile GType object_type = 0; \
if (G_UNLIKELY (object_type == 0)) { \ if (__gst_once_init_enter ((gsize *) &object_type)) { \
object_type = gst_type_register_static_full (parent_type_macro, #type, \ GType _type; \
sizeof (type ## Class), \ _type = gst_type_register_static_full (parent_type_macro, #type, \
sizeof (type ## Class), \
type_as_function ## _base_init, \ type_as_function ## _base_init, \
NULL, /* base_finalize */ \ NULL, /* base_finalize */ \
type_as_function ## _class_init_trampoline, \ type_as_function ## _class_init_trampoline, \
@ -142,7 +152,8 @@ type_as_function ## _get_type (void) \
(GInstanceInitFunc) type_as_function ## _init, \ (GInstanceInitFunc) type_as_function ## _init, \
NULL, \ NULL, \
(GTypeFlags) 0); \ (GTypeFlags) 0); \
additional_initializations (object_type); \ additional_initializations (_type); \
__gst_once_init_leave ((gsize *) &object_type, (gsize) _type); \
} \ } \
return object_type; \ return object_type; \
} }