summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2011-04-22 09:01:58 +0300
committerUoti Urpala <uau@mplayer2.org>2011-04-22 09:34:03 +0300
commitd6072d740826dd112eaeccc09c3f3bf46a8ece26 (patch)
tree2e805a720f76838592a9962bb8c5e221aefb40c9
parentc2067cabafa272dc96d51a3969c024d09fb7a78d (diff)
downloadmpv-d6072d740826dd112eaeccc09c3f3bf46a8ece26.tar.bz2
mpv-d6072d740826dd112eaeccc09c3f3bf46a8ece26.tar.xz
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.
-rw-r--r--input/input.c33
1 files changed, 14 insertions, 19 deletions
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)