aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorPaul Eggert2015-07-05 19:19:13 -0700
committerPaul Eggert2015-07-05 19:21:50 -0700
commitad23626030f0541e761f683661b51152128fb0b5 (patch)
tree2ad34efc062b4119443e69dd93eb3a4f79eef838 /src/process.c
parentf469c17b9c869b400b3515535b2f1fd9dd00f9a0 (diff)
downloademacs-ad23626030f0541e761f683661b51152128fb0b5.tar.gz
emacs-ad23626030f0541e761f683661b51152128fb0b5.zip
Avoid duplicate calls to current_timespec
* src/process.c (wait_reading_process_output): Cache current_timespec results as long as we're not waiting.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/process.c b/src/process.c
index 8a8dad793ad..9d8fa2237f3 100644
--- a/src/process.c
+++ b/src/process.c
@@ -4591,6 +4591,9 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4591 int got_some_output = -1; 4591 int got_some_output = -1;
4592 ptrdiff_t count = SPECPDL_INDEX (); 4592 ptrdiff_t count = SPECPDL_INDEX ();
4593 4593
4594 /* Close to the current time if known, an invalid timespec otherwise. */
4595 struct timespec now = invalid_timespec ();
4596
4594 FD_ZERO (&Available); 4597 FD_ZERO (&Available);
4595 FD_ZERO (&Writeok); 4598 FD_ZERO (&Writeok);
4596 4599
@@ -4611,8 +4614,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4611 else if (time_limit > 0 || nsecs > 0) 4614 else if (time_limit > 0 || nsecs > 0)
4612 { 4615 {
4613 wait = TIMEOUT; 4616 wait = TIMEOUT;
4614 end_time = timespec_add (current_timespec (), 4617 now = current_timespec ();
4615 make_timespec (time_limit, nsecs)); 4618 end_time = timespec_add (now, make_timespec (time_limit, nsecs));
4616 } 4619 }
4617 else 4620 else
4618 wait = INFINITY; 4621 wait = INFINITY;
@@ -4637,7 +4640,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4637 /* Exit if already run out. */ 4640 /* Exit if already run out. */
4638 if (wait == TIMEOUT) 4641 if (wait == TIMEOUT)
4639 { 4642 {
4640 struct timespec now = current_timespec (); 4643 if (!timespec_valid_p (now))
4644 now = current_timespec ();
4641 if (timespec_cmp (end_time, now) <= 0) 4645 if (timespec_cmp (end_time, now) <= 0)
4642 break; 4646 break;
4643 timeout = timespec_sub (end_time, now); 4647 timeout = timespec_sub (end_time, now);
@@ -4830,7 +4834,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4830 } 4834 }
4831 else 4835 else
4832 { 4836 {
4833
4834 /* Set the timeout for adaptive read buffering if any 4837 /* Set the timeout for adaptive read buffering if any
4835 process has non-zero read_output_skip and non-zero 4838 process has non-zero read_output_skip and non-zero
4836 read_output_delay, and we are not reading output for a 4839 read_output_delay, and we are not reading output for a
@@ -4876,17 +4879,21 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4876 && timespec_valid_p (timer_delay) 4879 && timespec_valid_p (timer_delay)
4877 && timespec_cmp (timer_delay, timeout) < 0) 4880 && timespec_cmp (timer_delay, timeout) < 0)
4878 { 4881 {
4879 struct timespec timeout_abs = timespec_add (current_timespec (), 4882 if (!timespec_valid_p (now))
4880 timeout); 4883 now = current_timespec ();
4884 struct timespec timeout_abs = timespec_add (now, timeout);
4881 if (!timespec_valid_p (got_output_end_time) 4885 if (!timespec_valid_p (got_output_end_time)
4882 || timespec_cmp (timeout_abs, 4886 || timespec_cmp (timeout_abs, got_output_end_time) < 0)
4883 got_output_end_time) < 0)
4884 got_output_end_time = timeout_abs; 4887 got_output_end_time = timeout_abs;
4885 timeout = timer_delay; 4888 timeout = timer_delay;
4886 } 4889 }
4887 else 4890 else
4888 got_output_end_time = invalid_timespec (); 4891 got_output_end_time = invalid_timespec ();
4889 4892
4893 /* NOW can become inaccurate if time can pass during pselect. */
4894 if (timeout.tv_sec > 0 || timeout.tv_nsec > 0)
4895 now = invalid_timespec ();
4896
4890#if defined (HAVE_NS) 4897#if defined (HAVE_NS)
4891 nfds = ns_select 4898 nfds = ns_select
4892#elif defined (HAVE_GLIB) 4899#elif defined (HAVE_GLIB)
@@ -4965,14 +4972,21 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4965 haven't lowered our timeout due to timers or SIGIO and 4972 haven't lowered our timeout due to timers or SIGIO and
4966 have waited a long amount of time due to repeated 4973 have waited a long amount of time due to repeated
4967 timers. */ 4974 timers. */
4968 struct timespec now = current_timespec (); 4975 if (wait < TIMEOUT)
4969 if (wait < TIMEOUT
4970 || (wait == TIMEOUT && timespec_cmp (end_time, now) <= 0)
4971 || (!process_skipped && got_some_output > 0
4972 && (!timespec_valid_p (got_output_end_time)
4973 || timespec_cmp (got_output_end_time, now) <= 0)
4974 && (timeout.tv_sec > 0 || timeout.tv_nsec > 0)))
4975 break; 4976 break;
4977 struct timespec cmp_time
4978 = (wait == TIMEOUT
4979 ? end_time
4980 : (!process_skipped && got_some_output > 0
4981 && (timeout.tv_sec > 0 || timeout.tv_nsec > 0))
4982 ? got_output_end_time
4983 : invalid_timespec ());
4984 if (timespec_valid_p (cmp_time))
4985 {
4986 now = current_timespec ();
4987 if (timespec_cmp (cmp_time, now) <= 0)
4988 break;
4989 }
4976 } 4990 }
4977 4991
4978 if (nfds < 0) 4992 if (nfds < 0)