emacs-diffs
[Top][All Lists]
Advanced

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

feature/pgtk 105205c: Get rid of pgtk_select and use xg_select instead


From: Po Lu
Subject: feature/pgtk 105205c: Get rid of pgtk_select and use xg_select instead
Date: Mon, 29 Nov 2021 19:53:03 -0500 (EST)

branch: feature/pgtk
commit 105205c86bc082eb73b15d6329745e3629ab9431
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Get rid of pgtk_select and use xg_select instead
    
    * src/pgtkmenu.c (pgtk_menu_wait_for_event): Get rid
    of pgtk_select.
    * src/pgtkterm.h (pgtk_select):
    * src/pgtkterm.c (pgtk_select): Delete function.
    * src/process.c (wait_reading_process_output): Stop
    using pgtk_select.
---
 src/pgtkmenu.c |   3 +-
 src/pgtkterm.c | 167 ---------------------------------------------------------
 src/pgtkterm.h |   3 --
 src/process.c  |  10 ++--
 4 files changed, 6 insertions(+), 177 deletions(-)

diff --git a/src/pgtkmenu.c b/src/pgtkmenu.c
index b8f4619..88020c3 100644
--- a/src/pgtkmenu.c
+++ b/src/pgtkmenu.c
@@ -37,6 +37,7 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include "keyboard.h"
 #include "menu.h"
 #include "pdumper.h"
+#include "xgselect.h"
 
 #include "gtkutil.h"
 #include <gtk/gtk.h>
@@ -82,7 +83,7 @@ pgtk_menu_wait_for_event (void *data)
   /* Gtk3 have arrows on menus when they don't fit.  When the
      pointer is over an arrow, a timeout scrolls it a bit.  Use
      xg_select so that timeout gets triggered.  */
-  pgtk_select (0, NULL, NULL, NULL, ntp, NULL);
+  xg_select (0, NULL, NULL, NULL, ntp, NULL);
 }
 
 DEFUN ("x-menu-bar-open-internal", Fx_menu_bar_open_internal, 
Sx_menu_bar_open_internal, 0, 1, "i",
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index 27b7cca..f7aadec 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -3700,173 +3700,6 @@ pgtk_read_socket (struct terminal *terminal, struct 
input_event *hold_quit)
   return 0;
 }
 
