[nautilus] batch-rename-dialog: don't multi-thread NautilusDirectory calls



commit 32fc66d5bfed95882e1a9746bcc404457d3d1706
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Sep 20 16:37:01 2016 +0200

    batch-rename-dialog: don't multi-thread NautilusDirectory calls
    
    Even if late... I just realized neither NautilusDirectory or
    NautilusFile are thread safe.
    
    We were using them from two different threads for checking conflicts,
    and that was crashing when the internal hash table was modified and
    accessed from the different threads.
    
    The ideal fix would be to make NautilusDirectory and NautilusFile thread
    safe, but that's a big work. So for now, call the main thread for using
    them.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771129

 src/nautilus-batch-rename-dialog.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/src/nautilus-batch-rename-dialog.c b/src/nautilus-batch-rename-dialog.c
index a545d2f..ad71bd3 100644
--- a/src/nautilus-batch-rename-dialog.c
+++ b/src/nautilus-batch-rename-dialog.c
@@ -1226,6 +1226,7 @@ on_file_names_list_has_duplicates (GObject      *object,
 typedef struct
 {
     GList *directories;
+    NautilusDirectory *current_directory;
     GMutex wait_ready_mutex;
     GCond wait_ready_condition;
     gboolean directory_conflicts_ready;
@@ -1256,6 +1257,20 @@ on_directory_conflicts_ready (NautilusDirectory *conflict_directory,
     g_mutex_unlock (&task_data->wait_ready_mutex);
 }
 
+static gboolean
+check_conflicts_on_main_thread (gpointer user_data)
+{
+    GTask *task = (GTask *) user_data;
+    CheckConflictsData *task_data = g_task_get_task_data (task);
+
+    nautilus_directory_call_when_ready (task_data->current_directory,
+                                        NAUTILUS_FILE_ATTRIBUTE_INFO,
+                                        TRUE,
+                                        on_directory_conflicts_ready,
+                                        task);
+    return FALSE;
+}
+
 static void
 file_names_list_has_duplicates_async_thread (GTask        *task,
                                              gpointer      object,
@@ -1290,11 +1305,11 @@ file_names_list_has_duplicates_async_thread (GTask        *task,
         task_data->directory_conflicts_ready = FALSE;
 
 
-        nautilus_directory_call_when_ready (l->data,
-                                            NAUTILUS_FILE_ATTRIBUTE_INFO,
-                                            TRUE,
-                                            on_directory_conflicts_ready,
-                                            task);
+        task_data->current_directory = l->data;
+        /* NautilusDirectory and NautilusFile are not thread safe, we need to call
+         * them on the main thread.
+         */
+        g_main_context_invoke (NULL, check_conflicts_on_main_thread, task);
 
         /* We need to block this thread until the call_when_ready call is done,
          * if not the GTask would finalize. */


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