[evolution-ews/gnome-3-8] Bug #681837 - Make enum type registration thread safe



commit d3ed6d92f9db445293335717baa4a496034ad59a
Author: Milan Crha <mcrha redhat com>
Date:   Thu Apr 11 20:35:03 2013 +0200

    Bug #681837 - Make enum type registration thread safe

 ...ws-enumtypes.c.template => enumtypes.c.template |   13 ++++++-------
 ...ws-enumtypes.h.template => enumtypes.h.template |    9 +++------
 src/server/Makefile.am                             |   15 ++++++++++-----
 3 files changed, 19 insertions(+), 18 deletions(-)
---
diff --git a/src/server/e-ews-enumtypes.c.template b/enumtypes.c.template
similarity index 72%
rename from src/server/e-ews-enumtypes.c.template
rename to enumtypes.c.template
index 90dd2e7..0a99121 100644
--- a/src/server/e-ews-enumtypes.c.template
+++ b/enumtypes.c.template
@@ -1,6 +1,4 @@
 /*** BEGIN file-header ***/
-#include "e-ews-enumtypes.h"
-
 /*** END file-header ***/
 
 /*** BEGIN file-production ***/
@@ -13,9 +11,9 @@
 GType
 @enum_name _get_type (void)
 {
-       static GType the_type = 0;
-       
-       if (the_type == 0) {
+       static volatile gsize the_type__volatile = 0;
+
+       if (g_once_init_enter (&the_type__volatile)) {
                static const G Type@Value values[] = {
 /*** END value-header ***/
 
@@ -28,11 +26,12 @@ GType
 /*** BEGIN value-tail ***/
                        { 0, NULL, NULL }
                };
-               the_type = g_ type@_register_static (
+               GType the_type = g_ type@_register_static (
                        g_intern_static_string ("@EnumName@"),
                        values);
+               g_once_init_leave (&the_type__volatile, the_type);
        }
-       return the_type;
+       return the_type__volatile;
 }
 
 /*** END value-tail ***/
diff --git a/src/server/e-ews-enumtypes.h.template b/enumtypes.h.template
similarity index 84%
rename from src/server/e-ews-enumtypes.h.template
rename to enumtypes.h.template
index 31b36d7..e1ff4b3 100644
--- a/src/server/e-ews-enumtypes.h.template
+++ b/enumtypes.h.template
@@ -1,14 +1,12 @@
 /*** BEGIN file-header ***/
-#ifndef E_EWS_ENUMTYPES_H
-#define E_EWS_ENUMTYPES_H
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
 
 #include <glib-object.h>
 
 G_BEGIN_DECLS
 
-/*** END file-header ***/
-
-/*** BEGIN file-production ***/
 /* Enumerations from "@filename@" */
 
 /*** END file-production ***/
@@ -22,6 +20,5 @@ GType @enum_name _get_type    (void) G_GNUC_CONST;
 /*** BEGIN file-tail ***/
 G_END_DECLS
 
-#endif /* E_EWS_ENUMTYPES_H */
 /*** END file-tail ***/
 
diff --git a/src/server/Makefile.am b/src/server/Makefile.am
index 13c1eb9..5d52a67 100644
--- a/src/server/Makefile.am
+++ b/src/server/Makefile.am
@@ -6,11 +6,16 @@ privlib_LTLIBRARIES = libeews-1.2.la
 
 ENUM_TYPES = e-ews-enums.h
 
-e-ews-enumtypes.h: e-ews-enumtypes.h.template $(ENUM_TYPES)
-       $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template e-ews-enumtypes.h.template $(ENUM_TYPES)) > $@
-
-e-ews-enumtypes.c: e-ews-enumtypes.c.template $(ENUM_TYPES)
-       $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template e-ews-enumtypes.c.template $(ENUM_TYPES)) > $@
+e-ews-enumtypes.h: $(top_srcdir)/enumtypes.h.template $(ENUM_TYPES)
+       $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template $(top_srcdir)/enumtypes.h.template \
+               --fhead "#ifndef E_EWS_ENUMTYPES_H\n#define E_EWS_ENUMTYPES_H\n" \
+               --ftail "#endif /* E_EWS_ENUMTYPES_H */\n" \
+               $(ENUM_TYPES)) > $@
+
+e-ews-enumtypes.c: $(top_srcdir)/enumtypes.h.template $(ENUM_TYPES)
+       $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template $(top_srcdir)/enumtypes.c.template \
+               --fhead "#include \"e-ews-enumtypes.h\"" \
+               $(ENUM_TYPES)) > $@
 
 ENUM_GENERATED = \
        e-ews-enumtypes.h \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]