llvm.org GIT mirror llvm / 2b46554
Detect the existence of pthread_{s,g}etname_np in libpthread on Linux Older Linux distributions may not have those functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296915 91177308-0d34-0410-b5e6-96231b3b80d8 Krzysztof Parzyszek 3 years ago
2 changed file(s) with 12 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
244244 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
245245 if( LLVM_USING_GLIBC )
246246 add_llvm_definitions( -D_GNU_SOURCE )
247 endif()
248 # This check requires _GNU_SOURCE
249 if(HAVE_LIBPTHREAD)
250 check_library_exists(pthread pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP)
251 check_library_exists(pthread pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP)
252 elseif(PTHREAD_IN_LIBC)
253 check_library_exists(c pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP)
254 check_library_exists(c pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP)
247255 endif()
248256
249257 set(headers "sys/types.h")
114114 StringRef NameStr = Name.toNullTerminatedStringRef(Storage);
115115 #if defined(__linux__)
116116 #if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
117 #if HAVE_PTHREAD_SETNAME_NP
117118 ::pthread_setname_np(::pthread_self(), NameStr.data());
119 #endif
118120 #endif
119121 #elif defined(__FreeBSD__)
120122 ::pthread_set_name_np(::pthread_self(), NameStr.data());
172174 Name.append(buf, buf + strlen(buf));
173175 #elif defined(__linux__)
174176 #if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
177 #if HAVE_PTHREAD_GETNAME_NP
175178 constexpr int MAXNAMELEN = 16;
176179 char Buffer[MAXNAMELEN];
177180 if (0 == ::pthread_getname_np(::pthread_self(), Buffer, MAXNAMELEN))
178181 Name.append(Buffer, Buffer + strlen(Buffer));
179182 #endif
180183 #endif
184 #endif
181185 }