[gtk+/gtk-2-24] Ensure we always grab the gdk lock in async callbacks



commit c9c23b0728552f9b7a640839100a82ae6d9ac81b
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Mar 28 14:00:03 2011 +0200

    Ensure we always grab the gdk lock in async callbacks
    
    Async callbacks are delivered in idles, so we need to make sure
    we get the gdk lock before calling any gdk/gtk stuff. This was
    missing in a few places.

 gtk/gtkfilechooserdefault.c  |    9 ++++++++-
 gtk/gtkfilesystem.c          |    3 +++
 gtk/gtkfilesystemmodel.c     |    4 ++++
 gtk/gtkrecentmanager.c       |    6 ++++++
 gtk/gtksearchenginetracker.c |   10 +++++++++-
 5 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 8d29f9f..dc95a7c 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -6648,11 +6648,16 @@ file_system_model_got_thumbnail (GObject *object, GAsyncResult *res, gpointer da
   if (queried == NULL)
     return;
 
+  GDK_THREADS_ENTER ();
+
   /* now we know model is valid */
 
   /* file was deleted */
   if (!_gtk_file_system_model_get_iter_for_file (model, &iter, file))
-    return;
+    {
+      GDK_THREADS_LEAVE ();
+      return;
+    }
 
   info = g_file_info_dup (_gtk_file_system_model_get_info (model, &iter));
 
@@ -6663,6 +6668,8 @@ file_system_model_got_thumbnail (GObject *object, GAsyncResult *res, gpointer da
   _gtk_file_system_model_update_file (model, file, info, FALSE);
 
   g_object_unref (info);
+
+  GDK_THREADS_LEAVE ();
 }
 
 static gboolean
diff --git a/gtk/gtkfilesystem.c b/gtk/gtkfilesystem.c
index ea79fed..112c600 100644
--- a/gtk/gtkfilesystem.c
+++ b/gtk/gtkfilesystem.c
@@ -1345,6 +1345,8 @@ query_created_file_info_callback (GObject      *source_object,
       return;
     }
 
+  gdk_threads_enter ();
+
   folder = GTK_FOLDER (user_data);
   gtk_folder_add_file (folder, file, info);
 
@@ -1353,6 +1355,7 @@ query_created_file_info_callback (GObject      *source_object,
   g_slist_free (files);
 
   g_object_unref (info);
+  gdk_threads_leave ();
 }
 
 static void
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c
index 933420c..1ba14d3 100644
--- a/gtk/gtkfilesystemmodel.c
+++ b/gtk/gtkfilesystemmodel.c
@@ -1150,7 +1150,9 @@ gtk_file_system_model_query_done (GObject *     object,
   if (info == NULL)
     return;
 
+  gdk_threads_enter ();
   _gtk_file_system_model_update_file (model, file, info, TRUE);
+  gdk_threads_leave ();
 }
 
 static void
@@ -1175,7 +1177,9 @@ gtk_file_system_model_monitor_change (GFileMonitor *      monitor,
                                  model);
         break;
       case G_FILE_MONITOR_EVENT_DELETED:
+	gdk_threads_enter ();
         remove_file (model, file);
+	gdk_threads_leave ();
         break;
       case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
         /* FIXME: use freeze/thaw with this somehow? */
diff --git a/gtk/gtkrecentmanager.c b/gtk/gtkrecentmanager.c
index ace6f4f..8d62e30 100644
--- a/gtk/gtkrecentmanager.c
+++ b/gtk/gtkrecentmanager.c
@@ -457,7 +457,9 @@ gtk_recent_manager_monitor_changed (GFileMonitor      *monitor,
     {
     case G_FILE_MONITOR_EVENT_CHANGED:
     case G_FILE_MONITOR_EVENT_CREATED:
+      gdk_threads_enter ();
       gtk_recent_manager_changed (manager);
+      gdk_threads_leave ();
       break;
 
     case G_FILE_MONITOR_EVENT_DELETED:
@@ -931,6 +933,8 @@ gtk_recent_manager_add_item_query_info (GObject      *source_object,
   recent_data.groups = NULL;
   recent_data.is_private = FALSE;
 
+  gdk_threads_enter ();
+
   /* Ignore return value, this can't fail anyway since all required
    * fields are set */
   gtk_recent_manager_add_full (manager, uri, &recent_data);
@@ -938,6 +942,8 @@ gtk_recent_manager_add_item_query_info (GObject      *source_object,
   manager->priv->is_dirty = TRUE;
   gtk_recent_manager_changed (manager);
 
+  gdk_threads_leave ();
+
   g_free (recent_data.mime_type);
   g_free (recent_data.app_name);
   g_free (recent_data.app_exec);
diff --git a/gtk/gtksearchenginetracker.c b/gtk/gtksearchenginetracker.c
index e46691a..6f3f046 100644
--- a/gtk/gtksearchenginetracker.c
+++ b/gtk/gtksearchenginetracker.c
@@ -226,6 +226,8 @@ search_callback (gpointer results,
   gchar *uri;
   gint i;
 
+  gdk_threads_enter ();
+
   tracker = GTK_SEARCH_ENGINE_TRACKER (user_data);
   hit_uris = NULL;
 
@@ -235,11 +237,15 @@ search_callback (gpointer results,
     {
       _gtk_search_engine_error (GTK_SEARCH_ENGINE (tracker), error->message);
       g_error_free (error);
+      gdk_threads_leave ();
       return;
     }
 
   if (!results)
-    return;
+    {
+      gdk_threads_leave ();
+      return;
+    }
 
   if (tracker->priv->version == TRACKER_0_8 ||
       tracker->priv->version == TRACKER_0_9)
@@ -276,6 +282,8 @@ search_callback (gpointer results,
 
   g_list_foreach (hit_uris, (GFunc) g_free, NULL);
   g_list_free (hit_uris);
+
+  gdk_threads_leave ();
 }
 
 



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