From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 2E293385780A; Wed, 15 Sep 2021 09:56:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E293385780A Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pipe: Do not call PeekNamedPipe() if it is not necessary. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 593a86f9b0262243510b2d9c97868a6b60f89c69 X-Git-Newrev: 00cbbaa33e7183a6b414cc0f36bc6cbf0b22d8ce Message-Id: <20210915095636.2E293385780A@sourceware.org> Date: Wed, 15 Sep 2021 09:56:36 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Sep 2021 09:56:36 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;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 select.cc, 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. Diff: --- winsup/cygwin/select.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index ac2f3a9e0..fd2312298 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -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) {