[glib: 6/10] gfileattribute: Do atomic addition before checking the old value on ref




commit 9c32cfbaaa42a89d4d69d62dccd931cf065c53ee
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Jun 21 04:59:54 2022 +0200

    gfileattribute: Do atomic addition before checking the old value on ref
    
    So we avoid working on a value that is not been updated yet.

 gio/gfileattribute.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/gio/gfileattribute.c b/gio/gfileattribute.c
index aa8c61e456..124eb4d07a 100644
--- a/gio/gfileattribute.c
+++ b/gio/gfileattribute.c
@@ -859,11 +859,12 @@ GFileAttributeInfoList *
 g_file_attribute_info_list_ref (GFileAttributeInfoList *list)
 {
   GFileAttributeInfoListPriv *priv = (GFileAttributeInfoListPriv *)list;
+  int old_ref_count;
 
   g_return_val_if_fail (list != NULL, NULL);
-  g_return_val_if_fail (priv->ref_count > 0, NULL);
 
-  g_atomic_int_inc (&priv->ref_count);
+  old_ref_count = g_atomic_int_add (&priv->ref_count, 1);
+  g_return_val_if_fail (old_ref_count > 0, NULL);
 
   return list;
 }


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