[Xfce4-commits] <thunar:master> Protect the interfaces types and use g_type_register_static_simple where possible.

Nick Schermer nick at xfce.org
Sat Aug 22 21:20:03 CEST 2009


Updating branch refs/heads/master
         to 09610f85d7e8016a443510636aeed4554dfcf044 (commit)
       from ce34ba48e5e38ea750c27df4a8aec94b39508f42 (commit)

commit 09610f85d7e8016a443510636aeed4554dfcf044
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Aug 22 20:50:06 2009 +0200

    Protect the interfaces types and use g_type_register_static_simple where possible.

 thunar/thunar-browser.c      |   11 +++++++----
 thunar/thunar-component.c    |   31 ++++++++++++++-----------------
 thunar/thunar-location-bar.c |   29 +++++++++++++----------------
 thunar/thunar-navigator.c    |    9 ++++++---
 thunar/thunar-side-pane.c    |   29 +++++++++++++----------------
 thunar/thunar-view.c         |   29 +++++++++++++----------------
 6 files changed, 66 insertions(+), 72 deletions(-)

diff --git a/thunar/thunar-browser.c b/thunar/thunar-browser.c
index 12ae250..e9e08fd 100644
--- a/thunar/thunar-browser.c
+++ b/thunar/thunar-browser.c
@@ -57,9 +57,10 @@ struct _PokeVolumeData
 GType
 thunar_browser_get_type (void)
 {
-  static GType type = G_TYPE_INVALID;
-  
-  if (G_UNLIKELY (type == G_TYPE_INVALID))
+  static volatile gsize type__volatile = 0;
+  GType                 type;
+
+  if (g_once_init_enter (&type__volatile))
     {
       type = g_type_register_static_simple (G_TYPE_INTERFACE,
                                             I_("ThunarBrowser"),
@@ -70,9 +71,11 @@ thunar_browser_get_type (void)
                                             0);
 
       g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
+
+      g_once_init_leave (&type__volatile, type);
     }
 
-  return type;
+  return type__volatile;
 }
 
 
diff --git a/thunar/thunar-component.c b/thunar/thunar-component.c
index 46906ac..66ea09f 100644
--- a/thunar/thunar-component.c
+++ b/thunar/thunar-component.c
@@ -35,28 +35,25 @@ static void thunar_component_class_init (gpointer klass);
 GType
 thunar_component_get_type (void)
 {
-  static GType type = G_TYPE_INVALID;
+  static volatile gsize type__volatile = 0;
+  GType                 type;
 
-  if (G_UNLIKELY (type == G_TYPE_INVALID))
+  if (g_once_init_enter (&type__volatile))
     {
-      static const GTypeInfo info =
-      {
-        sizeof (ThunarComponentIface),
-        NULL,
-        NULL,
-        (GClassInitFunc) thunar_component_class_init,
-        NULL,
-        NULL,
-        0,
-        0,
-        NULL,
-      };
-
-      type = g_type_register_static (G_TYPE_INTERFACE, I_("ThunarComponent"), &info, 0);
+      type = g_type_register_static_simple (G_TYPE_INTERFACE,
+                                            I_("ThunarComponent"),
+                                            sizeof (ThunarComponentIface),
+                                            (GClassInitFunc) thunar_component_class_init,
+                                            0,
+                                            NULL,
+                                            0);
+
       g_type_interface_add_prerequisite (type, THUNAR_TYPE_NAVIGATOR);
+
+      g_once_init_leave (&type__volatile, type);
     }
 
-  return type;
+  return type__volatile;
 }
 
 
diff --git a/thunar/thunar-location-bar.c b/thunar/thunar-location-bar.c
index ad89ebc..61122a9 100644
--- a/thunar/thunar-location-bar.c
+++ b/thunar/thunar-location-bar.c
@@ -29,28 +29,25 @@
 GType
 thunar_location_bar_get_type (void)
 {
-  static GType type = G_TYPE_INVALID;
+  static volatile gsize type__volatile = 0;
+  GType                 type;
 
-  if (G_UNLIKELY (type == G_TYPE_INVALID))
+  if (g_once_init_enter (&type__volatile))
     {
-      static const GTypeInfo info =
-      {
-        sizeof (ThunarLocationBarIface),
-        NULL,
-        NULL,
-        NULL,
-        NULL,
-        NULL,
-        0,
-        0,
-        NULL,
-      };
+      type = g_type_register_static_simple (G_TYPE_INTERFACE,
+                                            I_("ThunarLocationBar"),
+                                            sizeof (ThunarLocationBarIface),
+                                            NULL,
+                                            0,
+                                            NULL,
+                                            0);
 
-      type = g_type_register_static (G_TYPE_INTERFACE, I_("ThunarLocationBar"), &info, 0);
       g_type_interface_add_prerequisite (type, THUNAR_TYPE_COMPONENT);
+
+      g_once_init_leave (&type__volatile, type);
     }
 
-  return type;
+  return type__volatile;
 }
 
 
