debug: add wrapper for pthread_create to add a meaningful name

This is very useful for debugging. Though tbh I need to do this code
properly.
This commit is contained in:
Adam Sutton 2013-09-05 22:19:25 +01:00
parent 83f0e0cdf2
commit 2b909fe580
22 changed files with 48 additions and 27 deletions

View file

@ -269,5 +269,5 @@ avahi_init(void)
{
pthread_t tid;
pthread_create(&tid, NULL, avahi_thread, NULL);
tvhthread_create(&tid, NULL, avahi_thread, NULL);
}

View file

@ -997,7 +997,7 @@ capmt_entry_find(const char *id, int create)
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&ptid, &attr, capmt_thread, capmt);
tvhthread_create(&ptid, &attr, capmt_thread, capmt);
pthread_attr_destroy(&attr);
return capmt;

View file

@ -1112,7 +1112,7 @@ cwc_session(cwc_t *cwc)
pthread_cond_init(&cwc->cwc_writer_cond, NULL);
pthread_mutex_init(&cwc->cwc_writer_mutex, NULL);
TAILQ_INIT(&cwc->cwc_writeq);
pthread_create(&writer_thread_id, NULL, cwc_writer_thread, cwc);
tvhthread_create(&writer_thread_id, NULL, cwc_writer_thread, cwc);
/**
* Mainloop
@ -2091,7 +2091,7 @@ cwc_entry_find(const char *id, int create)
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&ptid, &attr, cwc_thread, cwc);
tvhthread_create(&ptid, &attr, cwc_thread, cwc);
pthread_attr_destroy(&attr);
return cwc;

View file

@ -66,7 +66,7 @@ void dvr_inotify_init ( void )
return;
}
pthread_create(&tid, NULL, _dvr_inotify_thread, NULL);
tvhthread_create(&tid, NULL, _dvr_inotify_thread, NULL);
}
/**

View file

@ -90,7 +90,7 @@ dvr_rec_subscribe(dvr_entry_t *de)
buf, st, flags,
NULL, NULL, NULL);
pthread_create(&de->de_thread, NULL, dvr_thread, de);
tvhthread_create(&de->de_thread, NULL, dvr_thread, de);
}
/**

View file

@ -400,7 +400,7 @@ void epggrab_init ( void )
pthread_attr_t tattr;
pthread_attr_init(&tattr);
pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
pthread_create(&tid, &tattr, _epggrab_internal_thread, NULL);
tvhthread_create(&tid, &tattr, _epggrab_internal_thread, NULL);
pthread_attr_destroy(&tattr);
}

View file

@ -414,7 +414,7 @@ int epggrab_module_enable_socket ( void *m, uint8_t e )
tvhlog(LOG_DEBUG, mod->id, "starting socket thread");
pthread_attr_init(&tattr);
pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
pthread_create(&tid, &tattr, _epggrab_socket_thread, mod);
tvhthread_create(&tid, &tattr, _epggrab_socket_thread, mod);
}
mod->enabled = e;
return 1;

View file

@ -2082,7 +2082,7 @@ htsp_serve(int fd, void *opaque, struct sockaddr_storage *source,
LIST_INSERT_HEAD(&htsp_connections, &htsp, htsp_link);
pthread_mutex_unlock(&global_lock);
pthread_create(&htsp.htsp_writer_thread, NULL, htsp_write_scheduler, &htsp);
tvhthread_create(&htsp.htsp_writer_thread, NULL, htsp_write_scheduler, &htsp);
/**
* Reader loop

View file

@ -134,7 +134,7 @@ idnode_init(void)
idnode_queue = NULL;
pthread_mutex_init(&idnode_mutex, NULL);
pthread_cond_init(&idnode_cond, NULL);
pthread_create(&tid, NULL, idnode_thread, NULL);
tvhthread_create(&tid, NULL, idnode_thread, NULL);
}
/**

View file

@ -165,7 +165,7 @@ void imagecache_init ( void )
#if ENABLE_IMAGECACHE
{
pthread_t tid;
pthread_create(&tid, NULL, _imagecache_thread, NULL);
tvhthread_create(&tid, NULL, _imagecache_thread, NULL);
}
#endif
}

View file

@ -230,7 +230,7 @@ v4l_service_start(service_t *t, int instance)
va->va_fd = fd;
va->va_current_service = t;
pthread_create(&va->va_thread, NULL, v4l_thread, va);
tvhthread_create(&va->va_thread, NULL, v4l_thread, va);
v4l_adapter_notify(va);
return 0;
}

View file

@ -534,13 +534,13 @@ void iptv_init ( void )
mpegts_input_set_network((mpegts_input_t*)&iptv_input,
(mpegts_network_t*)&iptv_network);
/* Set table thread */
pthread_create(&tid, NULL, mpegts_input_table_thread, &iptv_input);
tvhthread_create(&tid, NULL, mpegts_input_table_thread, &iptv_input);
/* Setup TS thread */
// TODO: could set this up only when needed
iptv_poll = tvhpoll_create(10);
pthread_mutex_init(&iptv_lock, NULL);
pthread_create(&iptv_thread, NULL, iptv_input_thread, NULL);
tvhthread_create(&iptv_thread, NULL, iptv_input_thread, NULL);
/* Load config */
iptv_mux_load_all();

View file

