From a8ef3525c89b0a2049abedd2a0b2d54f0d574476 Mon Sep 17 00:00:00 2001 From: Rich Fought Date: Fri, 26 Oct 2012 12:19:26 -0700 Subject: [PATCH] Add configure option to disable pthreads support --- configure.in | 14 ++++++++++++-- lib/socket.c | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index 79cd93f..9a190c2 100644 --- a/configure.in +++ b/configure.in @@ -41,7 +41,7 @@ m4_define([libnl_lt_age], [11]) m4_define([libnl_version], [libnl_major_version.libnl_minor_version.libnl_micro_version]) -AC_INIT(libnl, [libnl_version], [http://www.infradead.org/~tgr/libnl/]) +AC_INIT(libnl, [libnl_version], [], [], [http://www.infradead.org/~tgr/libnl/]) AC_CONFIG_HEADERS([lib/defs.h]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) @@ -83,8 +83,18 @@ AC_ARG_ENABLE([cli], [enable_cli="$enableval"], [enable_cli="yes"]) AM_CONDITIONAL([ENABLE_CLI], [test "$enable_cli" = "yes"]) +AC_ARG_ENABLE([pthreads], + AS_HELP_STRING([--disable-pthreads], [Disable pthreads support]), + [enable_pthreads="$enableval"], [enable_pthreads="yes"]) +AM_CONDITIONAL([DISABLE_PTHREADS], [test "$enable_pthreads" = "no"]) + AC_CHECK_LIB([m], [pow], [], AC_MSG_ERROR([libm is required])) -AC_CHECK_LIB([pthread], [pthread_mutex_lock], [], AC_MSG_ERROR([libpthread is required])) + +if test "x$enable_pthreads" = "xno"; then + AC_DEFINE([DISABLE_PTHREADS], [1], [Define to 1 to disable pthreads]) +else + AC_CHECK_LIB([pthread], [pthread_mutex_lock], [], AC_MSG_ERROR([libpthread is required])) +fi AC_CONFIG_SUBDIRS([doc]) diff --git a/lib/socket.c b/lib/socket.c index d53a714..4e1d84c 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -27,7 +27,11 @@ * ~~~~ */ +#include "defs.h" + +#ifndef DISABLE_PTHREADS #include +#endif #include #include @@ -57,14 +61,18 @@ static void __init init_default_cb(void) } static uint32_t used_ports_map[32]; +#ifndef DISABLE_PTHREADS static pthread_mutex_t port_map_mutex = PTHREAD_MUTEX_INITIALIZER; +#endif static uint32_t generate_local_port(void) { int i, n; uint32_t pid = getpid() & 0x3FFFFF; +#ifndef DISABLE_PTHREADS pthread_mutex_lock(&port_map_mutex); +#endif for (i = 0; i < 32; i++) { if (used_ports_map[i] == 0xFFFFFFFF) @@ -80,13 +88,17 @@ static uint32_t generate_local_port(void) /* PID_MAX_LIMIT is currently at 2^22, leaving 10 bit * to, i.e. 1024 unique ports per application. */ +#ifndef DISABLE_PTHREADS pthread_mutex_unlock(&port_map_mutex); +#endif return pid + (n << 22); } } +#ifndef DISABLE_PTHREADS pthread_mutex_unlock(&port_map_mutex); +#endif /* Out of sockets in our own PID namespace, what to do? FIXME */ return UINT_MAX; @@ -101,9 +113,13 @@ static void release_local_port(uint32_t port) nr = port >> 22; +#ifndef DISABLE_PTHREADS pthread_mutex_lock(&port_map_mutex); +#endif used_ports_map[nr / 32] &= ~(1 << (nr % 32)); +#ifndef DISABLE_PTHREADS pthread_mutex_unlock(&port_map_mutex); +#endif } /**