=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sndiod/file.c,v retrieving revision 1.11 retrieving revision 1.12 diff -c -r1.11 -r1.12 *** src/usr.bin/sndiod/file.c 2015/07/17 10:15:24 1.11 --- src/usr.bin/sndiod/file.c 2015/08/01 10:47:30 1.12 *************** *** 1,4 **** ! /* $OpenBSD: file.c,v 1.11 2015/07/17 10:15:24 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * --- 1,4 ---- ! /* $OpenBSD: file.c,v 1.12 2015/08/01 10:47:30 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * *************** *** 269,274 **** --- 269,310 ---- #endif } + void + file_process(struct file *f, struct pollfd *pfd) + { + int revents; + #ifdef DEBUG + struct timespec ts0, ts1; + long us; + #endif + + #ifdef DEBUG + if (log_level >= 3) + clock_gettime(CLOCK_MONOTONIC, &ts0); + #endif + revents = (f->state != FILE_ZOMB) ? + f->ops->revents(f->arg, pfd) : 0; + if ((revents & POLLHUP) && (f->state != FILE_ZOMB)) + f->ops->hup(f->arg); + if ((revents & POLLIN) && (f->state != FILE_ZOMB)) + f->ops->in(f->arg); + if ((revents & POLLOUT) && (f->state != FILE_ZOMB)) + f->ops->out(f->arg); + #ifdef DEBUG + if (log_level >= 3) { + clock_gettime(CLOCK_MONOTONIC, &ts1); + us = 1000000L * (ts1.tv_sec - ts0.tv_sec); + us += (ts1.tv_nsec - ts0.tv_nsec) / 1000; + if (log_level >= 4 || us >= 5000) { + file_log(f); + log_puts(": processed in "); + log_putu(us); + log_puts("us\n"); + } + } + #endif + } + int file_poll(void) { *************** *** 277,289 **** struct timespec ts; #ifdef DEBUG struct timespec sleepts; - struct timespec ts0, ts1; - long us; int i; #endif long long delta_nsec; ! int nfds, revents, res, immed; /* * cleanup zombies */ --- 313,325 ---- struct timespec ts; #ifdef DEBUG struct timespec sleepts; int i; #endif long long delta_nsec; ! int nfds, res; + log_flush(); + /* * cleanup zombies */ *************** *** 304,320 **** return 0; } ! log_flush(); nfds = 0; - immed = 0; for (f = file_list; f != NULL; f = f->next) { f->nfds = f->ops->pollfd(f->arg, pfds + nfds); if (f->nfds == 0) continue; - if (f->nfds < 0) { - immed = 1; - continue; - } nfds += f->nfds; } #ifdef DEBUG --- 340,353 ---- return 0; } ! /* ! * fill pollfd structures ! */ nfds = 0; for (f = file_list; f != NULL; f = f->next) { f->nfds = f->ops->pollfd(f->arg, pfds + nfds); if (f->nfds == 0) continue; nfds += f->nfds; } #ifdef DEBUG *************** *** 322,328 **** log_puts("poll:"); pfd = pfds; for (f = file_list; f != NULL; f = f->next) { ! if (f->nfds <= 0) continue; log_puts(" "); log_puts(f->ops->name); --- 355,361 ---- log_puts("poll:"); pfd = pfds; for (f = file_list; f != NULL; f = f->next) { ! if (f->nfds == 0) continue; log_puts(" "); log_puts(f->ops->name); *************** *** 335,350 **** } log_puts("\n"); } clock_gettime(CLOCK_MONOTONIC, &sleepts); file_utime += 1000000000LL * (sleepts.tv_sec - file_ts.tv_sec); file_utime += sleepts.tv_nsec - file_ts.tv_nsec; #endif ! if (!immed) { ! res = poll(pfds, nfds, TIMER_MSEC); ! if (res < 0 && errno != EINTR) err(1, "poll"); ! } else ! res = 0; clock_gettime(CLOCK_MONOTONIC, &ts); #ifdef DEBUG file_wtime += 1000000000LL * (ts.tv_sec - sleepts.tv_sec); --- 368,402 ---- } log_puts("\n"); } + #endif + + /* + * process files that do not rely on poll + */ + for (f = file_list; f != NULL; f = f->next) { + if (f->nfds > 0) + continue; + file_process(f, NULL); + } + + /* + * sleep + */ + #ifdef DEBUG clock_gettime(CLOCK_MONOTONIC, &sleepts); file_utime += 1000000000LL * (sleepts.tv_sec - file_ts.tv_sec); file_utime += sleepts.tv_nsec - file_ts.tv_nsec; #endif ! res = poll(pfds, nfds, TIMER_MSEC); ! if (res < 0) { ! if (errno != EINTR) err(1, "poll"); ! return 1; ! } ! ! /* ! * run timeouts ! */ clock_gettime(CLOCK_MONOTONIC, &ts); #ifdef DEBUG file_wtime += 1000000000LL * (ts.tv_sec - sleepts.tv_sec); *************** *** 363,399 **** if (log_level >= 2) log_puts("ignored huge clock delta\n"); } ! if (!immed && res <= 0) ! return 1; pfd = pfds; for (f = file_list; f != NULL; f = f->next) { ! if (f->nfds <= 0) continue; ! #ifdef DEBUG ! if (log_level >= 3) ! clock_gettime(CLOCK_MONOTONIC, &ts0); ! #endif ! revents = (f->state != FILE_ZOMB) ? ! f->ops->revents(f->arg, pfd) : 0; ! if ((revents & POLLHUP) && (f->state != FILE_ZOMB)) ! f->ops->hup(f->arg); ! if ((revents & POLLIN) && (f->state != FILE_ZOMB)) ! f->ops->in(f->arg); ! if ((revents & POLLOUT) && (f->state != FILE_ZOMB)) ! f->ops->out(f->arg); ! #ifdef DEBUG ! if (log_level >= 3) { ! clock_gettime(CLOCK_MONOTONIC, &ts1); ! us = 1000000L * (ts1.tv_sec - ts0.tv_sec); ! us += (ts1.tv_nsec - ts0.tv_nsec) / 1000; ! if (log_level >= 4 || us >= 5000) { ! file_log(f); ! log_puts(": processed in "); ! log_putu(us); ! log_puts("us\n"); ! } ! } ! #endif pfd += f->nfds; } return 1; --- 415,429 ---- if (log_level >= 2) log_puts("ignored huge clock delta\n"); } ! ! /* ! * process files that rely on poll ! */ pfd = pfds; for (f = file_list; f != NULL; f = f->next) { ! if (f->nfds == 0) continue; ! file_process(f, pfd); pfd += f->nfds; } return 1;