From 5ac0393304cc0d17d633e9f8c22d97d4143b6953 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 18 Nov 2020 14:03:16 +0000 Subject: 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(-) (limited to 'gdk-pixbuf') 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 ***/ -- cgit v1.2.1