public inbox for
help / color / mirror / Atom feed
From: Corinna Vinschen <>
Subject: [newlib-cygwin] Cygwin: pipe: Do not call PeekNamedPipe() if it is not necessary.
Date: Wed, 15 Sep 2021 09:56:36 +0000 (GMT)	[thread overview]
Message-ID: <> (raw);h=00cbbaa33e7183a6b414cc0f36bc6cbf0b22d8ce

commit 00cbbaa33e7183a6b414cc0f36bc6cbf0b22d8ce
Author: Takashi Yano <>
Date:   Wed Sep 15 09:55:57 2021 +0900

    Cygwin: pipe: Do not call PeekNamedPipe() if it is not necessary.
    - In pipe_data_available() in, PeekNamedPipe() call is
      not needed if WriteQuotaAvailable is non-zero because we already
      know the write pipe has a space. Therefore, with this patch,
      PeekNamedPipe() is called only when WriteQuotaAvailable is zero.
      This makes select() on pipe faster a bit.

 winsup/cygwin/ | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/winsup/cygwin/ b/winsup/cygwin/
index ac2f3a9e0..fd2312298 100644
--- a/winsup/cygwin/
+++ b/winsup/cygwin/
@@ -633,17 +633,15 @@ pipe_data_available (int fd, fhandler_base *fh, HANDLE h, bool writing)
       /* Note: Do not use NtQueryInformationFile() for query_hdl because
 	 NtQueryInformationFile() seems to interfere with reading pipes
 	 in non-cygwin apps. Instead, use PeekNamedPipe() here. */
-      if (fh->get_device () == FH_PIPEW)
+      if (fh->get_device () == FH_PIPEW && fpli.WriteQuotaAvailable == 0)
 	  HANDLE query_hdl = ((fhandler_pipe *) fh)->get_query_handle ();
-	  if (query_hdl)
-	    {
-	      DWORD nbytes_in_pipe;
-	      PeekNamedPipe (query_hdl, NULL, 0, NULL, &nbytes_in_pipe, NULL);
-	      fpli.WriteQuotaAvailable = fpli.InboundQuota - nbytes_in_pipe;
-	    }
-	  else
+	  if (!query_hdl)
+	    return 1; /* We cannot know actual write pipe space. */
+	  DWORD nbytes_in_pipe;
+	  if (!PeekNamedPipe (query_hdl, NULL, 0, NULL, &nbytes_in_pipe, NULL))
 	    return 1;
+	  fpli.WriteQuotaAvailable = fpli.InboundQuota - nbytes_in_pipe;
       if (fpli.WriteQuotaAvailable > 0)

                 reply	other threads:[~2021-09-15  9:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).