diff options
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/src/process.c b/src/process.c index 1ff26c83259..9d4e3aa2db6 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -3853,6 +3853,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | |||
| 3853 | for (;;) | 3853 | for (;;) |
| 3854 | { | 3854 | { |
| 3855 | int nfds; | 3855 | int nfds; |
| 3856 | int timeout_reduced_for_timers = 0; | ||
| 3856 | 3857 | ||
| 3857 | if (XINT (read_kbd)) | 3858 | if (XINT (read_kbd)) |
| 3858 | FD_SET (0, &waitchannels); | 3859 | FD_SET (0, &waitchannels); |
| @@ -3865,6 +3866,8 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | |||
| 3865 | if (XINT (read_kbd) >= 0) | 3866 | if (XINT (read_kbd) >= 0) |
| 3866 | QUIT; | 3867 | QUIT; |
| 3867 | 3868 | ||
| 3869 | /* Compute time from now till when time limit is up */ | ||
| 3870 | /* Exit if already run out */ | ||
| 3868 | if (timeout_p) | 3871 | if (timeout_p) |
| 3869 | { | 3872 | { |
| 3870 | EMACS_GET_TIME (*timeout_p); | 3873 | EMACS_GET_TIME (*timeout_p); |
| @@ -3873,6 +3876,29 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | |||
| 3873 | break; | 3876 | break; |
| 3874 | } | 3877 | } |
| 3875 | 3878 | ||
| 3879 | /* If our caller will not immediately handle keyboard events, | ||
| 3880 | run timer events directly. | ||
| 3881 | (Callers that will immediately read keyboard events | ||
| 3882 | call timer_delay on their own.) */ | ||
| 3883 | if (read_kbd >= 0) | ||
| 3884 | { | ||
| 3885 | EMACS_TIME timer_delay; | ||
| 3886 | int old_timers_run = timers_run; | ||
| 3887 | timer_delay = timer_check (1); | ||
| 3888 | if (timers_run != old_timers_run && do_display) | ||
| 3889 | redisplay_preserve_echo_area (); | ||
| 3890 | if (! EMACS_TIME_NEG_P (timer_delay) && timeout_p) | ||
| 3891 | { | ||
| 3892 | EMACS_TIME difference; | ||
| 3893 | EMACS_SUB_TIME (difference, timer_delay, *timeout_p); | ||
| 3894 | if (EMACS_TIME_NEG_P (difference)) | ||
| 3895 | { | ||
| 3896 | *timeout_p = timer_delay; | ||
| 3897 | timeout_reduced_for_timers = 1; | ||
| 3898 | } | ||
| 3899 | } | ||
| 3900 | } | ||
| 3901 | |||
| 3876 | /* Cause C-g and alarm signals to take immediate action, | 3902 | /* Cause C-g and alarm signals to take immediate action, |
| 3877 | and cause input available signals to zero out timeout. */ | 3903 | and cause input available signals to zero out timeout. */ |
| 3878 | if (XINT (read_kbd) < 0) | 3904 | if (XINT (read_kbd) < 0) |
| @@ -3883,9 +3909,23 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | |||
| 3883 | if (frame_garbaged && do_display) | 3909 | if (frame_garbaged && do_display) |
| 3884 | redisplay_preserve_echo_area (); | 3910 | redisplay_preserve_echo_area (); |
| 3885 | 3911 | ||
| 3886 | if (XINT (read_kbd) && detect_input_pending ()) | 3912 | nfds = 1; |
| 3887 | nfds = 0; | 3913 | if (XINT (read_kbd) < 0 && detect_input_pending ()) |
| 3888 | else | 3914 | { |
| 3915 | swallow_events (do_display); | ||
| 3916 | if (detect_input_pending ()) | ||
| 3917 | nfds = 0; | ||
| 3918 | } | ||
| 3919 | |||
| 3920 | if ((XINT (read_kbd) > 0) | ||
| 3921 | && detect_input_pending_run_timers (do_display)) | ||
| 3922 | { | ||
| 3923 | swallow_events (do_display); | ||
| 3924 | if (detect_input_pending_run_timers (do_display)) | ||
| 3925 | nfds = 0; | ||
| 3926 | } | ||
| 3927 | |||
| 3928 | if (nfds) | ||
| 3889 | nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0, | 3929 | nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0, |
| 3890 | timeout_p); | 3930 | timeout_p); |
| 3891 | 3931 | ||
| @@ -3914,7 +3954,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | |||
| 3914 | 3954 | ||
| 3915 | /* If we have timed out (nfds == 0) or found some input (nfds > 0), | 3955 | /* If we have timed out (nfds == 0) or found some input (nfds > 0), |
| 3916 | we should exit. */ | 3956 | we should exit. */ |
| 3917 | if (nfds >= 0) | 3957 | if (nfds >= 0 && ! timeout_reduced_for_timers) |
| 3918 | break; | 3958 | break; |
| 3919 | } | 3959 | } |
| 3920 | 3960 | ||