Set SDR thread name if pthread_setname_np() is available

This commit is contained in:
Oliver Jowett 2020-08-05 11:51:32 +08:00
parent 01587a114a
commit f82b7b7a8c
4 changed files with 18 additions and 2 deletions

View File

@ -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

3
sdr.c
View File

@ -173,7 +173,8 @@ bool sdrOpen()
void sdrRun()
{
return current_handler()->run();
set_thread_name("dump1090-sdr");
current_handler()->run();
}
void sdrClose()

12
util.c
View File

@ -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 <stdlib.h>
@ -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
}

3
util.h
View File

@ -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