mirror of
https://github.com/X11Libre/xf86-input-evdev.git
synced 2026-03-24 09:44:28 +00:00
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.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user