mirror of
https://github.com/ntop/n2n.git
synced 2024-09-19 16:41:11 +02:00
Simplify and make more consistant the pthread library
This commit is contained in:
parent
4c0c173221
commit
cfc9c8c10d
|
@ -97,11 +97,7 @@ AC_ARG_ENABLE([pthread],
|
||||||
[AS_HELP_STRING([--enable-pthread], [support for pthread])],
|
[AS_HELP_STRING([--enable-pthread], [support for pthread])],
|
||||||
[], [enable_pthread=no])
|
[], [enable_pthread=no])
|
||||||
AS_IF([test "x$enable_pthread" != xno],
|
AS_IF([test "x$enable_pthread" != xno],
|
||||||
[AC_CHECK_LIB([pthread], [pthread_mutex_trylock],
|
[AC_CHECK_LIB([pthread], [pthread_mutex_trylock],,
|
||||||
[
|
|
||||||
AC_DEFINE([HAVE_PTHREAD],[1],[pthread is present])
|
|
||||||
LDFLAGS="${LDFLAGS} -pthread"
|
|
||||||
],
|
|
||||||
[AC_MSG_ERROR([pthread library not found])]
|
[AC_MSG_ERROR([pthread library not found])]
|
||||||
)],
|
)],
|
||||||
)
|
)
|
||||||
|
|
|
@ -637,7 +637,7 @@ typedef struct n2n_resolve_ip_sock {
|
||||||
typedef struct n2n_resolve_parameter {
|
typedef struct n2n_resolve_parameter {
|
||||||
n2n_resolve_ip_sock_t *list; /* pointer to list of to be resolved nodes */
|
n2n_resolve_ip_sock_t *list; /* pointer to list of to be resolved nodes */
|
||||||
uint8_t changed; /* indicates a change */
|
uint8_t changed; /* indicates a change */
|
||||||
#ifdef HAVE_PTHREAD
|
#ifdef HAVE_LIBPTHREAD
|
||||||
pthread_t id; /* thread id */
|
pthread_t id; /* thread id */
|
||||||
pthread_mutex_t access; /* mutex for shared access */
|
pthread_mutex_t access; /* mutex for shared access */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1642,14 +1642,14 @@ void update_supernode_reg (n2n_edge_t * eee, time_t now) {
|
||||||
--(eee->sup_attempts);
|
--(eee->sup_attempts);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAVE_PTHREAD
|
#ifndef HAVE_LIBPTHREAD
|
||||||
if(supernode2sock(&(eee->curr_sn->sock), eee->curr_sn->ip_addr) == 0) {
|
if(supernode2sock(&(eee->curr_sn->sock), eee->curr_sn->ip_addr) == 0) {
|
||||||
#endif
|
#endif
|
||||||
traceEvent(TRACE_INFO, "registering with supernode [%s][number of supernodes %d][attempts left %u]",
|
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);
|
supernode_ip(eee), HASH_COUNT(eee->conf.supernodes), (unsigned int)eee->sup_attempts);
|
||||||
|
|
||||||
send_register_super(eee);
|
send_register_super(eee);
|
||||||
#ifndef HAVE_PTHREAD
|
#ifndef HAVE_LIBPTHREAD
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
12
src/n2n.c
12
src/n2n.c
|
@ -30,6 +30,10 @@
|
||||||
#include "sn_selection.h" // for sn_selection_criterion_default
|
#include "sn_selection.h" // for sn_selection_criterion_default
|
||||||
#include "uthash.h" // for UT_hash_handle, HASH_DEL, HASH_ITER, HAS...
|
#include "uthash.h" // for UT_hash_handle, HASH_DEL, HASH_ITER, HAS...
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBPTHREAD
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2def.h>
|
#include <ws2def.h>
|
||||||
|
@ -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_THREAD_RETURN_DATATYPE resolve_thread(N2N_THREAD_PARAMETER_DATATYPE p) {
|
||||||
|
|
||||||
n2n_resolve_parameter_t *param = (n2n_resolve_parameter_t*)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) {
|
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;
|
struct peer_info *sn, *tmp_sn;
|
||||||
n2n_resolve_ip_sock_t *entry;
|
n2n_resolve_ip_sock_t *entry;
|
||||||
int ret;
|
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) {
|
void resolve_cancel_thread (n2n_resolve_parameter_t *param) {
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD
|
#ifdef HAVE_LIBPTHREAD
|
||||||
pthread_cancel(param->id);
|
pthread_cancel(param->id);
|
||||||
free(param);
|
free(param);
|
||||||
#endif
|
#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 */
|
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_resolve_ip_sock_t *entry, *tmp_entry;
|
||||||
n2n_sock_str_t sock_buf;
|
n2n_sock_str_t sock_buf;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user