-int
-pgtk_select (int fds_lim, fd_set * rfds, fd_set * wfds, fd_set * efds,
-            struct timespec *timeout, sigset_t * sigmask)
-{
-  fd_set all_rfds, all_wfds;
-  struct timespec tmo;
-  struct timespec *tmop = timeout;
-
-  GMainContext *context;
-  bool have_wfds = wfds != NULL;
-  GPollFD gfds_buf[128];
-  GPollFD *gfds = gfds_buf;
-  int gfds_size = ARRAYELTS (gfds_buf);
-  int n_gfds, retval = 0, our_fds = 0, max_fds = fds_lim - 1;
-  bool context_acquired = false;
-  int i, nfds, tmo_in_millisec, must_free = 0;
-  bool need_to_dispatch;
-
-  if (event_q.nr >= 1)
-    {
-      raise (SIGIO);
-      errno = EINTR;
-      return -1;
-    }
-
-  context = g_main_context_default ();
-  context_acquired = g_main_context_acquire (context);
-  /* FIXME: If we couldn't acquire the context, we just silently proceed
-     because this function handles more than just glib file descriptors.
-     Note that, as implemented, this failure is completely silent: there is
-     no feedback to the caller.  */
-
-  /* Before sleep, dispatch draw events.
-   * Don't do this after g_main_context_query(), because fd may be closed
-   * in dispatch.
-   */
-  if (context_acquired)
-    {
-      int pselect_errno = errno;
-      block_input ();
-      while (g_main_context_pending (context))
-       g_main_context_dispatch (context);
-      unblock_input ();
-      errno = pselect_errno;
-    }
-
-  if (rfds)
-    all_rfds = *rfds;
-  else
-    FD_ZERO (&all_rfds);
-  if (wfds)
-    all_wfds = *wfds;
-  else
-    FD_ZERO (&all_wfds);
-
-  n_gfds = (context_acquired
-           ? g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec,
-                                   gfds, gfds_size) : -1);
-
-  if (gfds_size < n_gfds)
-    {
-      /* Avoid using SAFE_NALLOCA, as that implicitly refers to the
-         current thread.  Using xnmalloc avoids thread-switching
-         problems here.  */
-      gfds = xnmalloc (n_gfds, sizeof *gfds);
-      must_free = 1;
-      gfds_size = n_gfds;
-      n_gfds =
-       g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec, gfds,
-                             gfds_size);
-    }
-
-  for (i = 0; i < n_gfds; ++i)
-    {
-      if (gfds[i].events & G_IO_IN)
-       {
-         FD_SET (gfds[i].fd, &all_rfds);
-         if (gfds[i].fd > max_fds)
-           max_fds = gfds[i].fd;
-       }
-      if (gfds[i].events & G_IO_OUT)
-       {
-         FD_SET (gfds[i].fd, &all_wfds);
-         if (gfds[i].fd > max_fds)
-           max_fds = gfds[i].fd;
-         have_wfds = true;
-       }
-    }
-
-  if (must_free)
-    xfree (gfds);
-
-  if (n_gfds >= 0 && tmo_in_millisec >= 0)
-    {
-      tmo = make_timespec (tmo_in_millisec / 1000,
-                          1000 * 1000 * (tmo_in_millisec % 1000));
-      if (!timeout || timespec_cmp (tmo, *timeout) < 0)
-       tmop = &tmo;
-    }
-
-  fds_lim = max_fds + 1;
-  nfds = thread_select (pselect, fds_lim,
-                       &all_rfds, have_wfds ? &all_wfds : NULL, efds,
-                       tmop, sigmask);
-  if (nfds < 0)
-    retval = nfds;
-  else if (nfds > 0)
-    {
-      for (i = 0; i < fds_lim; ++i)
-       {
-         if (FD_ISSET (i, &all_rfds))
-           {
-             if (rfds && FD_ISSET (i, rfds))
-               ++retval;
-             else
-               ++our_fds;
-           }
-         else if (rfds)
-           FD_CLR (i, rfds);
-
-         if (have_wfds && FD_ISSET (i, &all_wfds))
-           {
-             if (wfds && FD_ISSET (i, wfds))
-               ++retval;
-             else
-               ++our_fds;
-           }
-         else if (wfds)
-           FD_CLR (i, wfds);
-
-         if (efds && FD_ISSET (i, efds))
-           ++retval;
-       }
-    }
-
-  /* If Gtk+ is in use eventually gtk_main_iteration will be called,
-     unless retval is zero.  */
-  need_to_dispatch = retval == 0;
-  if (need_to_dispatch && context_acquired)
-    {
-      int pselect_errno = errno;
-      /* Prevent g_main_dispatch recursion, that would occur without
-         block_input wrapper, because event handlers call
-         unblock_input.  Event loop recursion was causing Bug#15801.  */
-      block_input ();
-      while (g_main_context_pending (context))
-       {
-         g_main_context_dispatch (context);
-       }
-      unblock_input ();
-      errno = pselect_errno;
-    }
-
-  if (context_acquired)
-    g_main_context_release (context);
-
-  /* To not have to recalculate timeout, return like this.  */
-  if ((our_fds > 0 || (nfds == 0 && tmop == &tmo)) && (retval == 0))
-    {
-      retval = -1;
-      errno = EINTR;
-    }
-
-  return retval;
-}
-
-
 /* Lisp window being scrolled.  Set when starting to interact with
    a toolkit scroll bar, reset to nil when ending the interaction.  */
 
diff --git a/src/pgtkterm.h b/src/pgtkterm.h
index 635c5e6..231c8e8 100644
--- a/src/pgtkterm.h
+++ b/src/pgtkterm.h
@@ -571,9 +571,6 @@ extern void x_set_no_accept_focus (struct frame *f, 
Lisp_Object new_value,
                                   Lisp_Object old_value);
 extern void x_set_z_group (struct frame *f, Lisp_Object new_value,
                           Lisp_Object old_value);
-extern int pgtk_select (int nfds, fd_set * readfds, fd_set * writefds,
-                       fd_set * exceptfds, struct timespec *timeout,
-                       sigset_t * sigmask);
 
 /* Cairo related functions implemented in pgtkterm.c */
 extern void pgtk_cr_update_surface_desired_size (struct frame *, int, int);
diff --git a/src/process.c b/src/process.c
index eb27dde..241ffe9 100644
--- a/src/process.c
+++ b/src/process.c
@@ -5588,19 +5588,17 @@ wait_reading_process_output (intmax_t time_limit, int 
nsecs, int read_kbd,
            timeout = make_timespec (0, 0);
 #endif
 
-#if defined HAVE_PGTK
-         nfds = pgtk_select (max_desc + 1,
-                             &Available, (check_write ? &Writeok : 0),
-                             NULL, &timeout, NULL);
-#elif !defined USABLE_SIGIO && !defined WINDOWSNT
+#if !defined USABLE_SIGIO && !defined WINDOWSNT
          /* If we're polling for input, don't get stuck in select for
             more than 25 msec. */
          struct timespec short_timeout = make_timespec (0, 25000000);
          if ((read_kbd || !NILP (wait_for_cell))
              && timespec_cmp (short_timeout, timeout) < 0)
            timeout = short_timeout;
-#elif defined HAVE_GLIB && !defined HAVE_NS
+#endif
+
          /* Non-macOS HAVE_GLIB builds call thread_select in xgselect.c.  */
+#if defined HAVE_GLIB && !defined HAVE_NS
          nfds = xg_select (max_desc + 1,
                            &Available, (check_write ? &Writeok : 0),
                            NULL, &timeout, NULL);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]