[gtk/gtk-3-24: 1/2] Use g_once for all the mkenums template files
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gtk-3-24: 1/2] Use g_once for all the mkenums template files
- Date: Mon, 27 May 2019 09:30:52 +0000 (UTC)
commit b565f5d5c23a12d255242a9e3ad0d688134de0b8
Author: Federico Mena Quintero <federico gnome org>
Date: Tue May 21 10:32:08 2019 -0500
Use g_once for all the mkenums template files
Without this, initialization of enum/flags values from multithreaded
programs may not work correctly.
Fixes #1617.
gdk/gdkenumtypes.c.template | 21 +++++++++++++--------
gtk/gtkprivatetypebuiltins.c.template | 21 +++++++++++++--------
gtk/gtktypebuiltins.c.template | 21 +++++++++++++--------
3 files changed, 39 insertions(+), 24 deletions(-)
---
diff --git a/gdk/gdkenumtypes.c.template b/gdk/gdkenumtypes.c.template
index dcafd8d251..df9edfefa1 100644
--- a/gdk/gdkenumtypes.c.template
+++ b/gdk/gdkenumtypes.c.template
@@ -12,21 +12,26 @@
GType
@enum_name@_get_type (void)
{
- static GType etype = 0;
- if (G_UNLIKELY(etype == 0)) {
- static const G@Type@Value values[] = {
+ static volatile gsize g_define_type_id__volatile = 0;
+
+ if (g_once_init_enter (&g_define_type_id__volatile))
+ {
+ static const G@Type@Value values[] = {
/*** END value-header ***/
/*** BEGIN value-production ***/
- { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+ { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
/*** END value-production ***/
/*** BEGIN value-tail ***/
- { 0, NULL, NULL }
- };
- etype = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+ { 0, NULL, NULL }
+ };
+ GType g_define_type_id =
+ g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+ g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
}
- return etype;
+
+ return g_define_type_id__volatile;
}
/*** END value-tail ***/
diff --git a/gtk/gtkprivatetypebuiltins.c.template b/gtk/gtkprivatetypebuiltins.c.template
index db65d1efd6..2565208bfc 100644
--- a/gtk/gtkprivatetypebuiltins.c.template
+++ b/gtk/gtkprivatetypebuiltins.c.template
@@ -14,21 +14,26 @@
GType
_@enum_name@_get_type (void)
{
- static GType etype = 0;
- if (G_UNLIKELY(etype == 0)) {
- static const G@Type@Value values[] = {
+ static volatile gsize g_define_type_id__volatile = 0;
+
+ if (g_once_init_enter (&g_define_type_id__volatile))
+ {
+ static const G@Type@Value values[] = {
/*** END value-header ***/
/*** BEGIN value-production ***/
- { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+ { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
/*** END value-production ***/
/*** BEGIN value-tail ***/
- { 0, NULL, NULL }
- };
- etype = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+ { 0, NULL, NULL }
+ };
+ GType g_define_type_id =
+ g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+ g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
}
- return etype;
+
+ return g_define_type_id__volatile;
}
/*** END value-tail ***/
diff --git a/gtk/gtktypebuiltins.c.template b/gtk/gtktypebuiltins.c.template
index fbd21db368..f4d748b7b9 100644
--- a/gtk/gtktypebuiltins.c.template
+++ b/gtk/gtktypebuiltins.c.template
@@ -13,21 +13,26 @@
GType
@enum_name@_get_type (void)
{
- static GType etype = 0;
- if (G_UNLIKELY(etype == 0)) {
- static const G@Type@Value values[] = {
+ static volatile gsize g_define_type_id__volatile = 0;
+
+ if (g_once_init_enter (&g_define_type_id__volatile))
+ {
+ static const G@Type@Value values[] = {
/*** END value-header ***/
/*** BEGIN value-production ***/
- { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+ { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
/*** END value-production ***/
/*** BEGIN value-tail ***/
- { 0, NULL, NULL }
- };
- etype = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+ { 0, NULL, NULL }
+ };
+ GType g_define_type_id =
+ g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+ g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
}
- return etype;
+
+ return g_define_type_id__volatile;
}
/*** END value-tail ***/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]