+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):
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;
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)
{
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);
/* Start our thread */
pthread_cond_signal (&ready_cond);
+ pthread_cond_wait (&ready_cond, &pollfd_mutex);
pthread_mutex_unlock (&pollfd_mutex);
}