[gnome-software] trivial: Make the AppStream token cache cration threadsafe



commit e5f082eddd9e779c6b60ca6ba84a3425b8bfb11a
Author: Richard Hughes <richard hughsie com>
Date:   Thu Oct 31 08:55:44 2013 +0000

    trivial: Make the AppStream token cache cration threadsafe

 src/plugins/appstream-app.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index 3c3c394..08a933f 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -53,7 +53,7 @@ struct AppstreamApp
        gpointer                 userdata;
        GDestroyNotify           userdata_destroy_func;
        GPtrArray               *screenshots; /* of AppstreamScreenshot */
-       gboolean                 token_cache_valid;
+       gsize                    token_cache_valid;
        GPtrArray               *token_cache;
 };
 
@@ -572,7 +572,6 @@ appstream_app_create_token_cache (AppstreamApp *app)
                tmp = g_ptr_array_index (app->mimetypes, i);
                appstream_app_add_tokens (app, tmp, "C", 1);
        }
-       app->token_cache_valid = TRUE;
 }
 
 /**
@@ -586,11 +585,13 @@ appstream_app_search_matches (AppstreamApp *app, const gchar *search)
 
        /* nothing to do */
        if (search == NULL)
-               return FALSE;
+               return 0;
 
        /* ensure the token cache is created */
-       if (!app->token_cache_valid)
+       if (g_once_init_enter (&app->token_cache_valid)) {
                appstream_app_create_token_cache (app);
+               g_once_init_leave (&app->token_cache_valid, TRUE);
+       }
 
        /* find the search term */
        for (i = 0; i < app->token_cache->len; i++) {


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