[compiler-rt] r312159 - Add NetBSD support in test/tsan/thread_name*.cc
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 30 12:40:47 PDT 2017
Author: kamil
Date: Wed Aug 30 12:40:47 2017
New Revision: 312159
URL: http://llvm.org/viewvc/llvm-project?rev=312159&view=rev
Log:
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
Modified:
compiler-rt/trunk/test/tsan/thread_name.cc
compiler-rt/trunk/test/tsan/thread_name2.cc
Modified: compiler-rt/trunk/test/tsan/thread_name.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_name.cc?rev=312159&r1=312158&r2=312159&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/thread_name.cc (original)
+++ compiler-rt/trunk/test/tsan/thread_name.cc Wed Aug 30 12:40:47 2017
@@ -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
Modified: compiler-rt/trunk/test/tsan/thread_name2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/thread_name2.cc?rev=312159&r1=312158&r2=312159&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/thread_name2.cc (original)
+++ compiler-rt/trunk/test/tsan/thread_name2.cc Wed Aug 30 12:40:47 2017
@@ -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);
More information about the llvm-commits
mailing list