diff options
author | Adam Jackson <ajax@redhat.com> | 2009-02-23 16:01:14 -0500 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2009-02-23 16:01:14 -0500 |
commit | 75af278861dcd96124544d3c2889028578708317 (patch) | |
tree | 0d4640c5ad80f0edec60e418fe498fa91cf1ceb6 | |
parent | 4fd9cd2ea81607c17eb39baaad24f09dd55995f2 (diff) |
Open with O_NONBLOCK, and simplify EvdevReadInput to match.
xf86WaitForInput() would call select() with zero timeout to discover if
more input was ready. But we know that's always true at least once,
since we're only ever called from the sigio handler (if silken is
active) or from the main loop (if it's not and we selected readable).
With nonblocking IO we can just spin around until we hit EAGAIN, which
gets us down to n+1 syscalls per event instead of 2n.
-rw-r--r-- | src/evdev.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/evdev.c b/src/evdev.c index 73291d7..887175b 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -295,7 +295,7 @@ EvdevReopenTimer(OsTimerPtr timer, CARD32 time, pointer arg) EvdevPtr pEvdev = pInfo->private; do { - pInfo->fd = open(pEvdev->device, O_RDWR, 0); + pInfo->fd = open(pEvdev->device, O_RDWR | O_NONBLOCK, 0); } while (pInfo->fd < 0 && errno == EINTR); if (pInfo->fd != -1) @@ -347,9 +347,12 @@ EvdevReadInput(InputInfoPtr pInfo) tmp = 0; abs = 0; - while (xf86WaitForInput (pInfo->fd, 0) > 0) { + while (1) { len = read(pInfo->fd, &ev, sizeof ev); if (len != sizeof ev) { + if (errno == EAGAIN) + break; + /* The kernel promises that we always only read a complete * event, so len != sizeof ev is an error. */ xf86Msg(X_ERROR, "%s: Read error: %s\n", pInfo->name, strerror(errno)); @@ -1531,7 +1534,7 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags) xf86Msg(X_CONFIG, "%s: Device: \"%s\"\n", pInfo->name, device); do { - pInfo->fd = open(device, O_RDWR, 0); + pInfo->fd = open(device, O_RDWR | O_NONBLOCK, 0); } while (pInfo->fd < 0 && errno == EINTR); if (pInfo->fd < 0) { |