From d6072d740826dd112eaeccc09c3f3bf46a8ece26 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Fri, 22 Apr 2011 09:01:58 +0300 Subject: 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. --- input/input.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'input') diff --git a/input/input.c b/input/input.c index f201160e05..aeefec25f1 100644 --- a/input/input.c +++ b/input/input.c @@ -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) -- cgit v1.2.3