Skip to content

Commit f266601

Browse files
committedOct 24, 2014
[Tsan] Fix the thread_name tests to build on FreeBSD
Differential Revision: http://reviews.llvm.org/D5855 llvm-svn: 220552
1 parent 6a9dec2 commit f266601

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
 

‎compiler-rt/test/tsan/thread_name.cc

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
#include <stdio.h>
44
#include <unistd.h>
55

6+
#if defined(__linux__)
7+
#define USE_PTHREAD_SETNAME_NP __GLIBC_PREREQ(2, 12)
8+
#elif defined(__FreeBSD__)
9+
#include <pthread_np.h>
10+
#define USE_PTHREAD_SETNAME_NP 1
11+
#define pthread_setname_np pthread_set_name_np
12+
#else
13+
#define USE_PTHREAD_SETNAME_NP 0
14+
#endif
15+
616
extern "C" void AnnotateThreadName(const char *f, int l, const char *name);
717

818
int Global;
@@ -15,7 +25,7 @@ void *Thread1(void *x) {
1525
}
1626

1727
void *Thread2(void *x) {
18-
#if SANITIZER_LINUX && __GLIBC_PREREQ(2, 12)
28+
#if USE_PTHREAD_SETNAME_NP
1929
pthread_setname_np(pthread_self(), "Thread2");
2030
#else
2131
AnnotateThreadName(__FILE__, __LINE__, "Thread2");
@@ -35,4 +45,3 @@ int main() {
3545
// CHECK: WARNING: ThreadSanitizer: data race
3646
// CHECK: Thread T1 'Thread1'
3747
// CHECK: Thread T2 'Thread2'
38-

‎compiler-rt/test/tsan/thread_name2.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
#include <stdio.h>
44
#include <unistd.h>
55

6+
#if defined(__FreeBSD__)
7+
#include <pthread_np.h>
8+
#define pthread_setname_np pthread_set_name_np
9+
#endif
10+
611
int Global;
712

813
void *Thread1(void *x) {
@@ -29,4 +34,3 @@ int main() {
2934
// CHECK: WARNING: ThreadSanitizer: data race
3035
// CHECK: Thread T1 'foobar1'
3136
// CHECK: Thread T2 'foobar2'
32-

0 commit comments

Comments
 (0)
Please sign in to comment.