diff --git a/CMakeLists.txt b/CMakeLists.txt index 5eee82f7f..d1a39ed19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -597,8 +597,13 @@ else () target_link_libraries(iio PRIVATE ${PTHREAD_LIBRARIES}) endif() - + check_symbol_exists(pthread_setname_np "pthread.h" HAS_PTHREAD_SETNAME_NP) + if (HAS_PTHREAD_SETNAME_NP) + # still need to define _GNU_SOURCE for pthread_setname_np + set_source_files_properties(lock.c PROPERTIES COMPILE_FLAGS -D_GNU_SOURCE) + endif() target_sources(iio PRIVATE lock.c) + endif() if (IIOD_CLIENT OR WITH_IIOD OR WITH_LIBTINYIIOD) diff --git a/lock.c b/lock.c index 87e29cb35..1b1d2a6af 100644 --- a/lock.c +++ b/lock.c @@ -134,7 +134,12 @@ struct iio_thrd * iio_thrd_create(int (*thrd)(void *), return iio_ptr(ret); } - /* TODO: Set name */ + if (HAS_PTHREAD_SETNAME_NP) { + ret = pthread_setname_np(iio_thrd->thid, name); + if (ret) + fprintf(stderr, "[WARNING]: Setting thread name(%s) failed\n", + name); + } return iio_thrd; }