mpegts input: protect global variable mpegts_pid_skel using mutex
- the skel variable is shared in multiple thread - also remove mpegts_pid_sub_skel, it's not used frequently
This commit is contained in:
parent
fbf7a3da3c
commit
7f1d851a40
5 changed files with 21 additions and 9 deletions
|
@ -511,6 +511,7 @@ const int dvb_sat_position_from_str( const char *buf );
|
|||
|
||||
#endif /* ENABLE_MPEGTS_DVB */
|
||||
|
||||
void dvb_init ( void );
|
||||
void dvb_done ( void );
|
||||
|
||||
#endif /* DVB_SUPPORT_H */
|
||||
|
|
|
@ -899,13 +899,19 @@ dvb_sat_position_from_str( const char *buf )
|
|||
/**
|
||||
*
|
||||
*/
|
||||
extern pthread_mutex_t mpegts_pid_skel_mutex;
|
||||
|
||||
void dvb_init( void )
|
||||
{
|
||||
pthread_mutex_init(&mpegts_pid_skel_mutex, NULL);
|
||||
}
|
||||
|
||||
void dvb_done( void )
|
||||
{
|
||||
extern SKEL_DECLARE(mpegts_table_state_skel, struct mpegts_table_state);
|
||||
extern SKEL_DECLARE(mpegts_pid_sub_skel, mpegts_pid_sub_t);
|
||||
extern SKEL_DECLARE(mpegts_pid_skel, mpegts_pid_t);
|
||||
|
||||
SKEL_FREE(mpegts_table_state_skel);
|
||||
SKEL_FREE(mpegts_pid_sub_skel);
|
||||
SKEL_FREE(mpegts_pid_skel);
|
||||
pthread_mutex_destroy(&mpegts_pid_skel_mutex);
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
|
||||
SKEL_DECLARE(mpegts_pid_sub_skel, mpegts_pid_sub_t);
|
||||
|
||||
static void
|
||||
mpegts_input_del_network ( mpegts_network_link_t *mnl );
|
||||
|
||||
|
@ -338,17 +336,19 @@ mpegts_input_open_pid
|
|||
{
|
||||
char buf[512];
|
||||
mpegts_pid_t *mp;
|
||||
mpegts_pid_sub_t *mps;
|
||||
assert(owner != NULL);
|
||||
lock_assert(&mi->mi_output_lock);
|
||||
if ((mp = mpegts_mux_find_pid(mm, pid, 1))) {
|
||||
SKEL_ALLOC(mpegts_pid_sub_skel);
|
||||
mpegts_pid_sub_skel->mps_type = type;
|
||||
mpegts_pid_sub_skel->mps_owner = owner;
|
||||
if (!RB_INSERT_SORTED(&mp->mp_subs, mpegts_pid_sub_skel, mps_link, mps_cmp)) {
|
||||
mps = calloc(1, sizeof(*mps));
|
||||
mps->mps_type = type;
|
||||
mps->mps_owner = owner;
|
||||
if (!RB_INSERT_SORTED(&mp->mp_subs, mps, mps_link, mps_cmp)) {
|
||||
mpegts_mux_nice_name(mm, buf, sizeof(buf));
|
||||
tvhdebug("mpegts", "%s - open PID %04X (%d) [%d/%p]",
|
||||
buf, mp->mp_pid, mp->mp_pid, type, owner);
|
||||
SKEL_USED(mpegts_pid_sub_skel);
|
||||
} else {
|
||||
free(mps);
|
||||
}
|
||||
}
|
||||
return mp;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
pthread_mutex_t mpegts_pid_skel_mutex;
|
||||
SKEL_DECLARE(mpegts_pid_skel, mpegts_pid_t);
|
||||
|
||||
static void mpegts_mux_scan_timeout ( void *p );
|
||||
|
@ -1143,6 +1144,7 @@ mpegts_mux_find_pid_ ( mpegts_mux_t *mm, int pid, int create )
|
|||
skel.mp_pid = pid;
|
||||
mp = RB_FIND(&mm->mm_pids, &skel, mp_link, mp_cmp);
|
||||
} else {
|
||||
pthread_mutex_lock(&mpegts_pid_skel_mutex);
|
||||
SKEL_ALLOC(mpegts_pid_skel);
|
||||
mpegts_pid_skel->mp_pid = pid;
|
||||
mp = RB_INSERT_SORTED(&mm->mm_pids, mpegts_pid_skel, mp_link, mp_cmp);
|
||||
|
@ -1152,6 +1154,7 @@ mpegts_mux_find_pid_ ( mpegts_mux_t *mm, int pid, int create )
|
|||
mp->mp_fd = -1;
|
||||
mp->mp_cc = -1;
|
||||
}
|
||||
pthread_mutex_unlock(&mpegts_pid_skel_mutex);
|
||||
}
|
||||
if (mp) {
|
||||
mm->mm_last_pid = pid;
|
||||
|
|
|
@ -818,6 +818,8 @@ main(int argc, char **argv)
|
|||
|
||||
service_init();
|
||||
|
||||
dvb_init();
|
||||
|
||||
#if ENABLE_MPEGTS
|
||||
mpegts_init(adapter_mask, &opt_satip_xml, &opt_tsfile, opt_tsfile_tuner);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue