]> Pileus Git - ~andy/gtk/commitdiff
fix two more potential races that could happen when an application is
authorRonald Bultje <rbultje@ronald.bitfreak.net>
Sat, 28 Apr 2007 18:14:19 +0000 (18:14 +0000)
committerRonald Bultje <rbultje@src.gnome.org>
Sat, 28 Apr 2007 18:14:19 +0000 (18:14 +0000)
2007-04-28  Ronald Bultje  <rbultje@ronald.bitfreak.net>

        * gdk/quartz/gdkeventloop-quartz.c: (select_thread_func),
        (poll_func): fix two more potential races that could happen when
        an application is polling in the mainloop and a separate thread
        tries to wake it up using g_idle_add(). Fixes #425271 comment 5.

svn path=/trunk/; revision=17680

ChangeLog
gdk/quartz/gdkeventloop-quartz.c

index c78af24354ac87c05d8e54764e63b793c87f5d14..6dbd9b6d3030460a0bd55939a80177b49154f8b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-04-28  Ronald Bultje  <rbultje@ronald.bitfreak.net>
+
+       * gdk/quartz/gdkeventloop-quartz.c: (select_thread_func),
+       (poll_func): fix two more potential races that could happen when
+       an application is polling in the mainloop and a separate thread
+       tries to wake it up using g_idle_add(). Fixes #425271 comment 5.
+
 2007-04-28  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkentry.c (gtk_entry_grab_focus): 
index eb52921b1763064d99700a6de49ece22590eac76..d9e9ad85e7e085247b1a97b43be95b4bd7710922 100644 (file)
@@ -13,7 +13,7 @@ static NSEvent *current_event;
 
 static GPollFunc old_poll_func;
 
-static gboolean select_fd_waiting = FALSE;
+static gboolean select_fd_waiting = FALSE, ready_for_poll = FALSE;
 static pthread_t select_thread = 0;
 static int wakeup_pipe[2];
 static pthread_mutex_t pollfd_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -118,20 +118,23 @@ select_thread_func (void *arg)
   int n_active_fds;
 
   pthread_mutex_lock (&pollfd_mutex);
-  pthread_cond_signal (&ready_cond);
 
   while (1)
     {
       char c;
       int n;
 
+      ready_for_poll = TRUE;
+      pthread_cond_signal (&ready_cond);
       pthread_cond_wait (&ready_cond, &pollfd_mutex);
+      ready_for_poll = FALSE;
 
-      pthread_mutex_unlock (&pollfd_mutex);
       select_fd_waiting = TRUE;
+      pthread_cond_signal (&ready_cond);
+      pthread_mutex_unlock (&pollfd_mutex);
       n_active_fds = old_poll_func (pollfds, n_pollfds, -1);
-      select_fd_waiting = FALSE;
       pthread_mutex_lock (&pollfd_mutex);
+      select_fd_waiting = FALSE;
       n = read (pipe_pollfd->fd, &c, 1);
       if (n == 1)
         {
@@ -177,10 +180,12 @@ poll_func (GPollFD *ufds, guint nfds, gint timeout_)
 
         pthread_mutex_lock (&pollfd_mutex);
         pthread_create (&select_thread, NULL, select_thread_func, NULL);
-        pthread_cond_wait (&ready_cond, &pollfd_mutex);
       } else
         pthread_mutex_lock (&pollfd_mutex);
 
+      while (!ready_for_poll)
+        pthread_cond_wait (&ready_cond, &pollfd_mutex);
+
       n_pollfds = nfds;
       g_free (pollfds);
       pollfds = g_memdup (ufds, sizeof (GPollFD) * nfds);
@@ -198,6 +203,7 @@ poll_func (GPollFD *ufds, guint nfds, gint timeout_)
 
       /* Start our thread */
       pthread_cond_signal (&ready_cond);
+      pthread_cond_wait (&ready_cond, &pollfd_mutex);
       pthread_mutex_unlock (&pollfd_mutex);
     }