diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2020-11-18 14:03:16 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2020-12-07 23:16:00 +0000 |
commit | 5ac0393304cc0d17d633e9f8c22d97d4143b6953 (patch) | |
tree | 052328ab0266887749f848d8f87a81ec2237c128 | |
parent | f1467ce6aafa26b8fad30b7fae185afaf3a484f5 (diff) | |
download | gdk-pixbuf-5ac0393304cc0d17d633e9f8c22d97d4143b6953.tar.gz |
Make enum GType registration thread safe
Use g_once_init_enter/leave to ensure that enumeration types can be
registered across threads.
-rw-r--r-- | gdk-pixbuf/gdk-pixbuf-enum-types.c.template | 10 |
1 files 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 ***/ |