Patch: Use threadWaitRead to avoid blocking in nextEvent in the main loop

Hi,
I've been playing around with Control.Concurrent lately, and ran into a
problem with xmonad as it stands: it usually blocks inside XNextEvent()
in the main loop, so the Haskell runtime system never gets a chance to
run any other lightweight threads.
The attached patch uses threadWaitRead to tell the runtime system to
wait for the X file descriptor to become ready before calling
XNextEvent. This works for me: I've now got a couple of forkIO threads
happily updating my status bar periodically.
I'm not entirely convinced it's correct, though. Is it possible for the
X server to send more than one event in a single communication? If so,
it would be necessary to call nextEvent to handle the subsequent events
before the file descriptor becomes ready again (which'd be easy if
there's a way to find out whether there are any events pending without
blocking).
Thanks,
--
Adam Sampson

On 2008 Jun 21, at 20:47, Adam Sampson wrote:
I'm not entirely convinced it's correct, though. Is it possible for the X server to send more than one event in a single communication? If so, it would be necessary to call nextEvent to handle the subsequent events before the file descriptor becomes ready again (which'd be easy if there's a way to find out whether there are any events pending without blocking).
It is possible, and there are several ways to check (QLength(), XCheckIfEvent(), XPending(), XEventsQueued()) --- we probably want either XPending() or XEventsQueued(QueueAfterFlush) (same thing, different APIs). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

On Sun, Jun 22, 2008 at 10:37:10AM -0400, Brandon S. Allbery KF8NH wrote:
It is possible, and there are several ways to check
OK -- here's a version that uses XPending.
Thanks,
--
Adam Sampson
participants (2)
-
Adam Sampson
-
Brandon S. Allbery KF8NH