]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: pty: Make slave read() thread-safe.
authorTakashi Yano via Cygwin-patches <cygwin-patches@cygwin.com>
Thu, 28 Jan 2021 14:11:33 +0000 (23:11 +0900)
committerCorinna Vinschen <corinna@vinschen.de>
Mon, 1 Feb 2021 09:54:04 +0000 (10:54 +0100)
- Currently slave read() is somehow not thread-safe. This patch
  fixes the issue.

winsup/cygwin/fhandler_tty.cc

index 06fc19ac2e283e3cb9b087db7916128094009d96..48b89ae77a5b0f38e4369da40a62997c961790b4 100644 (file)
@@ -1241,6 +1241,7 @@ fhandler_pty_slave::read (void *ptr, size_t& len)
        time_to_wait = !vtime ? INFINITE : 100 * vtime;
     }
 
+wait_retry:
   while (len)
     {
       switch (cygwait (input_available_event, time_to_wait))
@@ -1319,6 +1320,11 @@ fhandler_pty_slave::read (void *ptr, size_t& len)
            }
          goto out;
        }
+      if (!IsEventSignalled (input_available_event))
+       { /* Maybe another thread has processed input. */
+         ReleaseMutex (input_mutex);
+         goto wait_retry;
+       }
 
       if (!bytes_available (bytes_in_pipe))
        {
This page took 0.030966 seconds and 5 git commands to generate.