From: Jaroslav Kysela Date: Thu, 1 Oct 2015 09:33:00 +0000 (+0200) Subject: fix tvh_write() endless loop X-Git-Tag: v4.2.1~2015 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfe6bd5e40bd4d4993c83fcdad1b1afe2a12eccf;p=thirdparty%2Ftvheadend.git fix tvh_write() endless loop --- diff --git a/src/main.c b/src/main.c index 5ef84bf2d..c47f78229 100644 --- a/src/main.c +++ b/src/main.c @@ -483,7 +483,23 @@ show_usage exit(0); } - +/** + * + */ +void +dispatch_clock_update(struct timespec *ts) +{ + struct timespec ts1; + if (ts == NULL) + ts = &ts1; + clock_gettime(CLOCK_REALTIME, ts); + + /* 1sec stuff */ + if (ts->tv_sec > dispatch_clock) { + dispatch_clock = ts->tv_sec; + comet_flush(); /* Flush idle comet mailboxes */ + } +} /** * @@ -501,14 +517,7 @@ mainloop(void) #endif while(tvheadend_running) { - clock_gettime(CLOCK_REALTIME, &ts); - - /* 1sec stuff */ - if (ts.tv_sec > dispatch_clock) { - dispatch_clock = ts.tv_sec; - - comet_flush(); /* Flush idle comet mailboxes */ - } + dispatch_clock_update(&ts); /* Global timers */ pthread_mutex_lock(&global_lock); diff --git a/src/tvhlog.h b/src/tvhlog.h index 2b789d828..4a4e958d3 100644 --- a/src/tvhlog.h +++ b/src/tvhlog.h @@ -27,6 +27,7 @@ #endif #include #include +#include #include "atomic.h" #include "htsmsg.h" @@ -128,4 +129,6 @@ static inline void tvhtrace_no_warnings(const char *fmt, ...) { (void)fmt; } #define tvhnotice(...) tvhlog(LOG_NOTICE, ##__VA_ARGS__) #define tvherror(...) tvhlog(LOG_ERR, ##__VA_ARGS__) +void dispatch_clock_update(struct timespec *ts); + #endif /* __TVH_LOGGING_H__ */ diff --git a/src/wrappers.c b/src/wrappers.c index 2d472f768..f464e7c43 100644 --- a/src/wrappers.c +++ b/src/wrappers.c @@ -109,6 +109,7 @@ tvh_write(int fd, const void *buf, size_t len) if (dispatch_clock > next) break; usleep(100); + dispatch_clock_update(NULL); continue; } break;