Hi,

Posting to the list before committing since this may be a little bit
controversial.

The patch adds a new argument to the --enable-threads option, which
enables a nptl-only build of apr. This enables the build process to make
better assumptions regarding the behavior (and speed) of a few lock
primitives (ie: apr_posixsem_is_global, much faster on nptl for
inter-process mutexes).

The patch still needs some tweaking here and there, but any comments or
feedback would be greatly appreciated.

--
Davi Arnaut
Index: apr/include/apr.h.in
===================================================================
--- apr.orig/include/apr.h.in
+++ apr/include/apr.h.in
@@ -221,6 +221,7 @@ extern "C" {
 #define APR_HAVE_UNION_SEMUN    @have_union_semun@
 #define APR_HAVE_SCTP           @have_sctp@
 #define APR_HAVE_IOVEC          @have_iovec@
+#define APR_HAVE_NPTL           @nptl@
 
 /*  APR Feature Macros */
 #define APR_HAS_SHARED_MEMORY     @sharedmem@
Index: apr/configure.in
===================================================================
--- apr.orig/configure.in
+++ apr/configure.in
@@ -554,6 +554,8 @@ esac
 dnl ----------------------------- Checking for Threads
 echo "${nl}Checking for Threads..."
 
+nptl="0"
+
 if test -z "$enable_threads"; then
        AC_ARG_ENABLE(threads,
        [  --enable-threads        Enable threading support in APR.],
@@ -584,6 +586,28 @@ else
         threads="1"
         pthreadh="0"
         pthreadser="0"
+    elif test "$enable_threads" = "nptl" &&
+         test "$build_os" = "linux-gnu"; then
+      APR_PTHREADS_CHECK_SAVE
+      APR_PTHREADS_CHECK
+      APR_CHECK_PTHREADS_H([
+          threads="1"
+          pthreadh="1"
+          pthreadser="1" ], [
+          threads="0"
+          pthreadh="0"
+          pthreadser="0"
+          APR_PTHREADS_CHECK_RESTORE ] )
+      AC_MSG_CHECKING(if libpthread is NPTL)
+        case `getconf GNU_LIBPTHREAD_VERSION` in *NPTL*) nptl="1";; esac
+        if test "$nptl" = 1; then
+            AC_MSG_RESULT(yes)
+            APR_SETIFNULL(apr_posixsem_is_global, [yes])
+        else
+            AC_MSG_ERROR([not NPTL])
+        fi
+    elif test "$enable_threads" = "nptl"; then
+        AC_MSG_ERROR(NPTL flag is only valid when building on linux-gnu)
     else
 # We basically specified that we wanted threads, but not how to implement
 # them.  In this case, just look for pthreads.  In the future, we can check
@@ -683,6 +707,7 @@ case $host in
 esac
 
 AC_SUBST(threads)
+AC_SUBST(nptl)
 AC_SUBST(have_sigsuspend)
 AC_SUBST(have_sigwait)
 
Index: apr/misc/unix/start.c
===================================================================
--- apr.orig/misc/unix/start.c
+++ apr/misc/unix/start.c
@@ -38,6 +38,22 @@ APR_DECLARE(apr_status_t) apr_app_initia
 
 static int initialized = 0;
 
+#if APR_HAVE_NPTL
+static int is_runtime_nptl(void)
+{
+    apr_size_t n;
+    char version[512];
+
+    n = confstr(_CS_GNU_LIBPTHREAD_VERSION, version, sizeof(version));
+
+    if (n < 1 || (strstr(version, "NPTL") == NULL)) {
+        return 0;
+    }
+
+    return 1;
+}
+#endif
+
 APR_DECLARE(apr_status_t) apr_initialize(void)
 {
     apr_pool_t *pool;
@@ -47,6 +63,12 @@ APR_DECLARE(apr_status_t) apr_initialize
         return APR_SUCCESS;
     }
 
+#if APR_HAVE_NPTL
+    if (!is_runtime_nptl()) {
+        return APR_ENOTIMPL;
+    }
+#endif
+
 #if !defined(BEOS) && !defined(OS2)
     apr_proc_mutex_unix_setup_lock();
     apr_unix_setup_time();

Reply via email to