Skip to content

Commit

Permalink
Use 1 select() call and let it block
Browse files Browse the repository at this point in the history
vusb-daemon spends a lot of time looping since it has two separate
select calls with short timeouts.  Unify the two select calls and let it
block to avoid needless CPU usage.

xcdbus_pre_select is written to add to in-use fd_sets and nfds, so use
that feature.  xcdbus_post_select will loop over its registered watches
checking for if the corresponding FD is set, so an extra FD in readfds
is fine.  udevfd can then be checked for events as is done currently.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
  • Loading branch information
jandryuk committed Oct 23, 2018
1 parent c269a8c commit d016da7
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ static void fill_vms()
int
main() {
int ret;
struct timeval tv;
fd_set readfds;
fd_set writefds;
fd_set exceptfds;
Expand Down Expand Up @@ -125,18 +124,13 @@ main() {
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
tv.tv_sec = 0;
tv.tv_usec = 1000;
nfds = xcdbus_pre_select(g_xcbus, 0, &readfds, &writefds, &exceptfds);
select(nfds, &readfds, &writefds, &exceptfds, &tv);
xcdbus_post_select(g_xcbus, 0, &readfds, &writefds, &exceptfds);

/* Check udev */
FD_ZERO(&readfds);
FD_SET(udevfd, &readfds);
tv.tv_sec = 0;
tv.tv_usec = 1000;
ret = select(udevfd + 1, &readfds, NULL, NULL, &tv);
nfds = udevfd + 1;

nfds = xcdbus_pre_select(g_xcbus, nfds, &readfds, &writefds, &exceptfds);
ret = select(nfds, &readfds, &writefds, &exceptfds, NULL);
xcdbus_post_select(g_xcbus, nfds, &readfds, &writefds, &exceptfds);
if (ret > 0 && FD_ISSET(udevfd, &readfds))
udev_event();
}
Expand Down

0 comments on commit d016da7

Please sign in to comment.