1
0
mirror of https://github.com/ericonr/sndio.git synced 2024-02-18 04:45:21 -06:00

Don't call poll(2) with few millisecond time-out argument when -1

could be used. Avoids syscalls when the daemon is not being used.
This commit is contained in:
Alexandre Ratchov 2015-08-11 19:49:07 +02:00
parent 29516de2c3
commit 30c199e808

View File

@ -64,6 +64,7 @@
void timo_update(unsigned int); void timo_update(unsigned int);
void timo_init(void); void timo_init(void);
void timo_done(void); void timo_done(void);
void file_process(struct file *, struct pollfd *);
struct timespec file_ts; struct timespec file_ts;
struct file *file_list; struct file *file_list;
@ -316,7 +317,7 @@ file_poll(void)
int i; int i;
#endif #endif
long long delta_nsec; long long delta_nsec;
int nfds, res; int nfds, res, timo;
log_flush(); log_flush();
@ -380,14 +381,22 @@ file_poll(void)
} }
/* /*
* sleep * Sleep. Calculate the number off milliseconds poll(2) must
* wait before the timo_update() needs to be called. If there're
* no timeouts scheduled, then call poll(2) with -1 timeout.
*/ */
#ifdef DEBUG #ifdef DEBUG
clock_gettime(CLOCK_MONOTONIC, &sleepts); clock_gettime(CLOCK_MONOTONIC, &sleepts);
file_utime += 1000000000LL * (sleepts.tv_sec - file_ts.tv_sec); file_utime += 1000000000LL * (sleepts.tv_sec - file_ts.tv_sec);
file_utime += sleepts.tv_nsec - file_ts.tv_nsec; file_utime += sleepts.tv_nsec - file_ts.tv_nsec;
#endif #endif
res = poll(pfds, nfds, TIMER_MSEC); if (timo_queue != NULL) {
timo = ((int)timo_queue->val - (int)timo_abstime) / 1000;
if (timo < TIMER_MSEC)
timo = TIMER_MSEC;
} else
timo = -1;
res = poll(pfds, nfds, timo);
if (res < 0) { if (res < 0) {
if (errno != EINTR) if (errno != EINTR)
err(1, "poll"); err(1, "poll");