[gnome-software: 10/11] gs-category: Make size atomic




commit b28d69ec2776fa4a9b1369fc9d57d57213011603
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Jul 15 16:21:32 2022 +0100

    gs-category: Make size atomic
    
    This means it’s safe for the size to be set by flatpak and appstream
    worker threads acting on it with parallel calls to
    `gs_appstream_refine_category_sizes()`.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 lib/gs-category.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
---
diff --git a/lib/gs-category.c b/lib/gs-category.c
index 2e1d075db..befc167d4 100644
--- a/lib/gs-category.c
+++ b/lib/gs-category.c
@@ -32,7 +32,7 @@ struct _GsCategory
 
        GPtrArray       *desktop_groups;  /* potentially NULL if empty */
        GsCategory      *parent;
-       guint            size;
+       guint            size;  /* (atomic) */
        GPtrArray       *children;  /* potentially NULL if empty */
 };
 
@@ -119,7 +119,7 @@ gs_category_get_size (GsCategory *category)
        if (category->parent != NULL && g_str_equal (gs_category_get_id (category), "all"))
                return gs_category_get_size (category->parent);
 
-       return category->size;
+       return g_atomic_int_get (&category->size);
 }
 
 /**
@@ -137,10 +137,7 @@ gs_category_set_size (GsCategory *category, guint size)
 {
        g_return_if_fail (GS_IS_CATEGORY (category));
 
-       if (size == category->size)
-               return;
-
-       category->size = size;
+       g_atomic_int_set (&category->size, size);
        g_object_notify_by_pspec (G_OBJECT (category), obj_props[PROP_SIZE]);
 }
 
@@ -159,8 +156,9 @@ gs_category_increment_size (GsCategory *category,
 {
        g_return_if_fail (GS_IS_CATEGORY (category));
 
-       category->size += value;
-       g_object_notify_by_pspec (G_OBJECT (category), obj_props[PROP_SIZE]);
+       g_atomic_int_add (&category->size, value);
+       if (value != 0)
+               g_object_notify_by_pspec (G_OBJECT (category), obj_props[PROP_SIZE]);
 }
 
 /**


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