]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvhlog: ensure the tvhlog thread completes before exit
authorAdam Sutton <dev@adamsutton.me.uk>
Wed, 28 Aug 2013 20:08:11 +0000 (21:08 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Fri, 30 Aug 2013 22:24:26 +0000 (23:24 +0100)
Note: I think my thinking for needing this logging thread is possibly
no longer valid. So this might be removed at some point (or at least
made optional).

src/main.c
src/tvhlog.c
src/tvhlog.h

index 7af4f473a9117949ffb1d19b13f2fa19d47a70d9..716f4086bcebdd5c4cde8d49f51e8311f48b30d1 100644 (file)
@@ -792,6 +792,7 @@ main(int argc, char **argv)
   pthread_mutex_unlock(&global_lock);
 
   tvhlog(LOG_NOTICE, "STOP", "Exiting HTS Tvheadend");
+  tvhlog_end();
 
   if(opt_fork)
     unlink(opt_pidpath);
index e32bb240af913c298e1005c0e685ad6eafa49894..fca5c0c75f90c92889883cdae683142416ae6013 100644 (file)
 
 #include "webui/webui.h"
 
+int                     tvhlog_exit;
 int                      tvhlog_level;
 int                      tvhlog_options;
 char                    *tvhlog_path;
 htsmsg_t                *tvhlog_debug;
 htsmsg_t                *tvhlog_trace;
+pthread_t                tvhlog_tid;
 pthread_mutex_t          tvhlog_mutex;
 pthread_cond_t           tvhlog_cond;
 TAILQ_HEAD(,tvhlog_msg)  tvhlog_queue;
@@ -147,13 +149,13 @@ tvhlog_thread ( void *p )
   size_t l;
   char buf[2048], t[128];
   struct tm tm;
-  
 
   pthread_mutex_lock(&tvhlog_mutex);
   while (1) {
 
     /* Wait */
     if (!(msg = TAILQ_FIRST(&tvhlog_queue))) {
+      if (tvhlog_exit) break;
       if (fp) {
         fclose(fp); // only issue here is we close with mutex!
                     // but overall performance will be higher
@@ -351,7 +353,7 @@ _tvhlog_hexdump(const char *file, int line,
 void 
 tvhlog_init ( int level, int options, const char *path )
 {
-  pthread_t tid;
+  tvhlog_exit    = 0;
   tvhlog_level   = level;
   tvhlog_options = options;
   tvhlog_path    = path ? strdup(path) : NULL;
@@ -361,6 +363,15 @@ tvhlog_init ( int level, int options, const char *path )
   pthread_mutex_init(&tvhlog_mutex, NULL);
   pthread_cond_init(&tvhlog_cond, NULL);
   TAILQ_INIT(&tvhlog_queue);
-  pthread_create(&tid, NULL, tvhlog_thread, NULL);
+  pthread_create(&tvhlog_tid, NULL, tvhlog_thread, NULL);
 }
 
+void
+tvhlog_end ( void )
+{
+  pthread_mutex_lock(&tvhlog_mutex);
+  tvhlog_exit = 1;
+  pthread_cond_signal(&tvhlog_cond);
+  pthread_mutex_unlock(&tvhlog_mutex);
+  pthread_join(tvhlog_tid, NULL);
+}
index 2003bede136a4cccfea975c8828fac7b2e22750a..54cb6ada3eeefc783ea01df3ec9cec5d185de74e 100644 (file)
@@ -35,6 +35,7 @@ extern pthread_mutex_t  tvhlog_mutex;
 
 /* Initialise */
 void tvhlog_init       ( int level, int options, const char *path ); 
+void tvhlog_end        ( void );
 void tvhlog_set_debug  ( const char *subsys );
 void tvhlog_get_debug  ( char *subsys, size_t len );
 void tvhlog_set_trace  ( const char *subsys );