[glib/wip/ebassi/rc-new: 83/86] Port GKeyFile to gatomicrefcount



commit 9311484fe7d13850fe5f62740125a6127422e75d
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri Feb 16 12:31:09 2018 +0000

    Port GKeyFile to gatomicrefcount
    
    Use the newly added API for reference counting instead of rolling our
    own.

 glib/gkeyfile.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c
index ae3bbbc1d..02daa1267 100644
--- a/glib/gkeyfile.c
+++ b/glib/gkeyfile.c
@@ -24,6 +24,7 @@
 #include "config.h"
 
 #include "gkeyfile.h"
+#include "grefcount.h"
 #include "gutils.h"
 
 #include <errno.h>
@@ -512,7 +513,7 @@ struct _GKeyFile
 
   gchar **locales;
 
-  volatile gint ref_count;
+  gatomicrefcount ref_count;
 };
 
 typedef struct _GKeyFileKeyValuePair GKeyFileKeyValuePair;
@@ -690,7 +691,7 @@ g_key_file_new (void)
   GKeyFile *key_file;
 
   key_file = g_slice_new0 (GKeyFile);
-  key_file->ref_count = 1;
+  g_atomic_ref_count_init (&key_file->ref_count);
   g_key_file_init (key_file);
 
   return key_file;
@@ -1170,7 +1171,7 @@ g_key_file_ref (GKeyFile *key_file)
 {
   g_return_val_if_fail (key_file != NULL, NULL);
 
-  g_atomic_int_inc (&key_file->ref_count);
+  g_atomic_ref_count_inc (&key_file->ref_count);
 
   return key_file;
 }
@@ -1208,7 +1209,7 @@ g_key_file_unref (GKeyFile *key_file)
 {
   g_return_if_fail (key_file != NULL);
 
-  if (g_atomic_int_dec_and_test (&key_file->ref_count))
+  if (g_atomic_ref_count_dec (&key_file->ref_count))
     {
       g_key_file_clear (key_file);
       g_slice_free (GKeyFile, key_file);


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