summaryrefslogtreecommitdiff
path: root/src/process.c
diff options
context:
space:
mode:
authorMiha Rihtaršič <miha@kamnitnik.top>2021-05-25 21:01:58 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2021-05-25 21:01:58 +0200
commit0c7a7433dce1b93a685396986d3a560c9cc291f1 (patch)
treeafd126aaef741769b2724fcdf3ae85468406f3ea /src/process.c
parent316de2a1317d40a9c68a220bd8a0014f4e31a536 (diff)
downloademacs-0c7a7433dce1b93a685396986d3a560c9cc291f1.tar.gz
Try to not prioritise reading from lower file descriptors
* src/process.c (wait_reading_process_output): When looping through fds, continue from where we left off. (syms_of_process): Vprocess_prioritize_lower_fds: New variable (bug#48118).
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/process.c b/src/process.c
index 47a2a6f1a31..2f32eadd50d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -5134,6 +5134,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
Lisp_Object wait_for_cell,
struct Lisp_Process *wait_proc, int just_wait_proc)
{
+ static int last_read_channel = -1;
int channel, nfds;
fd_set Available;
fd_set Writeok;
@@ -5188,6 +5189,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
while (1)
{
bool process_skipped = false;
+ bool wrapped;
+ int channel_start;
/* If calling from keyboard input, do not quit
since we want to return C-g as an input character.
@@ -5722,8 +5725,21 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
d->func (channel, d->data);
}
- for (channel = 0; channel <= max_desc; channel++)
+ /* Do round robin if `process-pritoritize-lower-fds' is nil. */
+ channel_start
+ = process_prioritize_lower_fds ? 0 : last_read_channel + 1;
+
+ for (channel = channel_start, wrapped = false;
+ !wrapped || (channel < channel_start && channel <= max_desc);
+ channel++)
{
+ if (channel > max_desc)
+ {
+ wrapped = true;
+ channel = -1;
+ continue;
+ }
+
if (FD_ISSET (channel, &Available)
&& ((fd_callback_info[channel].flags & (KEYBOARD_FD | PROCESS_FD))
== PROCESS_FD))
@@ -5761,6 +5777,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
don't try to read from any other processes
before doing the select again. */
FD_ZERO (&Available);
+ last_read_channel = channel;
if (do_display)
redisplay_preserve_echo_area (12);
@@ -8477,6 +8494,13 @@ non-nil value means that the delay is not reset on write.
The variable takes effect when `start-process' is called. */);
Vprocess_adaptive_read_buffering = Qt;
+ DEFVAR_BOOL ("process-prioritize-lower-fds", process_prioritize_lower_fds,
+ doc: /* If nil, try to not prioritize reading from any specific process.
+Emacs loops through file descriptors to receive data from subprocesses. After
+accepting output from the first file descriptor with available data, restart the
+loop from the file descriptor 0 if this option is non-nil. */);
+ process_prioritize_lower_fds = 0;
+
DEFVAR_LISP ("interrupt-process-functions", Vinterrupt_process_functions,
doc: /* List of functions to be called for `interrupt-process'.
The arguments of the functions are the same as for `interrupt-process'.