From cfc9c8c10d082677770c1aa4874fdc859f011cbe Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 25 Jun 2023 09:06:22 +0100 Subject: [PATCH] Simplify and make more consistant the pthread library --- configure.ac | 6 +----- include/n2n_typedefs.h | 2 +- src/edge_utils.c | 4 ++-- src/n2n.c | 12 ++++++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 8b7377a..9a6005d 100644 --- a/configure.ac +++ b/configure.ac @@ -97,11 +97,7 @@ AC_ARG_ENABLE([pthread], [AS_HELP_STRING([--enable-pthread], [support for pthread])], [], [enable_pthread=no]) AS_IF([test "x$enable_pthread" != xno], - [AC_CHECK_LIB([pthread], [pthread_mutex_trylock], - [ - AC_DEFINE([HAVE_PTHREAD],[1],[pthread is present]) - LDFLAGS="${LDFLAGS} -pthread" - ], + [AC_CHECK_LIB([pthread], [pthread_mutex_trylock],, [AC_MSG_ERROR([pthread library not found])] )], ) diff --git a/include/n2n_typedefs.h b/include/n2n_typedefs.h index 582b590..500bfcd 100644 --- a/include/n2n_typedefs.h +++ b/include/n2n_typedefs.h @@ -637,7 +637,7 @@ typedef struct n2n_resolve_ip_sock { typedef struct n2n_resolve_parameter { n2n_resolve_ip_sock_t *list; /* pointer to list of to be resolved nodes */ uint8_t changed; /* indicates a change */ -#ifdef HAVE_PTHREAD +#ifdef HAVE_LIBPTHREAD pthread_t id; /* thread id */ pthread_mutex_t access; /* mutex for shared access */ #endif diff --git a/src/edge_utils.c b/src/edge_utils.c index d59f1ad..85ef0db 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -1642,14 +1642,14 @@ void update_supernode_reg (n2n_edge_t * eee, time_t now) { --(eee->sup_attempts); } -#ifndef HAVE_PTHREAD +#ifndef HAVE_LIBPTHREAD if(supernode2sock(&(eee->curr_sn->sock), eee->curr_sn->ip_addr) == 0) { #endif traceEvent(TRACE_INFO, "registering with supernode [%s][number of supernodes %d][attempts left %u]", supernode_ip(eee), HASH_COUNT(eee->conf.supernodes), (unsigned int)eee->sup_attempts); send_register_super(eee); -#ifndef HAVE_PTHREAD +#ifndef HAVE_LIBPTHREAD } #endif diff --git a/src/n2n.c b/src/n2n.c index bcba07b..9b8689f 100644 --- a/src/n2n.c +++ b/src/n2n.c @@ -30,6 +30,10 @@ #include "sn_selection.h" // for sn_selection_criterion_default #include "uthash.h" // for UT_hash_handle, HASH_DEL, HASH_ITER, HAS... +#ifdef HAVE_LIBPTHREAD +#include +#endif + #ifdef WIN32 #include #include @@ -332,7 +336,7 @@ int supernode2sock (n2n_sock_t *sn, const n2n_sn_name_t addrIn) { } -#ifdef HAVE_PTHREAD +#ifdef HAVE_LIBPTHREAD N2N_THREAD_RETURN_DATATYPE resolve_thread(N2N_THREAD_PARAMETER_DATATYPE p) { n2n_resolve_parameter_t *param = (n2n_resolve_parameter_t*)p; @@ -385,7 +389,7 @@ N2N_THREAD_RETURN_DATATYPE resolve_thread(N2N_THREAD_PARAMETER_DATATYPE p) { int resolve_create_thread (n2n_resolve_parameter_t **param, struct peer_info *sn_list) { -#ifdef HAVE_PTHREAD +#ifdef HAVE_LIBPTHREAD struct peer_info *sn, *tmp_sn; n2n_resolve_ip_sock_t *entry; int ret; @@ -430,7 +434,7 @@ int resolve_create_thread (n2n_resolve_parameter_t **param, struct peer_info *sn void resolve_cancel_thread (n2n_resolve_parameter_t *param) { -#ifdef HAVE_PTHREAD +#ifdef HAVE_LIBPTHREAD pthread_cancel(param->id); free(param); #endif @@ -441,7 +445,7 @@ uint8_t resolve_check (n2n_resolve_parameter_t *param, uint8_t requires_resoluti uint8_t ret = requires_resolution; /* if trylock fails, it still requires resolution */ -#ifdef HAVE_PTHREAD +#ifdef HAVE_LIBPTHREAD n2n_resolve_ip_sock_t *entry, *tmp_entry; n2n_sock_str_t sock_buf;