1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-21 18:57:35 +00:00

input: sleep in event loop even if there are no input fds

The input loop select() call was only run if there was at least one
input file descriptor. However other code uses the input loop to wait;
this could result in the wait becoming a busy loop when running with
-noconsolecontrols (without that there is at least one input fd for
terminal input). Make the input loop call select() to sleep even if
there are no input file descriptors.
This commit is contained in:
Uoti Urpala 2011-04-22 09:01:58 +03:00
parent c2067cabaf
commit d6072d7408

View File

@ -1238,14 +1238,13 @@ static mp_cmd_t *read_events(struct input_ctx *ictx, int time)
fd_set fds;
FD_ZERO(&fds);
if (!got_cmd) {
int max_fd = 0, num_fd = 0;
int max_fd = 0;
for (i = 0; i < ictx->num_key_fd; i++) {
if (key_fds[i].no_select)
continue;
if (key_fds[i].fd > max_fd)
max_fd = key_fds[i].fd;
FD_SET(key_fds[i].fd, &fds);
num_fd++;
}
for (i = 0; i < ictx->num_cmd_fd; i++) {
if (cmd_fds[i].no_select)
@ -1253,24 +1252,20 @@ static mp_cmd_t *read_events(struct input_ctx *ictx, int time)
if (cmd_fds[i].fd > max_fd)
max_fd = cmd_fds[i].fd;
FD_SET(cmd_fds[i].fd, &fds);
num_fd++;
}
if (num_fd > 0) {
struct timeval tv, *time_val;
if (time >= 0) {
tv.tv_sec = time / 1000;
tv.tv_usec = (time % 1000) * 1000;
time_val = &tv;
}
else
time_val = NULL;
if (select(max_fd + 1, &fds, NULL, NULL, time_val) < 0) {
if (errno != EINTR)
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Select error: %s\n",
strerror(errno));
FD_ZERO(&fds);
}
}
struct timeval tv, *time_val;
if (time >= 0) {
tv.tv_sec = time / 1000;
tv.tv_usec = (time % 1000) * 1000;
time_val = &tv;
} else
time_val = NULL;
if (select(max_fd + 1, &fds, NULL, NULL, time_val) < 0) {
if (errno != EINTR)
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Select error: %s\n",
strerror(errno));
FD_ZERO(&fds);
}
}
#else
if (!got_cmd && time)