Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mpegts input: start input threads later when all structure members ar…
…e initialized

- for example iptv input initialized mi_display_name later and
  the input thread might call the the generic function
- discovered by 'valgrind --tool=helgrind'
  • Loading branch information
perexg committed Mar 8, 2016
1 parent 149d5b3 commit e522525
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/input/mpegts.h
Expand Up @@ -677,6 +677,7 @@ struct mpegts_input
/* Data input */
// Note: this section is protected by mi_input_lock
pthread_t mi_input_tid;
mtimer_t mi_input_thread_start;
pthread_mutex_t mi_input_lock;
tvh_cond_t mi_input_cond;
TAILQ_HEAD(,mpegts_packet) mi_input_queue;
Expand Down
18 changes: 12 additions & 6 deletions src/input/mpegts/mpegts_input.c
Expand Up @@ -1681,8 +1681,9 @@ mpegts_input_clear_stats ( tvh_input_t *i )
}

static void
mpegts_input_thread_start ( mpegts_input_t *mi )
mpegts_input_thread_start ( void *aux )
{
mpegts_input_t *mi = aux;
mi->mi_running = 1;

tvhthread_create(&mi->mi_table_tid, NULL,
Expand All @@ -1694,7 +1695,10 @@ mpegts_input_thread_start ( mpegts_input_t *mi )
static void
mpegts_input_thread_stop ( mpegts_input_t *mi )
{
int running = mi->mi_running;

mi->mi_running = 0;
mtimer_disarm(&mi->mi_input_thread_start);

/* Stop input thread */
pthread_mutex_lock(&mi->mi_input_lock);
Expand All @@ -1707,10 +1711,12 @@ mpegts_input_thread_stop ( mpegts_input_t *mi )
pthread_mutex_unlock(&mi->mi_output_lock);

/* Join threads (relinquish lock due to potential deadlock) */
pthread_mutex_unlock(&global_lock);
pthread_join(mi->mi_input_tid, NULL);
pthread_join(mi->mi_table_tid, NULL);
pthread_mutex_lock(&global_lock);
if (running) {
pthread_mutex_unlock(&global_lock);
pthread_join(mi->mi_input_tid, NULL);
pthread_join(mi->mi_table_tid, NULL);
pthread_mutex_lock(&global_lock);
}
}

/* **************************************************************************
Expand Down Expand Up @@ -1806,7 +1812,7 @@ mpegts_input_create0
idnode_load(&mi->ti_id, c);

/* Start threads */
mpegts_input_thread_start(mi);
mtimer_arm_rel(&mi->mi_input_thread_start, mpegts_input_thread_start, mi, NULL);

return mi;
}
Expand Down

0 comments on commit e522525

Please sign in to comment.