[gnome-software] Make the plugin cache threadsafe



commit 487a485d4d0bfcc253f675623e034847bc7673fd
Author: Richard Hughes <richard hughsie com>
Date:   Mon May 23 18:46:24 2016 +0100

    Make the plugin cache threadsafe
    
    We could access the plugin cache from multiple threads.

 src/gs-plugin.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 8953405..d61a685 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -56,6 +56,7 @@ typedef struct
 {
        AsProfile               *profile;
        GHashTable              *cache;
+       GMutex                   cache_mutex;
        GModule                 *module;
        GRWLock                  rwlock;
        GsPluginData            *data;                  /* for gs-plugin-{name}.c */
@@ -184,6 +185,7 @@ gs_plugin_finalize (GObject *object)
        g_object_unref (priv->profile);
        g_object_unref (priv->soup_session);
        g_hash_table_unref (priv->cache);
+       g_mutex_clear (&priv->cache_mutex);
        g_module_close (priv->module);
 }
 
@@ -910,6 +912,7 @@ gs_plugin_cache_lookup (GsPlugin *plugin, const gchar *key)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
        GsApp *app;
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->cache_mutex);
 
        g_return_val_if_fail (GS_IS_PLUGIN (plugin), NULL);
        g_return_val_if_fail (key != NULL, NULL);
@@ -933,6 +936,7 @@ void
 gs_plugin_cache_add (GsPlugin *plugin, const gchar *key, GsApp *app)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->cache_mutex);
 
        g_return_if_fail (GS_IS_PLUGIN (plugin));
        g_return_if_fail (key != NULL);
@@ -954,7 +958,10 @@ void
 gs_plugin_cache_invalidate (GsPlugin *plugin)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->cache_mutex);
+
        g_return_if_fail (GS_IS_PLUGIN (plugin));
+
        g_hash_table_remove_all (priv->cache);
 }
 
@@ -1046,6 +1053,7 @@ gs_plugin_init (GsPlugin *plugin)
                                             g_str_equal,
                                             g_free,
                                             (GDestroyNotify) g_object_unref);
+       g_mutex_init (&priv->cache_mutex);
        g_rw_lock_init (&priv->rwlock);
 }
 


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