]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
iptv: improve the thread exit procedure - use pipe, fixes #5550
authorJaroslav Kysela <perex@perex.cz>
Wed, 27 Feb 2019 16:59:28 +0000 (17:59 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 27 Feb 2019 17:01:42 +0000 (18:01 +0100)
src/input/mpegts/iptv/iptv.c

index b13348db467345f7f41159e03ab0fde093af35d0..f34030c2e5fccc0dbddfbc4633a1153012452c4f 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <signal.h>
+#include <fcntl.h>
 
 #include "iptv_private.h"
 #include "tvhpoll.h"
@@ -38,7 +39,7 @@ typedef struct iptv_thread_pool {
   pthread_t thread;
   iptv_input_t *input;
   tvhpoll_t *poll;
-  int running;
+  th_pipe_t pipe;
   uint32_t streams;
 } iptv_thread_pool_t;
 
@@ -525,7 +526,7 @@ iptv_input_thread ( void *aux )
   iptv_input_t *mi;
   tvhpoll_event_t ev;
 
-  while ( pool->running && tvheadend_is_running() ) {
+  while ( tvheadend_is_running() ) {
     nfds = tvhpoll_wait(pool->poll, &ev, 1, -1);
     if ( nfds < 0 ) {
       if (tvheadend_is_running() && !ERRNO_AGAIN(errno)) {
@@ -537,6 +538,10 @@ iptv_input_thread ( void *aux )
     } else if ( nfds == 0 ) {
       continue;
     }
+
+    if (ev.ptr == &pool->pipe)
+      break;
+
     im = ev.ptr;
     r  = 0;
 
@@ -1225,7 +1230,8 @@ iptv_input_thread_manage(int count, int force)
     pool = calloc(1, sizeof(*pool));
     pool->poll = tvhpoll_create(10);
     pool->input = iptv_create_input(pool);
-    pool->running = 1;
+    tvh_pipe(O_NONBLOCK, &pool->pipe);
+    tvhpoll_add1(pool->poll, pool->pipe.rd, TVHPOLL_IN, &pool->pipe);
     tvh_thread_create(&pool->thread, NULL, iptv_input_thread, pool, "iptv");
     TAILQ_INSERT_TAIL(&iptv_tpool, pool, link);
     iptv_tpool_count++;
@@ -1233,12 +1239,12 @@ iptv_input_thread_manage(int count, int force)
   while (iptv_tpool_count > count) {
     TAILQ_FOREACH(pool, &iptv_tpool, link)
       if (pool->streams == 0 || force) {
-        pool->running = 0;
-        tvh_thread_kill(pool->thread, SIGQUIT);
+        tvh_write(pool->pipe.wr, "q", 1);
         pthread_join(pool->thread, NULL);
         TAILQ_REMOVE(&iptv_tpool, pool, link);
         mpegts_input_stop_all((mpegts_input_t*)pool->input);
         mpegts_input_delete((mpegts_input_t *)pool->input, 0);
+        tvhpoll_rem1(pool->poll, pool->pipe.rd);
         tvhpoll_destroy(pool->poll);
         free(pool);
         iptv_tpool_count--;