From f82b7b7a8c0c8d2af8a17a5aa212d2c9e7caf940 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Wed, 5 Aug 2020 11:51:32 +0800 Subject: [PATCH] Set SDR thread name if pthread_setname_np() is available --- Makefile | 2 +- sdr.c | 3 ++- util.c | 12 ++++++++++++ util.h | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3379e4f..753c3a4 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,7 @@ benchmarks: oneoff/convert_benchmark oneoff/convert_benchmark oneoff/convert_benchmark: oneoff/convert_benchmark.o convert.o util.o - $(CC) $(CPPFLAGS) $(CFLAGS) -g -o $@ $^ -lm + $(CC) $(CPPFLAGS) $(CFLAGS) -g -o $@ $^ -lm -lpthread oneoff/decode_comm_b: oneoff/decode_comm_b.o comm_b.o ais_charset.o $(CC) $(CPPFLAGS) $(CFLAGS) -g -o $@ $^ -lm diff --git a/sdr.c b/sdr.c index 90d506d..1f76997 100644 --- a/sdr.c +++ b/sdr.c @@ -173,7 +173,8 @@ bool sdrOpen() void sdrRun() { - return current_handler()->run(); + set_thread_name("dump1090-sdr"); + current_handler()->run(); } void sdrClose() diff --git a/util.c b/util.c index d5f101c..f5baa18 100644 --- a/util.c +++ b/util.c @@ -47,6 +47,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// we want pthread_setname_np if available +#define _GNU_SOURCE + #include "dump1090.h" #include @@ -102,3 +105,12 @@ void end_cpu_timing(const struct timespec *start_time, struct timespec *add_to) add_to->tv_nsec += end_time.tv_nsec - start_time->tv_nsec; normalize_timespec(add_to); } + +void set_thread_name(const char *name) +{ +#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 12) + pthread_setname_np(pthread_self(), name); +#else + MODES_NOTUSED(name); +#endif +} diff --git a/util.h b/util.h index 5d32f05..af4185e 100644 --- a/util.h +++ b/util.h @@ -51,4 +51,7 @@ void start_cpu_timing(struct timespec *start_time); /* add difference between start_time and the current CPU time to add_to */ void end_cpu_timing(const struct timespec *start_time, struct timespec *add_to); +/* set current thread name, if supported */ +void set_thread_name(const char *name); + #endif