Add configure option to disable pthreads support

This commit is contained in:
Rich Fought 2012-10-26 12:19:26 -07:00
parent 609b47961b
commit a8ef3525c8
2 changed files with 28 additions and 2 deletions

View file

@ -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])

View file

@ -27,7 +27,11 @@
* ~~~~
*/
#include "defs.h"
#ifndef DISABLE_PTHREADS
#include <pthread.h>
#endif
#include <netlink-local.h>
#include <netlink/netlink.h>
@ -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
}
/**