Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add mtimer tick thread to update mono timer 10x in one second
  • Loading branch information
perexg committed Mar 5, 2016
1 parent 19eb890 commit 0425be7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/main.c
Expand Up @@ -177,6 +177,7 @@ static LIST_HEAD(, mtimer) mtimers;
static tvh_cond_t mtimer_cond;
static int64_t mtimer_periodic;
static pthread_t mtimer_tid;
static pthread_t mtimer_tick_tid;
static LIST_HEAD(, gtimer) gtimers;
static pthread_cond_t gtimer_cond;
static TAILQ_HEAD(, tasklet) tasklets;
Expand Down Expand Up @@ -527,6 +528,20 @@ mdispatch_clock_update(void)
return mdispatch_clock = mono;
}

/**
*
*/
static void *
mtimer_tick_thread(void *aux)
{
while (tvheadend_running) {
/* update clocks each 10x in one second */
mdispatch_clock = getmonoclock();
tvh_safe_usleep(100000);
}
return NULL;
}

/**
*
*/
Expand Down Expand Up @@ -1098,6 +1113,7 @@ main(int argc, char **argv)

epg_in_load = 1;

tvhthread_create(&mtimer_tick_tid, NULL, mtimer_tick_thread, NULL, "mtick");
tvhthread_create(&tasklet_tid, NULL, tasklet_thread, NULL, "tasklet");

dbus_server_init(opt_dbus, opt_dbus_session);
Expand Down Expand Up @@ -1254,6 +1270,9 @@ main(int argc, char **argv)
tvhtrace("main", "tasklet thread end");
tasklet_flush();
tvhtrace("main", "tasklet leave");
tvhtrace("main", "mtimer tick thread join enter");
pthread_join(tasklet_tid, NULL);
tvhtrace("main", "mtimer tick thread join leave");

tvhftrace("main", dvb_done);
tvhftrace("main", lang_str_done);
Expand Down
4 changes: 2 additions & 2 deletions src/tcp.c
Expand Up @@ -1112,9 +1112,9 @@ tcp_server_done(void)
tvh_pipe_close(&tcp_server_pipe);
tvhpoll_destroy(tcp_server_poll);

t = getfastmonoclock();
t = mdispatch_clock;
while (LIST_FIRST(&tcp_server_active) != NULL) {
if (t + sec2mono(5) < getfastmonoclock())
if (t + sec2mono(5) < mdispatch_clock)
tvhtrace("tcp", "tcp server %p active too long", LIST_FIRST(&tcp_server_active));
tvh_safe_usleep(20000);
}
Expand Down
4 changes: 2 additions & 2 deletions src/webui/webui.c
Expand Up @@ -396,8 +396,8 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,

if (hc->hc_no_output) {
streaming_msg_free(sm);
mono = getfastmonoclock() + sec2mono(2);
while (getfastmonoclock() < mono) {
mono = mdispatch_clock + sec2mono(2);
while (mdispatch_clock < mono) {
if (tcp_socket_dead(hc->hc_fd))
break;
tvh_safe_usleep(50000);
Expand Down

0 comments on commit 0425be7

Please sign in to comment.