diff options
| author | Paul Eggert | 2012-08-25 13:31:04 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-08-25 13:31:04 -0700 |
| commit | 0f46bc7515ccc835e5752b47f8752ab7aaf7ed27 (patch) | |
| tree | 9908d3cbf36442fb40595ffd0338dff74f8b9cbc | |
| parent | 9aba119d72dde74a86d436f6e4f934baa37ecbe9 (diff) | |
| download | emacs-0f46bc7515ccc835e5752b47f8752ab7aaf7ed27.tar.gz emacs-0f46bc7515ccc835e5752b47f8752ab7aaf7ed27.zip | |
* xgselect.c (xg_select): Use auto storage for the GPollFD buffer
as that's faster and simpler than static storage. Don't bother
with the g_main_context_query overhead if g_main_context_pending
says no events are pending.
(gfds, gfds_size): Remove these static vars.
(xgselect_initialize): Remove; no longer needed.
All uses and decls removed.
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/xgselect.c | 52 | ||||
| -rw-r--r-- | src/xgselect.h | 2 | ||||
| -rw-r--r-- | src/xterm.c | 2 |
4 files changed, 27 insertions, 37 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index eacb82d9814..5654a191ec0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,13 @@ | |||
| 1 | 2012-08-25 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2012-08-25 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * xgselect.c (xg_select): Use auto storage for the GPollFD buffer | ||
| 4 | as that's faster and simpler than static storage. Don't bother | ||
| 5 | with the g_main_context_query overhead if g_main_context_pending | ||
| 6 | says no events are pending. | ||
| 7 | (gfds, gfds_size): Remove these static vars. | ||
| 8 | (xgselect_initialize): Remove; no longer needed. | ||
| 9 | All uses and decls removed. | ||
| 10 | |||
| 3 | * emacs.c (fatal_error_signal_hook): Remove. | 11 | * emacs.c (fatal_error_signal_hook): Remove. |
| 4 | All uses removed. This leftover from old code was always 0. | 12 | All uses removed. This leftover from old code was always 0. |
| 5 | 13 | ||
diff --git a/src/xgselect.c b/src/xgselect.c index 04ca00274e8..0c00d815820 100644 --- a/src/xgselect.c +++ b/src/xgselect.c | |||
| @@ -29,9 +29,6 @@ along with GNU Emacs. If not, see <http§://www.gnu.org/licenses/>. */ | |||
| 29 | #include <setjmp.h> | 29 | #include <setjmp.h> |
| 30 | #include "xterm.h" | 30 | #include "xterm.h" |
| 31 | 31 | ||
| 32 | static GPollFD *gfds; | ||
| 33 | static ptrdiff_t gfds_size; | ||
| 34 | |||
| 35 | int | 32 | int |
| 36 | xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, | 33 | xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, |
| 37 | EMACS_TIME *timeout, sigset_t *sigmask) | 34 | EMACS_TIME *timeout, sigset_t *sigmask) |
| @@ -41,35 +38,31 @@ xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, | |||
| 41 | 38 | ||
| 42 | GMainContext *context; | 39 | GMainContext *context; |
| 43 | int have_wfds = wfds != NULL; | 40 | int have_wfds = wfds != NULL; |
| 44 | int n_gfds = 0, retval = 0, our_fds = 0, max_fds = fds_lim - 1; | 41 | GPollFD gfds_buf[128]; |
| 42 | GPollFD *gfds = gfds_buf; | ||
| 43 | int gfds_size = sizeof gfds_buf / sizeof *gfds_buf; | ||
| 44 | int n_gfds, retval = 0, our_fds = 0, max_fds = fds_lim - 1; | ||
| 45 | int i, nfds, tmo_in_millisec; | 45 | int i, nfds, tmo_in_millisec; |
| 46 | USE_SAFE_ALLOCA; | ||
| 46 | 47 | ||
| 47 | if (!x_in_use) | 48 | if (! (x_in_use |
| 48 | return pselect (fds_lim, rfds, wfds, efds, tmop, sigmask); | 49 | && g_main_context_pending (context = g_main_context_default ()))) |
| 50 | return pselect (fds_lim, rfds, wfds, efds, timeout, sigmask); | ||
| 49 | 51 | ||
| 50 | if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds)); | 52 | if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds)); |
| 51 | else FD_ZERO (&all_rfds); | 53 | else FD_ZERO (&all_rfds); |
| 52 | if (wfds) memcpy (&all_wfds, wfds, sizeof (all_rfds)); | 54 | if (wfds) memcpy (&all_wfds, wfds, sizeof (all_rfds)); |
| 53 | else FD_ZERO (&all_wfds); | 55 | else FD_ZERO (&all_wfds); |
| 54 | 56 | ||
| 55 | /* Update event sources in GLib. */ | 57 | n_gfds = g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec, |
| 56 | context = g_main_context_default (); | 58 | gfds, gfds_size); |
| 57 | g_main_context_pending (context); | 59 | if (gfds_size < n_gfds) |
| 58 | 60 | { | |
| 59 | do { | 61 | SAFE_NALLOCA (gfds, sizeof *gfds, n_gfds); |
| 60 | if (n_gfds > gfds_size) | 62 | gfds_size = n_gfds; |
| 61 | { | 63 | n_gfds = g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec, |
| 62 | xfree (gfds); | 64 | gfds, gfds_size); |
| 63 | gfds = xpalloc (0, &gfds_size, n_gfds - gfds_size, INT_MAX, | 65 | } |
| 64 | sizeof *gfds); | ||
| 65 | } | ||
| 66 | |||
| 67 | n_gfds = g_main_context_query (context, | ||
| 68 | G_PRIORITY_LOW, | ||
| 69 | &tmo_in_millisec, | ||
| 70 | gfds, | ||
| 71 | gfds_size); | ||
| 72 | } while (n_gfds > gfds_size); | ||
| 73 | 66 | ||
| 74 | for (i = 0; i < n_gfds; ++i) | 67 | for (i = 0; i < n_gfds; ++i) |
| 75 | { | 68 | { |
| @@ -86,6 +79,8 @@ xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, | |||
| 86 | } | 79 | } |
| 87 | } | 80 | } |
| 88 | 81 | ||
| 82 | SAFE_FREE (); | ||
| 83 | |||
| 89 | if (tmo_in_millisec >= 0) | 84 | if (tmo_in_millisec >= 0) |
| 90 | { | 85 | { |
| 91 | tmo = make_emacs_time (tmo_in_millisec / 1000, | 86 | tmo = make_emacs_time (tmo_in_millisec / 1000, |
| @@ -147,12 +142,3 @@ xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, | |||
| 147 | return retval; | 142 | return retval; |
| 148 | } | 143 | } |
| 149 | #endif /* USE_GTK || HAVE_GCONF || HAVE_GSETTINGS */ | 144 | #endif /* USE_GTK || HAVE_GCONF || HAVE_GSETTINGS */ |
| 150 | |||
| 151 | void | ||
| 152 | xgselect_initialize (void) | ||
| 153 | { | ||
| 154 | #if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS) | ||
| 155 | gfds_size = 128; | ||
| 156 | gfds = xmalloc (gfds_size * sizeof *gfds); | ||
| 157 | #endif | ||
| 158 | } | ||
diff --git a/src/xgselect.h b/src/xgselect.h index 8e5614ea972..5509e23c5c0 100644 --- a/src/xgselect.h +++ b/src/xgselect.h | |||
| @@ -31,6 +31,4 @@ extern int xg_select (int max_fds, | |||
| 31 | EMACS_TIME *timeout, | 31 | EMACS_TIME *timeout, |
| 32 | sigset_t *sigmask); | 32 | sigset_t *sigmask); |
| 33 | 33 | ||
| 34 | extern void xgselect_initialize (void); | ||
| 35 | |||
| 36 | #endif /* XGSELECT_H */ | 34 | #endif /* XGSELECT_H */ |
diff --git a/src/xterm.c b/src/xterm.c index 118c8767c23..7e61cc4d8ea 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -10815,8 +10815,6 @@ x_initialize (void) | |||
| 10815 | XSetIOErrorHandler (x_io_error_quitter); | 10815 | XSetIOErrorHandler (x_io_error_quitter); |
| 10816 | 10816 | ||
| 10817 | signal (SIGPIPE, x_connection_signal); | 10817 | signal (SIGPIPE, x_connection_signal); |
| 10818 | |||
| 10819 | xgselect_initialize (); | ||
| 10820 | } | 10818 | } |
| 10821 | 10819 | ||
| 10822 | 10820 | ||