delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/08/29/10:17:32

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Sun, 29 Aug 2010 16:17:16 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com, cygwin-xfree AT cygwin DOT com
Subject: Re: /dev/windows and select() [was Re: Slow response to keypresses in xorg-server-1.8.0-1]
Message-ID: <20100829141716.GG6726@calimero.vinschen.de>
Mail-Followup-To: cygwin AT cygwin DOT com, cygwin-xfree AT cygwin DOT com
References: <4BDC3161 DOT 9070101 AT cornell DOT edu> <4BDDE5F1 DOT 9080204 AT cornell DOT edu> <4C2B8171 DOT 5020409 AT dronecode DOT org DOT uk> <4C5B08AE DOT 4080902 AT pobox DOT com> <AANLkTin9mOFFkk21dYf+CT2uMXr=x5bnaNsTkH0w0cka AT mail DOT gmail DOT com> <4C5DD910 DOT 9050809 AT dronecode DOT org DOT uk> <AANLkTin6e74L1_Z7KzoOVmynQ+eW6a8tkTK_A21-mpg+@mail.gmail.com> <4C7A62FD DOT 10506 AT dronecode DOT org DOT uk>
MIME-Version: 1.0
In-Reply-To: <4C7A62FD.10506@dronecode.org.uk>
User-Agent: Mutt/1.5.20 (2009-06-14)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Aug 29 14:39, Jon TURNEY wrote:
> On 08/08/2010 12:04, Andy Koppe wrote:
> >On 7 August 2010 23:07, Jon TURNEY wrote:
> >>Hmmm, looking again at the implementation of select(), I don't immediately
> >>see that when waiting on /dev/windows, it checks that the message queue has
> >>old messages on it before waiting.  The MSDN documentation for
> >>MsgWaitForMultipleObjects() seems to says that messages which had arrived
> >>before the last PeekMessage() etc. aren't considered new and so don't end
> >>the wait?
> >
> >I think you're right, a call to PeekMessage is needed for proper
> >select() semantics: it shouldn't block if data is available for
> >reading.
> 
> Attached is a small test-case which seems to demonstrate this problem.
> 
> Run ./dev-windows-select-test and observe select() blocks for the
> full timeout, despite the fact that the /dev/windows fd is ready for
> reading (and it reported as such as the end of the timeout)
> 
> If you run './dev-windows-select-test -skip' to skip the
> PeekMessage(), select() returns immediately, indicating the
> /dev/windows fd is ready for reading.
> [...]

Thanks for the testcase.  I examined this and I think I have a
workaround.  MSDN states that there's a flag QS_ALLPOSTMESSAGE for
MsgWaitForMultipleObjects, which is not cleared by PeekMessage, if the
wMsgFilterMin and wMsgFilterMax arguments are not both 0.  So, what I
did was to add the QS_ALLPOSTMESSAGE flag to the
MsgWaitForMultipleObjects call in select.cc, and to change the
PeekMessage call in select.cc:peek_windows() from

  PeekMessage (&m, (HWND) h, 0, 0, PM_NOREMOVE)

to

  PeekMessage (&m, (HWND) h, 1, UINT_MAX, PM_NOREMOVE)

Same in your above test application.  This appears to do the trick.
However, I'm not exactly sure if that's a valid fix.  Patch below.


Corinna


Index: select.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/select.cc,v
retrieving revision 1.160
diff -u -p -r1.160 select.cc
--- select.cc	2 Apr 2010 22:36:44 -0000	1.160
+++ select.cc	29 Aug 2010 14:16:18 -0000
@@ -287,7 +287,8 @@ select_stuff::wait (fd_set *readfds, fd_
       if (!windows_used)
 	wait_ret = WaitForMultipleObjects (m, w4, FALSE, ms);
       else
-	wait_ret = MsgWaitForMultipleObjects (m, w4, FALSE, ms, QS_ALLINPUT);
+	wait_ret = MsgWaitForMultipleObjects (m, w4, FALSE, ms,
+					      QS_ALLINPUT | QS_ALLPOSTMESSAGE);
 
       switch (wait_ret)
       {
@@ -1531,7 +1532,7 @@ peek_windows (select_record *me, bool)
   if (me->read_selected && me->read_ready)
     return 1;
 
-  if (PeekMessage (&m, (HWND) h, 0, 0, PM_NOREMOVE))
+  if (PeekMessage (&m, (HWND) h, 1, UINT_MAX, PM_NOREMOVE))
     {
       me->read_ready = true;
       select_printf ("window %d(%p) ready", me->fd, me->fh->get_handle ());


-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019