neil / rpms / udisks2

Forked from rpms/udisks2 a year ago
Clone

Blame SOURCES/udisks-2.10.0-ata_conf_apply_GTask.patch

aebde2
commit 6ff556afabd490feb6c4b29f9e91e81d64e2c0ed
aebde2
Author: Tomas Bzatek <tbzatek@redhat.com>
aebde2
Date:   Tue Mar 23 12:56:40 2021 +0100
aebde2
aebde2
    udiskslinuxdriveata: Use GTask to apply configuration in a thread
aebde2
    
aebde2
    Should fix a leaking GThread without a need to join or track it anyhow.
aebde2
aebde2
diff --git a/src/udiskslinuxdriveata.c b/src/udiskslinuxdriveata.c
aebde2
index 5ebdcd76..2de138cd 100644
aebde2
--- a/src/udiskslinuxdriveata.c
aebde2
+++ b/src/udiskslinuxdriveata.c
aebde2
@@ -1625,10 +1625,13 @@ apply_conf_data_free (ApplyConfData *data)
aebde2
   g_free (data);
aebde2
 }
aebde2
 
aebde2
-static gpointer
aebde2
-apply_configuration_thread_func (gpointer user_data)
aebde2
+static void
aebde2
+apply_configuration_thread_func (GTask        *task,
aebde2
+                                 gpointer      source_object,
aebde2
+                                 gpointer      task_data,
aebde2
+                                 GCancellable *cancellable)
aebde2
 {
aebde2
-  ApplyConfData *data = user_data;
aebde2
+  ApplyConfData *data = task_data;
aebde2
   UDisksDaemon *daemon;
aebde2
   const gchar *device_file = NULL;
aebde2
   gint fd = -1;
aebde2
@@ -1799,8 +1802,6 @@ apply_configuration_thread_func (gpointer user_data)
aebde2
  out:
aebde2
   if (fd != -1)
aebde2
     close (fd);
aebde2
-  apply_conf_data_free (data);
aebde2
-  return NULL;
aebde2
 }
aebde2
 
aebde2
 /**
aebde2
@@ -1819,6 +1820,7 @@ udisks_linux_drive_ata_apply_configuration (UDisksLinuxDriveAta *drive,
aebde2
 {
aebde2
   gboolean has_conf = FALSE;
aebde2
   ApplyConfData *data = NULL;
aebde2
+  GTask *task;
aebde2
 
aebde2
   data = g_new0 (ApplyConfData, 1);
aebde2
   data->ata_pm_standby = -1;
aebde2
@@ -1862,9 +1864,10 @@ udisks_linux_drive_ata_apply_configuration (UDisksLinuxDriveAta *drive,
aebde2
   /* this can easily take a long time and thus block (the drive may be in standby mode
aebde2
    * and needs to spin up) - so run it in a thread
aebde2
    */
aebde2
-  g_thread_new ("apply-conf-thread",
aebde2
-                apply_configuration_thread_func,
aebde2
-                data);
aebde2
+  task = g_task_new (data->object, NULL, NULL, NULL);
aebde2
+  g_task_set_task_data (task, data, (GDestroyNotify) apply_conf_data_free);
aebde2
+  g_task_run_in_thread (task, apply_configuration_thread_func);
aebde2
+  g_object_unref (task);
aebde2
 
aebde2
   data = NULL; /* don't free data below */
aebde2