comparison src/process.c @ 15021:af36df262fc5

(wait_reading_process_input) [!subprocesses]: Handle the case of READ_KBD being a cons cell. Retry the timer check after a timer fired. (All of these make this definition consistent with the one that supports async subprocesses.) (wait_reading_process_input, both definitions): Use plain detect_input_pending just before the select call.
author Richard M. Stallman <rms@gnu.org>
date Sun, 14 Apr 1996 17:45:31 +0000
parents ffbd85603f91
children e5f54fd1c352
comparison
equal deleted inserted replaced
15020:85feb24c0ac5 15021:af36df262fc5
2172 redisplay_preserve_echo_area (); 2172 redisplay_preserve_echo_area ();
2173 if (XINT (read_kbd) < 0) 2173 if (XINT (read_kbd) < 0)
2174 set_waiting_for_input (&timeout); 2174 set_waiting_for_input (&timeout);
2175 } 2175 }
2176 2176
2177 { 2177 if (XINT (read_kbd) && detect_input_pending ())
2178 int old_timers_run = timers_run; 2178 {
2179 if (XINT (read_kbd) && detect_input_pending_run_timers (do_display)) 2179 nfds = 0;
2180 { 2180 FD_ZERO (&Available);
2181 nfds = 0; 2181 }
2182 FD_ZERO (&Available); 2182 else
2183 } 2183 nfds = select (MAXDESC, &Available, (SELECT_TYPE *)0, (SELECT_TYPE *)0,
2184 else if (timers_run != old_timers_run) 2184 &timeout);
2185 ;
2186 else
2187 nfds = select (MAXDESC, &Available, (SELECT_TYPE *)0, (SELECT_TYPE *)0,
2188 &timeout);
2189 }
2190 2185
2191 xerrno = errno; 2186 xerrno = errno;
2192 2187
2193 /* Make C-g and alarm signals set flags again */ 2188 /* Make C-g and alarm signals set flags again */
2194 clear_waiting_for_input (); 2189 clear_waiting_for_input ();
3828 read_kbd is a Lisp_Object: 3823 read_kbd is a Lisp_Object:
3829 0 to ignore keyboard input, or 3824 0 to ignore keyboard input, or
3830 1 to return when input is available, or 3825 1 to return when input is available, or
3831 -1 means caller will actually read the input, so don't throw to 3826 -1 means caller will actually read the input, so don't throw to
3832 the quit handler. 3827 the quit handler.
3828 a cons cell, meaning wait until its car is non-nil
3829 (and gobble terminal input into the buffer if any arrives), or
3833 We know that read_kbd will never be a Lisp_Process, since 3830 We know that read_kbd will never be a Lisp_Process, since
3834 `subprocesses' isn't defined. 3831 `subprocesses' isn't defined.
3835 3832
3836 do_display != 0 means redisplay should be done to show subprocess 3833 do_display != 0 means redisplay should be done to show subprocess
3837 output that arrives. 3834 output that arrives.
3845 int do_display; 3842 int do_display;
3846 { 3843 {
3847 EMACS_TIME end_time, timeout; 3844 EMACS_TIME end_time, timeout;
3848 SELECT_TYPE waitchannels; 3845 SELECT_TYPE waitchannels;
3849 int xerrno; 3846 int xerrno;
3847 Lisp_Object *wait_for_cell = 0;
3848
3849 /* If waiting for non-nil in a cell, record where. */
3850 if (CONSP (read_kbd))
3851 {
3852 wait_for_cell = &XCONS (read_kbd)->car;
3853 XSETFASTINT (read_kbd, 0);
3854 }
3850 3855
3851 /* What does time_limit really mean? */ 3856 /* What does time_limit really mean? */
3852 if (time_limit || microsecs) 3857 if (time_limit || microsecs)
3853 { 3858 {
3854 if (time_limit == -1) 3859 if (time_limit == -1)
3872 for (;;) 3877 for (;;)
3873 { 3878 {
3874 int nfds; 3879 int nfds;
3875 int timeout_reduced_for_timers = 0; 3880 int timeout_reduced_for_timers = 0;
3876 3881
3877 if (XINT (read_kbd))
3878 FD_SET (0, &waitchannels);
3879 else
3880 FD_ZERO (&waitchannels);
3881
3882 /* If calling from keyboard input, do not quit 3882 /* If calling from keyboard input, do not quit
3883 since we want to return C-g as an input character. 3883 since we want to return C-g as an input character.
3884 Otherwise, do pending quit if requested. */ 3884 Otherwise, do pending quit if requested. */
3885 if (XINT (read_kbd) >= 0) 3885 if (XINT (read_kbd) >= 0)
3886 QUIT; 3886 QUIT;
3887
3888 /* Exit now if the cell we're waiting for became non-nil. */
3889 if (wait_for_cell && ! NILP (*wait_for_cell))
3890 break;
3887 3891
3888 /* Compute time from now till when time limit is up */ 3892 /* Compute time from now till when time limit is up */
3889 /* Exit if already run out */ 3893 /* Exit if already run out */
3890 if (time_limit > 0 || microsecs) 3894 if (time_limit > 0 || microsecs)
3891 { 3895 {
3897 3901
3898 /* If our caller will not immediately handle keyboard events, 3902 /* If our caller will not immediately handle keyboard events,
3899 run timer events directly. 3903 run timer events directly.
3900 (Callers that will immediately read keyboard events 3904 (Callers that will immediately read keyboard events
3901 call timer_delay on their own.) */ 3905 call timer_delay on their own.) */
3902 if (XINT (read_kbd) >= 0) 3906 if (1)
3903 { 3907 {
3904 EMACS_TIME timer_delay; 3908 EMACS_TIME timer_delay;
3905 int old_timers_run = timers_run; 3909 int old_timers_run;
3910
3911 retry:
3912 old_timers_run = timers_run;
3906 timer_delay = timer_check (1); 3913 timer_delay = timer_check (1);
3907 if (timers_run != old_timers_run && do_display) 3914 if (timers_run != old_timers_run && do_display)
3908 redisplay_preserve_echo_area (); 3915 {
3916 redisplay_preserve_echo_area ();
3917 /* We must retry, since a timer may have requeued itself
3918 and that could alter the time delay. */
3919 goto retry;
3920 }
3921
3909 if (! EMACS_TIME_NEG_P (timer_delay) && time_limit != -1) 3922 if (! EMACS_TIME_NEG_P (timer_delay) && time_limit != -1)
3910 { 3923 {
3911 EMACS_TIME difference; 3924 EMACS_TIME difference;
3912 EMACS_SUB_TIME (difference, timer_delay, timeout); 3925 EMACS_SUB_TIME (difference, timer_delay, timeout);
3913 if (EMACS_TIME_NEG_P (difference)) 3926 if (EMACS_TIME_NEG_P (difference))
3921 /* Cause C-g and alarm signals to take immediate action, 3934 /* Cause C-g and alarm signals to take immediate action,
3922 and cause input available signals to zero out timeout. */ 3935 and cause input available signals to zero out timeout. */
3923 if (XINT (read_kbd) < 0) 3936 if (XINT (read_kbd) < 0)
3924 set_waiting_for_input (&timeout); 3937 set_waiting_for_input (&timeout);
3925 3938
3939 /* Wait till there is something to do. */
3940
3941 if (! XINT (read_kbd) && wait_for_cell == 0)
3942 FD_ZERO (&waitchannels);
3943 else
3944 FD_SET (0, &waitchannels);
3945
3926 /* If a frame has been newly mapped and needs updating, 3946 /* If a frame has been newly mapped and needs updating,
3927 reprocess its display stuff. */ 3947 reprocess its display stuff. */
3928 if (frame_garbaged && do_display) 3948 if (frame_garbaged && do_display)
3929 redisplay_preserve_echo_area (); 3949 {
3950 clear_waiting_for_input ();
3951 redisplay_preserve_echo_area ();
3952 if (XINT (read_kbd) < 0)
3953 set_waiting_for_input (&timeout);
3954 }
3930 3955
3931 { 3956 {
3932 int old_timers_run = timers_run; 3957 int old_timers_run = timers_run;
3933 if (XINT (read_kbd) && detect_input_pending_run_timers (do_display)) 3958 if (XINT (read_kbd) && detect_input_pending ())
3934 nfds = 0; 3959 {
3960 nfds = 0;
3961 FD_ZERO (&waitchannels);
3962 }
3935 else if (timers_run != old_timers_run) 3963 else if (timers_run != old_timers_run)
3936 ; 3964 ;
3937 else 3965 else
3938 nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0, 3966 nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0,
3939 &timeout); 3967 &timeout);
3970 kill (getpid (), SIGIO); 3998 kill (getpid (), SIGIO);
3971 #endif 3999 #endif
3972 4000
3973 /* Check for keyboard input */ 4001 /* Check for keyboard input */
3974 4002
3975 if (XINT (read_kbd) != 0 4003 if ((XINT (read_kbd) != 0 || wait_for_cell)
3976 && detect_input_pending_run_timers (do_display)) 4004 && detect_input_pending_run_timers (do_display))
3977 { 4005 {
3978 swallow_events (do_display); 4006 swallow_events (do_display);
3979 if (detect_input_pending_run_timers (do_display)) 4007 if (detect_input_pending_run_timers (do_display))
3980 break; 4008 break;
3981 } 4009 }
4010
4011 /* Exit now if the cell we're waiting for became non-nil. */
4012 if (wait_for_cell && ! NILP (*wait_for_cell))
4013 break;
3982 } 4014 }
3983 4015
3984 start_polling (); 4016 start_polling ();
3985 4017
3986 return 0; 4018 return 0;