[pango] Make enum get_type functions thread-safe
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango] Make enum get_type functions thread-safe
- Date: Wed, 29 Aug 2012 02:21:01 +0000 (UTC)
commit 88692e4eb0a971f6d32da9207c9c91c8d8c7c8d9
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Aug 28 22:06:20 2012 -0400
Make enum get_type functions thread-safe
Use a more modern, template-based way of calling glib-mkenums,
and use templates that use g_once_init_enter/leave to be
thread-safe.
pango/Makefile.am | 29 ++++++++++-------------------
pango/pango-enum-types.c.template | 36 ++++++++++++++++++++++++++++++++++++
pango/pango-enum-types.h.template | 24 ++++++++++++++++++++++++
3 files changed, 70 insertions(+), 19 deletions(-)
---
diff --git a/pango/Makefile.am b/pango/Makefile.am
index 0da59c8..435b495 100644
--- a/pango/Makefile.am
+++ b/pango/Makefile.am
@@ -128,29 +128,18 @@ pangoinclude_HEADERS = \
pango-enum-types.h
pango-enum-types.h: s-enum-types-h
-s-enum-types-h: $(pango_headers) Makefile.am
+s-enum-types-h: $(pango_headers) Makefile.am pango-enum-types.h.template
$(AM_V_GEN) ( cd $(srcdir) && $(GLIB_MKENUMS) \
- --fhead "#ifndef __PANGO_ENUM_TYPES_H__\n#define __PANGO_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \
- --fprod "/* enumerations from \"@filename \" */\n" \
- --vhead "GType @enum_name _get_type (void);\n#define @ENUMPREFIX _TYPE_@ENUMSHORT@ (@enum_name _get_type())\n" \
- --ftail "G_END_DECLS\n\n#endif /* __PANGO_ENUM_TYPES_H__ */" \
- $(pango_headers) ) > tmp-pango-enum-types.h \
- && (cmp -s tmp-pango-enum-types.h pango-enum-types.h || cp tmp-pango-enum-types.h pango-enum-types.h ) \
- && $(RM) tmp-pango-enum-types.h \
- && echo timestamp > $(@F)
+ --template pango-enum-types.h.template \
+ $(pango_headers) ) > pango-enum-types.h.tmp \
+ && mv pango-enum-types.h.tmp pango-enum-types.h
pango-enum-types.c: s-enum-types-c
-s-enum-types-c: $(pango_headers) Makefile.am
+s-enum-types-c: $(pango_headers) Makefile.am pango-enum-types.c.template
$(AM_V_GEN) ( cd $(srcdir) && $(GLIB_MKENUMS) \
- --fhead "#include <pango.h>" \
- --fprod "\n/* enumerations from \"@filename \" */" \
- --vhead "GType\n enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G Type@Value values[] = {" \
- --vprod " { @VALUENAME@, \"@VALUENAME \", \"@valuenick \" }," \
- --vtail " { 0, NULL, NULL }\n };\n etype = g_ type@_register_static (g_intern_static_string (\"@EnumName \"), values);\n }\n return etype;\n}\n" \
- $(pango_headers) ) > tmp-pango-enum-types.c \
- && (cmp -s tmp-pango-enum-types.c pango-enum-types.c || cp tmp-pango-enum-types.c pango-enum-types.c ) \
- && $(RM) tmp-pango-enum-types.c \
- && echo timestamp > $(@F)
+ --template pango-enum-types.c.template \
+ $(pango_headers) ) > pango-enum-types.c.tmp \
+ && mv pango-enum-types.c.tmp pango-enum-types.c
pango-features.h:
$(AM_V_GEN) cd $(top_builddir) && ./config.status pango/pango-features.h
@@ -444,6 +433,8 @@ pango_querymodules_LDADD += libpango-$(PANGO_API_VERSION).la $(GLIB_LIBS)
EXTRA_DIST = \
pango-enum-types.h \
+ pango-enum-types.h.template \
+ pango-enum-types.c.template \
module-defs.h \
module-defs.h.win32 \
module-defs-lang.c.win32 \
diff --git a/pango/pango-enum-types.c.template b/pango/pango-enum-types.c.template
new file mode 100644
index 0000000..c12f4b3
--- /dev/null
+++ b/pango/pango-enum-types.c.template
@@ -0,0 +1,36 @@
+/*** BEGIN file-header ***/
+#include <pango.h>
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+ enum_name@_get_type (void)
+{
+ 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@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+ { 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 g_define_type_id__volatile;
+}
+
+/*** END value-tail ***/
diff --git a/pango/pango-enum-types.h.template b/pango/pango-enum-types.h.template
new file mode 100644
index 0000000..e5ffbe8
--- /dev/null
+++ b/pango/pango-enum-types.h.template
@@ -0,0 +1,24 @@
+/*** BEGIN file-header ***/
+#ifndef __PANGO_ENUM_TYPES_H__
+#define __PANGO_ENUM_TYPES_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType @enum_name _get_type (void) G_GNUC_CONST;
+#define @ENUMPREFIX _TYPE_@ENUMSHORT@ (@enum_name _get_type ())
+/*** END value-header ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* __PANGO_ENUM_TYPES_H__ */
+/*** END file-tail ***/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]