[Xfce4-commits] <garcon:master> Make GarconMenuItemCache a singleton.

Nick Schermer nick at xfce.org
Mon Aug 17 18:16:05 CEST 2009


Updating branch refs/heads/master
         to bcc9171e5cf4eeed62eb271f2e2f1c9a3aa147ec (commit)
       from d72666bbb1beeaa9571eea3753e10a2164840213 (commit)

commit bcc9171e5cf4eeed62eb271f2e2f1c9a3aa147ec
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Aug 17 17:40:37 2009 +0200

    Make GarconMenuItemCache a singleton.

 garcon/garcon-menu-item-cache.c |   57 ++++++++++----------------------------
 garcon/garcon-menu-item-cache.h |   20 ++++++++++---
 garcon/garcon.c                 |    6 ----
 3 files changed, 30 insertions(+), 53 deletions(-)

diff --git a/garcon/garcon-menu-item-cache.c b/garcon/garcon-menu-item-cache.c
index 2637d01..d2d74b0 100644
--- a/garcon/garcon-menu-item-cache.c
+++ b/garcon/garcon-menu-item-cache.c
@@ -51,39 +51,6 @@ static void garcon_menu_item_cache_finalize   (GObject                  *object)
 
 
 
-
-static GarconMenuItemCache *_garcon_menu_item_cache = NULL;
-
-
-
-void
-_garcon_menu_item_cache_init (void)
-{
-  if (G_LIKELY (_garcon_menu_item_cache == NULL))
-    {
-      _garcon_menu_item_cache = g_object_new (GARCON_TYPE_MENU_ITEM_CACHE, NULL);
-      g_object_add_weak_pointer (G_OBJECT (_garcon_menu_item_cache),
-                                 (gpointer) &_garcon_menu_item_cache);
-    }
-}
-
-
-
-void
-_garcon_menu_item_cache_shutdown (void)
-{
-  if (G_LIKELY (_garcon_menu_item_cache != NULL))
-    g_object_unref (G_OBJECT (_garcon_menu_item_cache));
-
-}
-
-
-
-struct _GarconMenuItemCacheClass
-{
-  GObjectClass __parent__;
-};
-
 struct _GarconMenuItemCachePrivate
 {
   /* Hash table for mapping absolute filenames to GarconMenuItem's */
@@ -93,14 +60,6 @@ struct _GarconMenuItemCachePrivate
   GMutex     *lock;
 };
 
-struct _GarconMenuItemCache
-{
-  GObject                     __parent__;
-
-  /* Private data */
-  GarconMenuItemCachePrivate *priv;
-};
-
 
 
 G_DEFINE_TYPE (GarconMenuItemCache, garcon_menu_item_cache, G_TYPE_OBJECT)
@@ -149,7 +108,21 @@ garcon_menu_item_cache_init (GarconMenuItemCache *cache)
 GarconMenuItemCache*
 garcon_menu_item_cache_get_default (void)
 {
-  return g_object_ref (G_OBJECT (_garcon_menu_item_cache));
+  static GarconMenuItemCache *cache = NULL;
+
+  if (G_UNLIKELY (cache == NULL))
+    {
+      /* create a new cache */
+      cache = g_object_new (GARCON_TYPE_MENU_ITEM_CACHE, NULL);
+      g_object_add_weak_pointer (G_OBJECT (cache), (gpointer) &cache);
+    }
+  else
+    {
+      /* set and extra reference */
+      g_object_ref (G_OBJECT (cache));
+    }
+
+  return cache;
 }
 
 
diff --git a/garcon/garcon-menu-item-cache.h b/garcon/garcon-menu-item-cache.h
index a6198dc..1e8bbb6 100644
--- a/garcon/garcon-menu-item-cache.h
+++ b/garcon/garcon-menu-item-cache.h
@@ -41,6 +41,21 @@ typedef struct _GarconMenuItemCache        GarconMenuItemCache;
 #define GARCON_IS_MENU_ITEM_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GARCON_TYPE_MENU_ITEM_CACHE))
 #define GARCON_MENU_ITEM_CACHE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GARCON_TYPE_MENU_ITEM_CACHE, GarconMenuItemCacheClass))
 
+struct _GarconMenuItemCacheClass
+{
+  GObjectClass __parent__;
+};
+
+struct _GarconMenuItemCache
+{
+  GObject                     __parent__;
+
+  /* Private data */
+  GarconMenuItemCachePrivate *priv;
+};
+
+
+
 GType                garcon_menu_item_cache_get_type    (void) G_GNUC_CONST;
 
 GarconMenuItemCache *garcon_menu_item_cache_get_default (void);
@@ -53,11 +68,6 @@ void                 garcon_menu_item_cache_foreach     (GarconMenuItemCache *ca
                                                          gpointer             user_data);
 void                 garcon_menu_item_cache_invalidate  (GarconMenuItemCache *cache);
 
-#if defined(GARCON_COMPILATION)
-void                 _garcon_menu_item_cache_init       (void) G_GNUC_INTERNAL;
-void                 _garcon_menu_item_cache_shutdown   (void) G_GNUC_INTERNAL;
-#endif
-
 G_END_DECLS
 
 #endif /* !__GARCON_MENU_ITEM_CACHE_H__ */
diff --git a/garcon/garcon.c b/garcon/garcon.c
index d1a646c..43a0cb1 100644
--- a/garcon/garcon.c
+++ b/garcon/garcon.c
@@ -69,9 +69,6 @@ garcon_init (const gchar *env)
       /* Set desktop environment */
       garcon_set_environment (env);
 
-      /* Initialize the menu item cache */
-      _garcon_menu_item_cache_init ();
-
       /* Creates the menu separator */
       _garcon_menu_separator_init ();
    }
@@ -94,9 +91,6 @@ garcon_shutdown (void)
 
       /* Destroys the menu separator */
       _garcon_menu_separator_shutdown ();
-
-      /* Shutdown the menu item cache */
-      _garcon_menu_item_cache_shutdown ();
     }
 }
 



More information about the Xfce4-commits mailing list