Remove unnecessary 1ms wakeups while USB transfers are in progress
--- linux.c.orig 2007-12-02 16:02:27.000000000 -0800
+++ linux.c 2007-12-02 16:33:12.000000000 -0800
@@ -14,6 +14,7 @@
#include <errno.h>
#include <sys/time.h>
#include <dirent.h>
+#include <poll.h>
#include "linux.h"
#include "usbi.h"
@@ -164,7 +165,7 @@
{
struct usb_urb urb;
int bytesdone = 0, requested;
- struct timeval tv, tv_ref, tv_now;
+ struct timeval tv_ref, tv_now;
struct usb_urb *context;
int ret, waiting;
@@ -191,8 +192,6 @@
}
do {
- fd_set writefds;
-
requested = size - bytesdone;
if (requested > MAX_READ_WRITE)
requested = MAX_READ_WRITE;
@@ -213,25 +212,25 @@
return ret;
}
- FD_ZERO(&writefds);
- FD_SET(dev->fd, &writefds);
-
restart:
waiting = 1;
context = NULL;
while (!urb.usercontext && ((ret = ioctl(dev->fd, IOCTL_USB_REAPURBNDELAY, &context)) == -1) && waiting) {
- tv.tv_sec = 0;
- tv.tv_usec = 1000; // 1 msec
- select(dev->fd + 1, NULL, &writefds, NULL, &tv); //sub second wait
+ struct pollfd pollfd;
+ int poll_timeout = -1;
+
+ pollfd.fd = dev->fd;
+ pollfd.events = POLLOUT;
+ pollfd.revents = 0;
if (timeout) {
- /* compare with actual time, as the select timeout is not that precise */
gettimeofday(&tv_now, NULL);
-
- if ((tv_now.tv_sec > tv_ref.tv_sec) ||
- ((tv_now.tv_sec == tv_ref.tv_sec) && (tv_now.tv_usec >= tv_ref.tv_usec)))
- waiting = 0;
+ poll_timeout = (tv_ref.tv_sec-tv_now.tv_sec)*1000 +
+ (tv_ref.tv_usec-tv_now.tv_usec)/1000;
}
+
+ if ((ret = poll(&pollfd, 1, poll_timeout)) != 1)
+ waiting = 0;
}
if (context && context != &urb) {