From 1e307e8e9fbf5dac0ae1bcebd2eca70ebb2d3a22 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 17 May 2022 09:38:44 -0500 Subject: [PATCH] a/os: Add a function to set thread name. --- CMakeLists.txt | 1 + src/xrt/auxiliary/os/os_threading.h | 32 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14694fc51..3d69243f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,7 @@ else() set(CMAKE_THREAD_PREFER_PTHREAD ON) find_package(Threads) target_link_libraries(xrt-pthreads INTERFACE Threads::Threads) + target_compile_definitions(xrt-pthreads INTERFACE _GNU_SOURCE) endif() if(PKGCONFIG_FOUND AND NOT ANDROID) diff --git a/src/xrt/auxiliary/os/os_threading.h b/src/xrt/auxiliary/os/os_threading.h index 34156b7c9..025b7d503 100644 --- a/src/xrt/auxiliary/os/os_threading.h +++ b/src/xrt/auxiliary/os/os_threading.h @@ -21,11 +21,13 @@ #include #include #include +#define OS_THREAD_HAVE_SETNAME #elif defined(XRT_OS_WINDOWS) #include #include #include #include +#define OS_THREAD_HAVE_SETNAME #else #error "OS not supported" #endif @@ -201,6 +203,21 @@ static inline void os_thread_destroy(struct os_thread *ost) {} +/*! + * Make a best effort to name our thread. + * + * @public @memberof os_thread + */ +static inline void +os_thread_name(struct os_thread *ost, const char *name) +{ +#ifdef OS_THREAD_HAVE_SETNAME + pthread_setname_np(ost->thread, name); +#else + (void)ost; + (void)name; +#endif +} /* * @@ -517,6 +534,21 @@ os_thread_helper_signal_locked(struct os_thread_helper *oth) pthread_cond_signal(&oth->cond); } +/*! + * Make a best effort to name our thread. + * + * @public @memberof os_thread_helper + */ +static inline void +os_thread_helper_name(struct os_thread_helper *oth, const char *name) +{ +#ifdef OS_THREAD_HAVE_SETNAME + pthread_setname_np(oth->thread, name); +#else + (void)oth; + (void)name; +#endif +} /*! * @}