[gdk-pixbuf/enum-thread-safe] Make enum GType registration thread safe
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf/enum-thread-safe] Make enum GType registration thread safe
- Date: Mon, 7 Dec 2020 23:17:40 +0000 (UTC)
commit 5ac0393304cc0d17d633e9f8c22d97d4143b6953
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed Nov 18 14:03:16 2020 +0000
Make enum GType registration thread safe
Use g_once_init_enter/leave to ensure that enumeration types can be
registered across threads.
gdk-pixbuf/gdk-pixbuf-enum-types.c.template | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gdk-pixbuf/gdk-pixbuf-enum-types.c.template b/gdk-pixbuf/gdk-pixbuf-enum-types.c.template
index a4252f336..1e30bd2b1 100644
--- a/gdk-pixbuf/gdk-pixbuf-enum-types.c.template
+++ b/gdk-pixbuf/gdk-pixbuf-enum-types.c.template
@@ -13,9 +13,9 @@
GType
@enum_name@_get_type (void)
{
- static GType etype = 0;
+ static gsize g_define_type;
- if (G_UNLIKELY(etype == 0)) {
+ if (g_once_init_enter (&g_define_type)) {
static const G@Type@Value values[] = {
/*** END value-header ***/
@@ -26,9 +26,11 @@ GType
/*** BEGIN value-tail ***/
{ 0, NULL, NULL }
};
- etype = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+ GType enum_type = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+
+ g_once_init_leave (&g_define_type, enum_type);
}
- return etype;
+ return g_define_type;
}
/*** END value-tail ***/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]