Skip to content

Commit 647f892

Browse files
authored
[llvm][Support] Simplify HAVE_PTHREAD_GETNAME/SETNAME_NP handling. NFCI (llvm#106486)
1 parent c74cc73 commit 647f892

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

llvm/lib/Support/Unix/Threading.inc

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,8 @@ static constexpr uint32_t get_max_thread_name_length_impl() {
141141
return PTHREAD_MAX_NAMELEN_NP;
142142
#elif defined(__APPLE__)
143143
return 64;
144-
#elif defined(__linux__)
145-
#if HAVE_PTHREAD_SETNAME_NP
144+
#elif defined(__linux__) && HAVE_PTHREAD_SETNAME_NP
146145
return 16;
147-
#else
148-
return 0;
149-
#endif
150146
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
151147
return 16;
152148
#elif defined(__OpenBSD__)
@@ -174,12 +170,8 @@ void llvm::set_thread_name(const Twine &Name) {
174170
if (get_max_thread_name_length() > 0)
175171
NameStr = NameStr.take_back(get_max_thread_name_length() - 1);
176172
(void)NameStr;
177-
#if defined(__linux__)
178-
#if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
179-
#if HAVE_PTHREAD_SETNAME_NP
173+
#if defined(__linux__) && HAVE_PTHREAD_SETNAME_NP
180174
::pthread_setname_np(::pthread_self(), NameStr.data());
181-
#endif
182-
#endif
183175
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
184176
::pthread_set_name_np(::pthread_self(), NameStr.data());
185177
#elif defined(__NetBSD__)
@@ -241,14 +233,12 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
241233
::pthread_get_name_np(::pthread_self(), buf, len);
242234

243235
Name.append(buf, buf + strlen(buf));
244-
#elif defined(__linux__)
245-
#if HAVE_PTHREAD_GETNAME_NP
236+
#elif defined(__linux__) && HAVE_PTHREAD_GETNAME_NP
246237
constexpr uint32_t len = get_max_thread_name_length_impl();
247238
char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive.
248239
if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len))
249240
Name.append(Buffer, Buffer + strlen(Buffer));
250241
#endif
251-
#endif
252242
}
253243

254244
SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {

0 commit comments

Comments
 (0)