Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mpegts tables: reorganize destroy / mt_subscribed code
  • Loading branch information
perexg committed Nov 8, 2014
1 parent e2df5d2 commit 0b2e072
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
5 changes: 4 additions & 1 deletion src/input/mpegts.h
Expand Up @@ -802,7 +802,10 @@ static inline void mpegts_table_release
(mpegts_table_t *mt)
{
assert(mt->mt_refcount > 0);
if(--mt->mt_refcount == 0) mpegts_table_release_(mt);
if(--mt->mt_refcount == 0) {
assert(mt->mt_destroyed == 1);
mpegts_table_release_(mt);
}
}
int mpegts_table_type
( mpegts_table_t *mt );
Expand Down
30 changes: 15 additions & 15 deletions src/input/mpegts/mpegts_mux.c
Expand Up @@ -770,16 +770,16 @@ mpegts_mux_open_table ( mpegts_mux_t *mm, mpegts_table_t *mt, int subscribe )
mi = mm->mm_active->mmi_input;
LIST_INSERT_HEAD(&mm->mm_tables, mt, mt_link);
mm->mm_num_tables++;
mpegts_table_grab(mt);
pthread_mutex_unlock(&mm->mm_tables_lock);
pthread_mutex_lock(&mi->mi_output_lock);
if (subscribe) {
mi->mi_open_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt);
if (subscribe && !mt->mt_subscribed) {
mpegts_table_grab(mt);
mt->mt_subscribed = 1;
pthread_mutex_unlock(&mm->mm_tables_lock);
pthread_mutex_lock(&mi->mi_output_lock);
mi->mi_open_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt);
pthread_mutex_unlock(&mi->mi_output_lock);
pthread_mutex_lock(&mm->mm_tables_lock);
mpegts_table_release(mt);
}
pthread_mutex_unlock(&mi->mi_output_lock);
pthread_mutex_lock(&mm->mm_tables_lock);
mpegts_table_release(mt);
}

void
Expand Down Expand Up @@ -819,16 +819,16 @@ mpegts_mux_close_table ( mpegts_mux_t *mm, mpegts_table_t *mt )
mi = mm->mm_active->mmi_input;
LIST_REMOVE(mt, mt_link);
mm->mm_num_tables--;
mpegts_table_grab(mt);
pthread_mutex_unlock(&mm->mm_tables_lock);
pthread_mutex_lock(&mi->mi_output_lock);
if (mt->mt_subscribed) {
mi->mi_close_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt);
mpegts_table_grab(mt);
mt->mt_subscribed = 0;
pthread_mutex_unlock(&mm->mm_tables_lock);
pthread_mutex_lock(&mi->mi_output_lock);
mi->mi_close_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt);
pthread_mutex_unlock(&mi->mi_output_lock);
pthread_mutex_lock(&mm->mm_tables_lock);
mpegts_table_release(mt);
}
pthread_mutex_unlock(&mi->mi_output_lock);
pthread_mutex_lock(&mm->mm_tables_lock);
mpegts_table_release(mt);
}

/* **************************************************************************
Expand Down
29 changes: 19 additions & 10 deletions src/input/mpegts/mpegts_table.c
Expand Up @@ -148,26 +148,40 @@ mpegts_table_release_ ( mpegts_table_t *mt )
if (mt->mt_destroy)
mt->mt_destroy(mt);
free(mt->mt_name);
#if ENABLE_TRACE
/* poison */
memset(mt, 0xa5, sizeof(*mt));
#endif
free(mt);
}

void
mpegts_table_destroy ( mpegts_table_t *mt )
static void
mpegts_table_destroy_ ( mpegts_table_t *mt )
{
mpegts_mux_t *mm = mt->mt_mux;

pthread_mutex_lock(&mm->mm_tables_lock);
lock_assert(&mm->mm_tables_lock);

tvhtrace("mpegts", "table: mux %p destroy %s %02X/%02X (%d) pid %04X (%d)",
mm, mt->mt_name, mt->mt_table, mt->mt_mask, mt->mt_table,
mt->mt_pid, mt->mt_pid);
mpegts_table_consistency_check(mm);
mt->mt_destroyed = 1;
mt->mt_mux->mm_close_table(mt->mt_mux, mt);
mpegts_table_consistency_check(mm);
pthread_mutex_unlock(&mm->mm_tables_lock);
mpegts_table_release(mt);
}

void
mpegts_table_destroy ( mpegts_table_t *mt )
{
mpegts_mux_t *mm = mt->mt_mux;

pthread_mutex_lock(&mm->mm_tables_lock);
mpegts_table_destroy_(mt);
pthread_mutex_unlock(&mm->mm_tables_lock);
}

/**
* Determine table type
*/
Expand Down Expand Up @@ -271,13 +285,8 @@ mpegts_table_flush_all ( mpegts_mux_t *mm )
}
while ((mt = LIST_FIRST(&mm->mm_tables))) {
mt->mt_flags &= ~MT_DEFER; /* force destroy */
mt->mt_destroyed = 1; /* early destroy mark */
mpegts_table_grab(mt);
mpegts_table_consistency_check(mm);
pthread_mutex_unlock(&mm->mm_tables_lock);
mpegts_table_destroy(mt);
mpegts_table_release(mt);
pthread_mutex_lock(&mm->mm_tables_lock);
mpegts_table_destroy_(mt);
mpegts_table_consistency_check(mm);
}
assert(mm->mm_num_tables == 0);
Expand Down

0 comments on commit 0b2e072

Please sign in to comment.