[evolution-exchange] Use thread safe G_DEFINE_TYPE



commit b373c4d2f64edfe5e03591d1c9b143933d3491d9
Author: Milan Crha <mcrha redhat com>
Date:   Wed Feb 17 18:50:20 2010 +0100

    Use thread safe G_DEFINE_TYPE

 eplugin/exchange-send-options.c |   43 ++++++--------------------------------
 server/lib/e2k-types.h          |   18 +++++++++-------
 2 files changed, 17 insertions(+), 44 deletions(-)
---
diff --git a/eplugin/exchange-send-options.c b/eplugin/exchange-send-options.c
index c7c96dc..782a45a 100644
--- a/eplugin/exchange-send-options.c
+++ b/eplugin/exchange-send-options.c
@@ -33,6 +33,8 @@
 
 #include "exchange-send-options.h"
 
+G_DEFINE_TYPE (ExchangeSendOptionsDialog, exchange_sendoptions_dialog, G_TYPE_OBJECT)
+
 struct _ExchangeSendOptionsDialogPrivate {
 	/*Widgets*/
 	GtkWidget *main;
@@ -64,9 +66,7 @@ struct _ExchangeSendOptionsDialogPrivate {
 	gchar *help_section;
 };
 
-static void exchange_sendoptions_dialog_class_init (GObjectClass *object_class);
 static void exchange_sendoptions_dialog_finalize (GObject *object);
-static void exchange_sendoptions_dialog_init (GObject *object);
 static void exchange_sendoptions_dialog_dispose (GObject *object);
 
 static GObjectClass *parent_class = NULL;
@@ -213,29 +213,6 @@ exchange_sendoptions_dialog_new (void) {
 	return sod;
 }
 
-GType exchange_sendoptions_dialog_get_type (void)
-{
-  static GType type = 0;
-  if (type == 0) {
-    static const GTypeInfo info = {
-      sizeof (ExchangeSendOptionsDialogClass),
-      NULL,   /* base_init */
-      NULL,   /* base_finalize */
-      (GClassInitFunc) exchange_sendoptions_dialog_class_init,   /* class_init */
-      NULL,   /* class_finalize */
-      NULL,   /* class_data */
-      sizeof (ExchangeSendOptionsDialog),
-     0,      /* n_preallocs */
-     (GInstanceInitFunc) exchange_sendoptions_dialog_init,
-	NULL    /* instance_init */
-    };
-    type = g_type_register_static (G_TYPE_OBJECT,
-                                   "ExchangeSendOptionsDialogType",
-                                   &info, 0);
-  }
-  return type;
-}
-
 static void exchange_send_options_cb (GtkDialog *dialog, gint state, gpointer func_data)
 {
 	ExchangeSendOptionsDialogPrivate *priv;
@@ -526,12 +503,10 @@ exchange_sendoptions_dialog_run (ExchangeSendOptionsDialog *sod, GtkWidget *pare
 }
 
 static void
-exchange_sendoptions_dialog_class_init (GObjectClass *object)
+exchange_sendoptions_dialog_class_init (ExchangeSendOptionsDialogClass *klass)
 {
-	ExchangeSendOptionsDialogClass *klass;
 	GObjectClass *object_class;
 
-	klass = EXCHANGE_SENDOPTIONS_DIALOG_CLASS (object);
 	parent_class = g_type_class_peek_parent (klass);
 	object_class = G_OBJECT_CLASS (klass);
 
@@ -549,20 +524,17 @@ exchange_sendoptions_dialog_class_init (GObjectClass *object)
 }
 
 static void
-exchange_sendoptions_dialog_init (GObject *object)
+exchange_sendoptions_dialog_init (ExchangeSendOptionsDialog *sod)
 {
-
-	ExchangeSendOptionsDialog *sod;
 	ExchangeSendOptionsDialogPrivate *priv;
-	ExchangeSendOptions *new;
+	ExchangeSendOptions *options;
 
-	sod = EXCHANGE_SENDOPTIONS_DIALOG (object);
-	new = g_new0 (ExchangeSendOptions, 1);
+	options = g_new0 (ExchangeSendOptions, 1);
 
 	priv = g_new0 (ExchangeSendOptionsDialogPrivate, 1);
 
 	sod->priv = priv;
-	sod->options = new;
+	sod->options = options;
 	sod->options->send_as_del_enabled = FALSE;
 	sod->options->delivery_enabled = FALSE;
 	sod->options->read_enabled = FALSE;
@@ -578,7 +550,6 @@ exchange_sendoptions_dialog_init (GObject *object)
 	priv->proxy_name_selector = NULL;
 	priv->read_receipt = NULL;
 	priv->delivery_receipt = NULL;
-
 }
 
 static void
diff --git a/server/lib/e2k-types.h b/server/lib/e2k-types.h
index dfa5983..68ebe13 100644
--- a/server/lib/e2k-types.h
+++ b/server/lib/e2k-types.h
@@ -34,8 +34,8 @@ typedef struct _E2kSidClass                   E2kSidClass;
 #define E2K_MAKE_TYPE(type_name,TypeName,class_init,init,parent) \
 GType type_name##_get_type(void)			\
 {							\
-	static GType type = 0;				\
-	if (!type){					\
+	static volatile gsize type_id__volatile = 0;	\
+	if (g_once_init_enter (&type_id__volatile)) {	\
 		static GTypeInfo const object_info = {	\
 			sizeof (TypeName##Class),	\
 							\
@@ -50,16 +50,17 @@ GType type_name##_get_type(void)			\
 			0,	/* n_preallocs */	\
 			(GInstanceInitFunc) init,	\
 		};					\
-		type = g_type_register_static (parent, #TypeName, &object_info, 0); \
+		GType type = g_type_register_static (parent, #TypeName, &object_info, 0); \
+		g_once_init_leave (&type_id__volatile, type);	\
 	}						\
-	return type;					\
+	return type_id__volatile;			\
 }
 
 #define E2K_MAKE_TYPE_WITH_IFACE(type_name,TypeName,class_init,init,parent,iface_init,iparent) \
 GType type_name##_get_type(void)			\
 {							\
-	static GType type = 0;				\
-	if (!type){					\
+	static volatile gsize type_id__volatile = 0;	\
+	if (g_once_init_enter (&type_id__volatile)) {	\
 		static GTypeInfo const object_info = {	\
 			sizeof (TypeName##Class),	\
 							\
@@ -79,10 +80,11 @@ GType type_name##_get_type(void)			\
 			NULL,					\
 			NULL					\
 		};						\
-		type = g_type_register_static (parent, #TypeName, &object_info, 0);	\
+		GType type = g_type_register_static (parent, #TypeName, &object_info, 0);	\
 		g_type_add_interface_static (type, iparent, &iface_info);		\
+		g_once_init_leave (&type_id__volatile, type);	\
 	}						\
-	return type;					\
+	return type_id__volatile;					\
 }
 
 /* Put "E2K_KEEP_PRECEDING_COMMENT_OUT_OF_PO_FILES;" on a line to



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