summaryrefslogtreecommitdiff
path: root/usr.bin/aucat
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2011-06-02 19:03:59 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2011-06-02 19:03:59 +0000
commit3e573a9cb78b3c6db0b904ef36be01998f19e818 (patch)
tree82e58e1dd823c4dfd780e6153aea8c87243248d7 /usr.bin/aucat
parenta1ffda8d647e28b75e44b0fe269118da18cc628c (diff)
If there are no descriptors to poll, just sleep until SIGALRM
is posted and then update all timers and restart the event loop. Fixes throtteling while midi inputs are drained.
Diffstat (limited to 'usr.bin/aucat')
-rw-r--r--usr.bin/aucat/file.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/usr.bin/aucat/file.c b/usr.bin/aucat/file.c
index 6e68deaa5c3..fd76508628f 100644
--- a/usr.bin/aucat/file.c
+++ b/usr.bin/aucat/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.25 2011/06/02 16:58:02 ratchov Exp $ */
+/* $OpenBSD: file.c,v 1.26 2011/06/02 19:03:58 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -24,10 +24,10 @@
* the module also provides trivial timeout implementation,
* derived from:
*
- * anoncvs@moule.caoua.org:/cvs
+ * anoncvs@moule.caoua.org:/midish
*
- * midish/timo.c rev 1.16
- * midish/mdep.c rev 1.69
+ * midish/timo.c rev 1.18
+ * midish/mdep.c rev 1.71
*
* A timeout is used to schedule the call of a routine (the callback)
* there is a global list of timeouts that is processed inside the
@@ -297,7 +297,8 @@ file_poll(void)
struct file *f, *fnext;
struct aproc *p;
struct timespec ts;
- long delta_nsec;
+ long long delta_nsec;
+ int res;
if (LIST_EMPTY(&file_list) && timo_queue == NULL) {
#ifdef DEBUG
@@ -346,20 +347,25 @@ file_poll(void)
dbg_puts("\n");
}
#endif
- if (nfds > 0) {
- if (poll(pfds, nfds, -1) < 0) {
- if (errno == EINTR)
- return 1;
- err(1, "file_poll: poll failed");
- }
- clock_gettime(CLOCK_MONOTONIC, &ts);
- delta_nsec = 1000000000L * (ts.tv_sec - file_ts.tv_sec);
- delta_nsec += ts.tv_nsec - file_ts.tv_nsec;
- if (delta_nsec > 0) {
- file_ts = ts;
+ res = poll(pfds, nfds, -1);
+ if (res < 0 && errno != EINTR)
+ err(1, "poll");
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ delta_nsec = 1000000000LL * (ts.tv_sec - file_ts.tv_sec);
+ delta_nsec += ts.tv_nsec - file_ts.tv_nsec;
+ if (delta_nsec > 0) {
+ file_ts = ts;
+ if (delta_nsec < 1000000000LL)
timo_update(delta_nsec / 1000);
+ else {
+#ifdef DEBUG
+ dbg_puts("ignored huge clock delta\n");
+#endif
}
}
+ if (res <= 0)
+ return 1;
+
f = LIST_FIRST(&file_list);
while (f != NULL) {
if (f->pfd == NULL) {