Add NetBSD support in test/tsan/thread_name*.cc

Summary:
A snipped from the documentation of thread_setname_np(3):

NAME
     pthread_getname_np - get and set descriptive name of a thread

LIBRARY
     POSIX Threads Library (libpthread, -lpthread)

SYNOPSIS
     #include <pthread.h>

     int
     pthread_getname_np(pthread_t thread, char *name, size_t len);

     int
     pthread_setname_np(pthread_t thread, const char *name, void *arg);

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc

Reviewed By: dvyukov

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D37306

llvm-svn: 312159
This commit is contained in:
Kamil Rytarowski 2017-08-30 19:40:47 +00:00
parent c6615f56f5
commit 08e525ea06
2 changed files with 13 additions and 5 deletions

View File

@ -3,10 +3,14 @@
#if defined(__linux__)
#define USE_PTHREAD_SETNAME_NP __GLIBC_PREREQ(2, 12)
#define tsan_pthread_setname_np pthread_setname_np
#elif defined(__FreeBSD__)
#include <pthread_np.h>
#define USE_PTHREAD_SETNAME_NP 1
#define pthread_setname_np pthread_set_name_np
#define tasn_pthread_setname_np pthread_set_name_np
#elif defined(__NetBSD__)
#define USE_PTHREAD_SETNAME_NP 1
#define tsan_pthread_setname_np(a, b) pthread_setname_np((a), "%s", (void *)(b))
#else
#define USE_PTHREAD_SETNAME_NP 0
#endif
@ -24,7 +28,7 @@ void *Thread1(void *x) {
void *Thread2(void *x) {
#if USE_PTHREAD_SETNAME_NP
pthread_setname_np(pthread_self(), "Thread2");
tsan_pthread_setname_np(pthread_self(), "Thread2");
#else
AnnotateThreadName(__FILE__, __LINE__, "Thread2");
#endif

View File

@ -6,7 +6,11 @@
#if defined(__FreeBSD__)
#include <pthread_np.h>
#define pthread_setname_np pthread_set_name_np
#define tsan_pthread_setname_np pthread_set_name_np
#elif defined(__NetBSD__)
#define tsan_pthread_setname_np(a, b) pthread_setname_np((a), "%s", (void *)(b))
#else
#define tsan_pthread_setname_np pthread_setname_np
#endif
long long Global;
@ -18,7 +22,7 @@ void *Thread1(void *x) {
}
void *Thread2(void *x) {
pthread_setname_np(pthread_self(), "foobar2");
tsan_pthread_setname_np(pthread_self(), "foobar2");
Global--;
barrier_wait(&barrier);
return 0;
@ -29,7 +33,7 @@ int main() {
pthread_t t[2];
pthread_create(&t[0], 0, Thread1, 0);
pthread_create(&t[1], 0, Thread2, 0);
pthread_setname_np(t[0], "foobar1");
tsan_pthread_setname_np(t[0], "foobar1");
barrier_wait(&barrier);
pthread_join(t[0], NULL);
pthread_join(t[1], NULL);