diff options
author | Nishal Kulkarni <kulknishu@gmail.com> | 2021-05-14 18:10:06 +0530 |
---|---|---|
committer | Benjamin Berg <benjamin@sipsolutions.net> | 2021-05-14 12:48:50 +0000 |
commit | b23408d1cffd2ab07cb22fcf797137c41ef6f3af (patch) | |
tree | 3fdf38f47d3f68fe5770d74323aa4ecf1ed4ca02 | |
parent | e5f62bd38b0f580b90427c46445d28450b012742 (diff) | |
download | gnome-settings-daemon-b23408d1cffd2ab07cb22fcf797137c41ef6f3af.tar.gz |
housekeeping: use grefcount
reference counting is implemented manually instead of using grefcount
provided by glib.
Fix: using grefcount and its functions for `DeleteData` struct
Updated `glib_min_version` to 2.58
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | plugins/housekeeping/gsd-disk-space.c | 27 | ||||
-rw-r--r-- | plugins/housekeeping/gsd-disk-space.h | 2 |
3 files changed, 15 insertions, 16 deletions
diff --git a/meson.build b/meson.build index 88e4f87d..65a1a54b 100644 --- a/meson.build +++ b/meson.build @@ -11,7 +11,7 @@ gsd_major_version = version_array[0].to_int() gsd_api_name = '@0@-@1@'.format(meson.project_name(), gsd_major_version) -glib_min_version = '2.56' +glib_min_version = '2.58' glib_version_def = 'GLIB_VERSION_@0@_@1@'.format( glib_min_version.split('.')[0], glib_min_version.split('.')[1]) diff --git a/plugins/housekeeping/gsd-disk-space.c b/plugins/housekeeping/gsd-disk-space.c index 9d57531f..c5ae8f6b 100644 --- a/plugins/housekeeping/gsd-disk-space.c +++ b/plugins/housekeeping/gsd-disk-space.c @@ -257,7 +257,7 @@ delete_data_new (GFile *file, DeleteData *data; data = g_new (DeleteData, 1); - data->ref_count = 1; + g_ref_count_init (&data->ref_count); data->file = g_object_ref (file); data->filesystem = g_strdup (filesystem); data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; @@ -288,24 +288,23 @@ get_filesystem (GFile *file) static DeleteData * delete_data_ref (DeleteData *data) { - data->ref_count += 1; - return data; + g_ref_count_inc (&data->ref_count); + + return data; } void delete_data_unref (DeleteData *data) { - data->ref_count -= 1; - if (data->ref_count > 0) - return; - - g_object_unref (data->file); - if (data->cancellable) - g_object_unref (data->cancellable); - g_date_time_unref (data->old); - g_free (data->name); - g_free (data->filesystem); - g_free (data); + if (g_ref_count_dec (&data->ref_count)) { + g_object_unref (data->file); + if (data->cancellable) + g_object_unref (data->cancellable); + g_date_time_unref (data->old); + g_free (data->name); + g_free (data->filesystem); + g_free (data); + } } static void diff --git a/plugins/housekeeping/gsd-disk-space.h b/plugins/housekeeping/gsd-disk-space.h index 38c29639..d90d36e3 100644 --- a/plugins/housekeeping/gsd-disk-space.h +++ b/plugins/housekeeping/gsd-disk-space.h @@ -28,7 +28,7 @@ G_BEGIN_DECLS typedef struct { - gint ref_count; + grefcount ref_count; GFile *file; GCancellable *cancellable; GDateTime *old; |