@ -550,7 +550,7 @@ linuxdvb_frontend_monitor ( void *aux )
/* Start input */
tvh_pipe(O_NONBLOCK, &lfe->lfe_dvr_pipe);
pthread_mutex_lock(&lfe->lfe_dvr_lock);
pthread_create(&lfe->lfe_dvr_thread, NULL,
tvhthread_create(&lfe->lfe_dvr_thread, NULL,
linuxdvb_frontend_input_thread, lfe);
pthread_cond_wait(&lfe->lfe_dvr_cond, &lfe->lfe_dvr_lock);
pthread_mutex_unlock(&lfe->lfe_dvr_lock);
@ -883,7 +883,7 @@ linuxdvb_frontend_create0
pthread_cond_init(&lfe->lfe_dvr_cond, NULL);
/* Start table thread */
pthread_create(&tid, NULL, mpegts_input_table_thread, lfe);
tvhthread_create(&tid, NULL, mpegts_input_table_thread, lfe);
/* No conf */
if (!conf)

View file

@ -206,7 +206,7 @@ tsfile_input_start_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *t )
return SM_CODE_TUNING_FAILED;
}
tvhtrace("tsfile", "adapter %d starting thread", mi->mi_instance);
pthread_create(&mi->mi_thread_id, NULL, tsfile_input_thread, mi);
tvhthread_create(&mi->mi_thread_id, NULL, tsfile_input_thread, mi);
}
/* Current */
@ -243,7 +243,7 @@ tsfile_input_create ( int idx )
LIST_INSERT_HEAD(&tsfile_inputs, mi, mi_global_link);
/* Start table thread */
pthread_create(&tid, NULL, mpegts_input_table_thread, mi);
tvhthread_create(&tid, NULL, mpegts_input_table_thread, mi);
return mi;
}

View file

@ -984,7 +984,7 @@ service_init(void)
TAILQ_INIT(&service_all);
pthread_mutex_init(&pending_save_mutex, NULL);
pthread_cond_init(&pending_save_cond, NULL);
pthread_create(&tid, NULL, service_saver, NULL);
tvhthread_create(&tid, NULL, service_saver, NULL);
}

View file

@ -48,7 +48,7 @@ service_mapper_init ( void )
pthread_t tid;
TAILQ_INIT(&service_mapper_queue);
pthread_cond_init(&service_mapper_cond, NULL);
pthread_create(&tid, NULL, service_mapper_thread, NULL);
tvhthread_create(&tid, NULL, service_mapper_thread, NULL);
}
/*

View file

@ -490,7 +490,7 @@ tcp_server_loop(void *aux)
continue;
}
pthread_create(&tid, &attr, tcp_server_start, tsl);
tvhthread_create(&tid, &attr, tcp_server_start, tsl);
}
}
return NULL;
@ -590,7 +590,7 @@ tcp_server_init(int opt_ipv6)
tcp_preferred_address_family = AF_INET6;
tcp_server_poll = tvhpoll_create(10);
pthread_create(&tid, NULL, tcp_server_loop, NULL);
tvhthread_create(&tid, NULL, tcp_server_loop, NULL);
}

View file

@ -253,8 +253,8 @@ streaming_target_t *timeshift_create
/* Initialise input */
streaming_queue_init(&ts->wr_queue, 0);
streaming_target_init(&ts->input, timeshift_input, ts, 0);
pthread_create(&ts->wr_thread, NULL, timeshift_writer, ts);
pthread_create(&ts->rd_thread, NULL, timeshift_reader, ts);
tvhthread_create(&ts->wr_thread, NULL, timeshift_writer, ts);
tvhthread_create(&ts->rd_thread, NULL, timeshift_reader, ts);
/* Update index */
timeshift_index++;

View file

@ -344,7 +344,7 @@ void timeshift_filemgr_init ( void )
pthread_mutex_init(&timeshift_reaper_lock, NULL);
pthread_cond_init(&timeshift_reaper_cond, NULL);
TAILQ_INIT(&timeshift_reaper_list);
pthread_create(&timeshift_reaper_thread, NULL,
tvhthread_create(&timeshift_reaper_thread, NULL,
timeshift_reaper_callback, NULL);
}

View file

@ -20,6 +20,7 @@
#include "config.h"
#define _GNU_SOURCE
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
@ -522,6 +523,11 @@ static inline void mystrset(char **p, const char *s)
*p = s ? strdup(s) : NULL;
}
int tvhthread_create0(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg, const char *name);
#define tvhthread_create(a, b, c, d) tvhthread_create0(a, b, c, d, #c)
int tvh_open(const char *pathname, int flags, mode_t mode);
int tvh_socket(int domain, int type, int protocol);

View file

@ -393,7 +393,7 @@ 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(&tvhlog_tid, NULL, tvhlog_thread, NULL);
tvhthread_create(&tvhlog_tid, NULL, tvhlog_thread, NULL);
}
void

View file

@ -1,8 +1,10 @@
#define __USE_GNU
#include "tvheadend.h"
#include <fcntl.h>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <unistd.h>
#include "tvheadend.h"
#include <pthread.h>
int
tvh_open(const char *pathname, int flags, mode_t mode)
@ -78,3 +80,16 @@ tvh_write(int fd, const void *buf, size_t len)
return len ? 1 : 0;
}
int tvhthread_create0(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg, const char *name)
{
int r;
char buf[16] = { 0 };
strncpy(buf, name, sizeof(buf)-1);
r = pthread_create(thread, attr, start_routine, arg);
tvhinfo("thread", "created thread %ld [%s / %p]", *thread, name, start_routine);
if (r) return r;
pthread_setname_np(*thread, buf);
return r;
}