Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
IPTV: http/https - another locking cleanup
  • Loading branch information
perexg committed Dec 7, 2015
1 parent ea0e993 commit 637d1f3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/input/mpegts/iptv/iptv_http.c
Expand Up @@ -31,6 +31,7 @@
typedef struct http_priv {
iptv_mux_t *im;
http_client_t *hc;
uint8_t shutdown;
uint8_t started;
sbuf_t m3u_sbuf;
sbuf_t key_sbuf;
Expand Down Expand Up @@ -63,20 +64,21 @@ static int iptv_http_complete_key ( http_client_t *hc );
*
*/
static int
iptv_http_safe_global_lock( iptv_mux_t *im )
iptv_http_safe_global_lock( http_priv_t *hp )
{
iptv_mux_t *im = hp->im;
int r;

while (1) {
if (im->mm_active == NULL)
if (im->mm_active == NULL || hp->shutdown)
return 0;
r = pthread_mutex_trylock(&global_lock);
if (r == 0)
break;
if (r != EBUSY)
continue;
sched_yield();
if (im->mm_active == NULL)
if (im->mm_active == NULL || hp->shutdown)
return 0;
r = pthread_mutex_trylock(&global_lock);
if (r == 0)
Expand Down Expand Up @@ -242,7 +244,7 @@ iptv_http_header ( http_client_t *hc )

hp->m3u_header = 0;
hp->off = 0;
if (iptv_http_safe_global_lock(hp->im)) {
if (iptv_http_safe_global_lock(hp)) {
if (!hp->started) {
iptv_input_mux_started(hp->im);
} else {
Expand Down Expand Up @@ -337,8 +339,8 @@ iptv_http_data

pthread_mutex_unlock(&iptv_lock);

if (pause && iptv_http_safe_global_lock(im)) {
if (im->mm_active)
if (pause && iptv_http_safe_global_lock(hp)) {
if (im->mm_active && !hp->shutdown)
gtimer_arm(&im->im_pause_timer, iptv_input_unpause, im, 1);
pthread_mutex_unlock(&global_lock);
}
Expand Down Expand Up @@ -547,6 +549,7 @@ iptv_http_stop
http_priv_t *hp = im->im_data;

hp->hc->hc_aux = NULL;
hp->shutdown = 1;
pthread_mutex_unlock(&iptv_lock);
http_client_close(hp->hc);
pthread_mutex_lock(&iptv_lock);
Expand Down

0 comments on commit 637d1f3

Please sign in to comment.