]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid busy-waiting for child processes on Windows. (Bug#13086)
authorEli Zaretskii <eliz@gnu.org>
Thu, 6 Dec 2012 18:36:22 +0000 (20:36 +0200)
committerEli Zaretskii <eliz@gnu.org>
Thu, 6 Dec 2012 18:36:22 +0000 (20:36 +0200)
 src/w32proc.c (waitpid): Avoid busy-waiting when called with WNOHANG
 if the child process is still running.  Instead, exit the wait
 loop and return zero.

src/ChangeLog
src/w32proc.c

index 2fefef1275bda8eedbd188a2ca7fda09ba81f541..2a138bfcf655c6c11186b72f6837fe5415686072 100644 (file)
@@ -1,3 +1,9 @@
+2012-12-06  Eli Zaretskii  <eliz@gnu.org>
+
+       * w32proc.c (waitpid): Avoid busy-waiting when called with WNOHANG
+       if the child process is still running.  Instead, exit the wait
+       loop and return zero.  (Bug#13086)
+
 2012-12-06  Dmitry Antipov  <dmantipov@yandex.ru>
 
        * frame.h (x_char_width, x_char_height): Remove prototypes.
index 87af8682390949b3cb9fc5222fc31202f2f5e796..0b36804b0e82b0bf0a160f6715024ce4e51ecf1c 100644 (file)
@@ -1220,13 +1220,22 @@ waitpid (pid_t pid, int *status, int options)
     {
       QUIT;
       active = WaitForMultipleObjects (nh, wait_hnd, FALSE, timeout_ms);
-    } while (active == WAIT_TIMEOUT);
+    } while (active == WAIT_TIMEOUT && !dont_wait);
 
   if (active == WAIT_FAILED)
     {
       errno = EBADF;
       return -1;
     }
+  else if (active == WAIT_TIMEOUT && dont_wait)
+    {
+      /* PID specifies our subprocess, but it didn't exit yet, so its
+        status is not yet available.  */
+#ifdef FULL_DEBUG
+      DebPrint (("Wait: PID %d not reap yet\n", cp->pid));
+#endif
+      return 0;
+    }
   else if (active >= WAIT_OBJECT_0
           && active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS)
     {