[glib/wip/ebassi/rc-new: 85/86] Port GMappedFile to gatomicrefcount
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/ebassi/rc-new: 85/86] Port GMappedFile to gatomicrefcount
- Date: Fri, 16 Feb 2018 13:05:12 +0000 (UTC)
commit 3cf2a6e723200c2884fa0b0a7751c47c3abff5ca
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Feb 16 12:46:47 2018 +0000
Port GMappedFile to gatomicrefcount
Use the newly added API for reference counting instead of rolling our
own.
glib/gmappedfile.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/glib/gmappedfile.c b/glib/gmappedfile.c
index d180a9a4d..65f3948ef 100644
--- a/glib/gmappedfile.c
+++ b/glib/gmappedfile.c
@@ -48,15 +48,16 @@
#endif
+#include "gatomic.h"
#include "gconvert.h"
#include "gerror.h"
#include "gfileutils.h"
#include "gmappedfile.h"
#include "gmem.h"
#include "gmessages.h"
+#include "grefcount.h"
#include "gstdio.h"
#include "gstrfuncs.h"
-#include "gatomic.h"
#include "glibintl.h"
@@ -82,7 +83,7 @@ struct _GMappedFile
gchar *contents;
gsize length;
gpointer free_func;
- int ref_count;
+ gatomicrefcount ref_count;
#ifdef G_OS_WIN32
HANDLE mapping;
#endif
@@ -115,7 +116,7 @@ mapped_file_new_from_fd (int fd,
struct stat st;
file = g_slice_new0 (GMappedFile);
- file->ref_count = 1;
+ g_atomic_ref_count_init (&file->ref_count);
file->free_func = g_mapped_file_destroy;
if (fstat (fd, &st) == -1)
@@ -378,7 +379,7 @@ g_mapped_file_ref (GMappedFile *file)
{
g_return_val_if_fail (file != NULL, NULL);
- g_atomic_int_inc (&file->ref_count);
+ g_atomic_ref_count_inc (&file->ref_count);
return file;
}
@@ -399,7 +400,7 @@ g_mapped_file_unref (GMappedFile *file)
{
g_return_if_fail (file != NULL);
- if (g_atomic_int_dec_and_test (&file->ref_count))
+ if (g_atomic_ref_count_dec (&file->ref_count))
g_mapped_file_destroy (file);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]