[libcxx-commits] [libcxx] [llvm] [libc++] Refactor the configuration macros to being always defined (PR #112094)
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Nov 6 05:53:20 PST 2024
mstorsjo wrote:
> Here's what I would suggest:
>
> ```c++
> #if __has_include(<pthread.h>)
>
> #include <pthread.h>
> inline void maybe_set_thread_name(std::thread& t, std::string const& name) {
> if constexpr (std::is_same_v<std::thread::native_handle_type, ::pthread_t>) {
> (void)pthread_setname_np(t.native_handle(), name.c_str());
> }
> }
>
> #else
>
> inline void maybe_set_thread_name(std::thread& t, std::string const& name) {
> // don't even try
> }
>
> #endif
> ```
Thanks - that might indeed work. As the other alternative is to set the thread name with win32 threads, we could also check for that data type - assuming that `pthread_t` and `HANDLE` boil down to distinct types (but it can also very well be that both of them are `void*` underneath...).
Although - I'm potentially leaning towards simply skipping this entirely for mingw, as this is used in libfuzzer which isn't even usable in mingw contexts yet (libfuzzer gets compiled but clang doesn't let you use it); no need to bend over backwards for quality of life improvements for such a configuration.
https://github.com/llvm/llvm-project/pull/112094
More information about the libcxx-commits
mailing list