Skip to content

Commit

Permalink
iiod: thread-pool: define HAS_PTHREAD_SETNAME_NP as 0 or 1
Browse files Browse the repository at this point in the history
Instead of making HAS_PTHREAD_SETNAME_NP as a "pure" preprocessor define,
make it defined with a value of 0 or 1 so that we can use it normal
code and since it's a compile time constant, the compiler can get rid of
dead code when it evaluates to 0.

This change will also make it cleaner for adding support for naming
pthreads.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
  • Loading branch information
nunojsa committed Jan 30, 2025
1 parent ee3a89b commit 7b7adee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion iio-config.h.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
#cmakedefine01 HAVE_AVAHI
#cmakedefine01 WITH_ZSTD
#cmakedefine01 NO_THREADS
#cmakedefine01 HAS_PTHREAD_SETNAME_NP

#cmakedefine HAS_PIPE2
#cmakedefine HAS_STRDUP
#cmakedefine HAS_STRNDUP
#cmakedefine HAS_STRTOK_R
#cmakedefine HAS_STRERROR_R
#cmakedefine HAS_NEWLOCALE
#cmakedefine HAS_PTHREAD_SETNAME_NP
#cmakedefine HAVE_IPV6

#define IF_ENABLED(cfg, ptr) ((cfg) ? (ptr) : NULL)
Expand Down
5 changes: 2 additions & 3 deletions iiod/thread-pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Author: Paul Cercueil <paul.cercueil@analog.com>
*/

#include "iio-config.h"
#include "thread-pool.h"

#include <errno.h>
Expand Down Expand Up @@ -101,10 +102,8 @@ int thread_pool_add_thread(struct thread_pool *pool,
if (ret) {
free(pdata);
thread_pool_thread_stopped(pool);
} else {
#ifdef HAS_PTHREAD_SETNAME_NP
} else if (HAS_PTHREAD_SETNAME_NP) {
pthread_setname_np(thd, name);
#endif
}

pthread_attr_destroy(&attr);
Expand Down

0 comments on commit 7b7adee

Please sign in to comment.