diff --git a/thunar/thunar-navigator.c b/thunar/thunar-navigator.c
index 9e6f4f2..c7def2f 100644
--- a/thunar/thunar-navigator.c
+++ b/thunar/thunar-navigator.c
@@ -46,9 +46,10 @@ static guint navigator_signals[LAST_SIGNAL];
 GType
 thunar_navigator_get_type (void)
 {
-  static GType type = G_TYPE_INVALID;
+  static volatile gsize type__volatile = 0;
+  GType                 type;
 
-  if (G_UNLIKELY (type == G_TYPE_INVALID))
+  if (g_once_init_enter (&type__volatile))
     {
       static const GTypeInfo info =
       {
@@ -65,9 +66,11 @@ thunar_navigator_get_type (void)
 
       type = g_type_register_static (G_TYPE_INTERFACE, I_("ThunarNavigator"), &info, 0);
       g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
+    
+      g_once_init_leave (&type__volatile, type);
     }
 
-  return type;
+  return type__volatile;
 }
 
 
diff --git a/thunar/thunar-side-pane.c b/thunar/thunar-side-pane.c
index 21d1618..991f0c8 100644
--- a/thunar/thunar-side-pane.c
+++ b/thunar/thunar-side-pane.c
@@ -33,29 +33,26 @@ static void thunar_side_pane_class_init (gpointer klass);
 GType
 thunar_side_pane_get_type (void)
 {
-  static GType type = G_TYPE_INVALID;
+  static volatile gsize type__volatile = 0;
+  GType                 type;
 
-  if (G_UNLIKELY (type == G_TYPE_INVALID))
+  if (g_once_init_enter (&type__volatile))
     {
-      static const GTypeInfo info =
-      {
-        sizeof (ThunarSidePaneIface),
-        NULL,
-        NULL,
-        (GClassInitFunc) thunar_side_pane_class_init,
-        NULL,
-        NULL,
-        0,
-        0,
-        NULL,
-      };
-
-      type = g_type_register_static (G_TYPE_INTERFACE, I_("ThunarSidePane"), &info, 0);
+      type = g_type_register_static_simple (G_TYPE_INTERFACE,
+                                            I_("ThunarSidePane"),
+                                            sizeof (ThunarSidePaneIface),
+                                            (GClassInitFunc) thunar_side_pane_class_init,
+                                            0,
+                                            NULL,
+                                            0);
+
       g_type_interface_add_prerequisite (type, GTK_TYPE_WIDGET);
       g_type_interface_add_prerequisite (type, THUNAR_TYPE_COMPONENT);
+
+      g_once_init_leave (&type__volatile, type);
     }
 
-  return type;
+  return type__volatile;
 }
 
 
diff --git a/thunar/thunar-view.c b/thunar/thunar-view.c
index 85672f7..067bc09 100644
--- a/thunar/thunar-view.c
+++ b/thunar/thunar-view.c
@@ -33,29 +33,26 @@ static void thunar_view_class_init (gpointer klass);
 GType
 thunar_view_get_type (void)
 {
-  static GType type = G_TYPE_INVALID;
+  static volatile gsize type__volatile = 0;
+  GType                 type;
 
-  if (G_UNLIKELY (type == G_TYPE_INVALID))
+  if (g_once_init_enter (&type__volatile))
     {
-      static const GTypeInfo info =
-      {
-        sizeof (ThunarViewIface),
-        NULL,
-        NULL,
-        (GClassInitFunc) thunar_view_class_init,
-        NULL,
-        NULL,
-        0,
-        0,
-        NULL,
-      };
-
-      type = g_type_register_static (G_TYPE_INTERFACE, I_("ThunarView"), &info, 0);
+      type = g_type_register_static_simple (G_TYPE_INTERFACE,
+                                            I_("ThunarView"),
+                                            sizeof (ThunarViewIface),
+                                            (GClassInitFunc) thunar_view_class_init,
+                                            0,
+                                            NULL,
+                                            0);
+
       g_type_interface_add_prerequisite (type, GTK_TYPE_WIDGET);
       g_type_interface_add_prerequisite (type, THUNAR_TYPE_COMPONENT);
+
+      g_once_init_leave (&type__volatile, type);
     }
 
-  return type;
+  return type__volatile;
 }
 
 



More information about the Xfce4-commits mailing list