[Xfce4-commits] r24868 - libfrap/trunk/libfrap/menu

Jannis Pohlmann jannis at xfce.org
Tue Feb 6 15:00:51 CET 2007


Author: jannis
Date: 2007-02-06 14:00:51 +0000 (Tue, 06 Feb 2007)
New Revision: 24868

Modified:
   libfrap/trunk/libfrap/menu/ChangeLog
   libfrap/trunk/libfrap/menu/frap-menu-item-cache.c
   libfrap/trunk/libfrap/menu/frap-menu.c
Log:
	* frap-menu-item-cache.c: Add GMutex variable to the item cache and
	  lock the item cache in frap_menu_item_cache_lookup() which is the
	  only public function where the contents of the item cache may be
	  modified. 
	* frap-menu.c: Initialize GThread system in frap_menu_init ().

Modified: libfrap/trunk/libfrap/menu/ChangeLog
===================================================================
--- libfrap/trunk/libfrap/menu/ChangeLog	2007-02-06 13:35:13 UTC (rev 24867)
+++ libfrap/trunk/libfrap/menu/ChangeLog	2007-02-06 14:00:51 UTC (rev 24868)
@@ -1,3 +1,11 @@
+2007-02-06	Jannis Pohlmann <jannis at xfce.org>
+
+	* frap-menu-item-cache.c: Add GMutex variable to the item cache and
+	  lock the item cache in frap_menu_item_cache_lookup() which is the
+	  only public function where the contents of the item cache may be
+	  modified. 
+	* frap-menu.c: Initialize GThread system in frap_menu_init ().
+
 2007-02-05	Jannis Pohlmann <jannis at xfce.org>
 
 	* tests/Makefile.am, tests/test-menu-spec.c: Test program for

Modified: libfrap/trunk/libfrap/menu/frap-menu-item-cache.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-item-cache.c	2007-02-06 13:35:13 UTC (rev 24867)
+++ libfrap/trunk/libfrap/menu/frap-menu-item-cache.c	2007-02-06 14:00:51 UTC (rev 24868)
@@ -104,13 +104,16 @@
   /* TDB context */
   TDB_CONTEXT *context;
   TDB_DATA     data;
+
+  /* Mutex lock */
+  GMutex      *lock;
 };
 
 struct _FrapMenuItemCache
 {
   GObject __parent__;
 
-  /* < private > */
+  /* Private data */
   FrapMenuItemCachePrivate *priv;
 };
 
@@ -172,6 +175,9 @@
 
   cache->priv = FRAP_MENU_ITEM_CACHE_GET_PRIVATE (cache);
 
+  /* Initialize the mutex lock */
+  cache->priv->lock = g_mutex_new ();
+
   /* Create empty hash table */
   cache->priv->items = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) frap_menu_item_unref);
 
@@ -224,6 +230,9 @@
   if (G_LIKELY (cache->priv->context != NULL))
     tdb_close (cache->priv->context);
 
+  /* Release mutex lock */
+  g_mutex_free (cache->priv->lock);
+
   (*G_OBJECT_CLASS (frap_menu_item_cache_parent_class)->finalize) (object);
 }
 
@@ -245,6 +254,11 @@
   g_return_val_if_fail (g_path_is_absolute (filename), NULL);
   g_return_val_if_fail (desktop_id != NULL, NULL);
 
+  /* Acquire lock on the item cache as it's likely that we need to load 
+   * items from the hard drive and store it in the hash table of the 
+   * item cache */
+  g_mutex_lock (cache->priv->lock);
+
   /* Search filename in the hash table */
   item = g_hash_table_lookup (cache->priv->items, filename);
 
@@ -259,6 +273,9 @@
       /* Store updated item in cache */
       frap_menu_item_cache_store_item (cache, filename, item);
 
+      /* Release item cache lock */
+      g_mutex_unlock (cache->priv->lock);
+
       return item;
     }
 
@@ -285,6 +302,9 @@
            * counter */
           g_object_ref (G_OBJECT (item));
 
+          /* Release item cache lock */
+          g_mutex_unlock (cache->priv->lock);
+
           return item;
         }
     }
@@ -307,6 +327,9 @@
       g_object_ref (G_OBJECT (item));
     }
 
+  /* Release item cache lock */
+  g_mutex_unlock (cache->priv->lock);
+
   return item;
 }
 

Modified: libfrap/trunk/libfrap/menu/frap-menu.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu.c	2007-02-06 13:35:13 UTC (rev 24867)
+++ libfrap/trunk/libfrap/menu/frap-menu.c	2007-02-06 14:00:51 UTC (rev 24868)
@@ -83,6 +83,10 @@
       /* Initialize the GObject type system */
       g_type_init ();
 
+      /* Initialize the GThread system */
+      if (!g_thread_supported ())
+        g_thread_init (NULL);
+
       /* Set desktop environment */
       frap_menu_set_environment (env);
 



More information about the Xfce4-commits mailing list