[gnome-software] Use GMutexLocker in a few more places



commit f49d1a56ae36357f2f2a1cde566543204e4e4c90
Author: Kalev Lember <klember redhat com>
Date:   Thu Jan 21 15:49:13 2016 +0100

    Use GMutexLocker in a few more places

 src/gs-app.c           |   10 ++++++----
 src/gs-plugin-loader.c |   15 +++++----------
 2 files changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 0a77892..350efe6 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -882,9 +882,10 @@ icon_theme_add_path (const gchar *path)
 GdkPixbuf *
 gs_app_get_pixbuf (GsApp *app)
 {
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&icon_theme_lock);
+
        g_return_val_if_fail (GS_IS_APP (app), NULL);
 
-       g_mutex_lock (&icon_theme_lock);
        /* has an icon */
        if (app->pixbuf == NULL &&
            app->icon != NULL &&
@@ -928,7 +929,6 @@ gs_app_get_pixbuf (GsApp *app)
                                                              GTK_ICON_LOOKUP_FORCE_SIZE,
                                                              NULL);
        }
-       g_mutex_unlock (&icon_theme_lock);
 
        return app->pixbuf;
 }
@@ -983,7 +983,9 @@ gs_app_load_icon (GsApp *app, gint scale, GError **error)
                                                           error);
                break;
        case AS_ICON_KIND_STOCK:
-               g_mutex_lock (&icon_theme_lock);
+       {
+               g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&icon_theme_lock);
+
                icon_theme_add_path (as_icon_get_prefix (icon));
                pixbuf = gtk_icon_theme_load_icon (icon_theme_get (),
                                                   as_icon_get_name (icon),
@@ -991,8 +993,8 @@ gs_app_load_icon (GsApp *app, gint scale, GError **error)
                                                   GTK_ICON_LOOKUP_USE_BUILTIN |
                                                   GTK_ICON_LOOKUP_FORCE_SIZE,
                                                   error);
-               g_mutex_unlock (&icon_theme_lock);
                break;
+       }
        default:
                g_set_error (error,
                             GS_PLUGIN_ERROR,
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 38c4bab..c2e6ffe 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -115,32 +115,28 @@ gs_plugin_loader_dedupe (GsPluginLoader *plugin_loader, GsApp *app)
 {
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
        GsApp *new_app;
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->app_cache_mutex);
 
        g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), NULL);
        g_return_val_if_fail (GS_IS_APP (app), NULL);
 
-       g_mutex_lock (&priv->app_cache_mutex);
-
        /* not yet set */
        if (gs_app_get_id (app) == NULL) {
-               new_app = app;
-               goto out;
+               return app;
        }
 
        /* already exists */
        new_app = g_hash_table_lookup (priv->app_cache, gs_app_get_id (app));
        if (new_app == app) {
-               new_app = app;
-               goto out;
+               return app;
        }
 
        /* insert new entry */
        if (new_app == NULL) {
-               new_app = app;
                g_hash_table_insert (priv->app_cache,
                                     g_strdup (gs_app_get_id (app)),
                                     g_object_ref (app));
-               goto out;
+               return app;
        }
 
        /* import all the useful properties */
@@ -152,8 +148,7 @@ gs_plugin_loader_dedupe (GsPluginLoader *plugin_loader, GsApp *app)
         */
        g_object_unref (app);
        g_object_ref (new_app);
-out:
-       g_mutex_unlock (&priv->app_cache_mutex);
+
        return new_app;
 }
 


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