tvhlog: ensure the tvhlog thread completes before exit
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).
This commit is contained in:
parent
75fa931667
commit
e7cc34be74
3 changed files with 16 additions and 3 deletions
|
@ -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);
|
||||
|
|
17
src/tvhlog.c
17
src/tvhlog.c
|
@ -25,11 +25,13 @@
|
|||
|
||||
#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);
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Add table
Reference in a new issue