]> git.eshelyaron.com Git - emacs.git/commitdiff
[!subprocesses] (wait_reading_process_input):
authorRichard M. Stallman <rms@gnu.org>
Sun, 10 Mar 1996 14:38:37 +0000 (14:38 +0000)
committerRichard M. Stallman <rms@gnu.org>
Sun, 10 Mar 1996 14:38:37 +0000 (14:38 +0000)
Port the timer changes from the other wait_reading_process_input.

src/process.c

index 1ff26c83259faf07d07fe0c3d891a8b29dab1567..9d4e3aa2db62d53475ef6c07e3d1b8e287391b99 100644 (file)
@@ -3853,6 +3853,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
   for (;;)
     {
       int nfds;
+      int timeout_reduced_for_timers = 0;
 
       if (XINT (read_kbd))
        FD_SET (0, &waitchannels);
@@ -3865,6 +3866,8 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
       if (XINT (read_kbd) >= 0)
        QUIT;
 
+      /* Compute time from now till when time limit is up */
+      /* Exit if already run out */
       if (timeout_p)
        {
          EMACS_GET_TIME (*timeout_p);
@@ -3873,6 +3876,29 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
            break;
        }
 
+      /* If our caller will not immediately handle keyboard events,
+        run timer events directly.
+        (Callers that will immediately read keyboard events
+        call timer_delay on their own.)  */
+      if (read_kbd >= 0)
+       {
+         EMACS_TIME timer_delay;
+         int old_timers_run = timers_run;
+         timer_delay = timer_check (1);
+         if (timers_run != old_timers_run && do_display)
+           redisplay_preserve_echo_area ();
+         if (! EMACS_TIME_NEG_P (timer_delay) && timeout_p)
+           {
+             EMACS_TIME difference;
+             EMACS_SUB_TIME (difference, timer_delay, *timeout_p);
+             if (EMACS_TIME_NEG_P (difference))
+               {
+                 *timeout_p = timer_delay;
+                 timeout_reduced_for_timers = 1;
+               }
+           }
+       }
+
       /* Cause C-g and alarm signals to take immediate action,
         and cause input available signals to zero out timeout.  */
       if (XINT (read_kbd) < 0)
@@ -3883,9 +3909,23 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
       if (frame_garbaged && do_display)
        redisplay_preserve_echo_area ();
 
-      if (XINT (read_kbd) && detect_input_pending ())
-       nfds = 0;
-      else
+      nfds = 1;
+      if (XINT (read_kbd) < 0 && detect_input_pending ())
+       {
+         swallow_events (do_display);
+         if (detect_input_pending ())
+           nfds = 0;
+       }
+
+      if ((XINT (read_kbd) > 0) 
+         && detect_input_pending_run_timers (do_display))
+       {
+         swallow_events (do_display);
+         if (detect_input_pending_run_timers (do_display))
+           nfds = 0;
+       }
+
+      if (nfds)
        nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0,
                       timeout_p);
 
@@ -3914,7 +3954,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
 
       /* If we have timed out (nfds == 0) or found some input (nfds > 0),
         we should exit.  */
-      if (nfds >= 0)
+      if (nfds >= 0 && ! timeout_reduced_for_timers)
        break;
     }