Index: trunk/aclocal.m4
===================================================================
--- trunk/aclocal.m4	(revision 138)
+++ trunk/aclocal.m4	(revision 139)
@@ -1794,4 +1794,19 @@
         fi
 
+        # Detect PTHREAD_MUTEX_RECURSIVE
+	AC_MSG_CHECKING([for recursive mutexes])
+	mutex_recursive=no
+	AC_TRY_LINK([
+#define _XOPEN_SOURCE 500
+#include <pthread.h>], [
+pthread_mutexattr_t   mta;
+pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
+return 0;],[mutex_recursive=yes])
+	if test "x$mutex_recursive" = "xyes"
+	then
+	  AC_DEFINE(HAVE_PTHREAD_MUTEX_RECURSIVE,1,[Define if you have recursive mutexes.])
+	fi
+        AC_MSG_RESULT($mutex_recursive)
+
         LIBS="$save_LIBS"
         CFLAGS="$save_CFLAGS"
Index: trunk/include/sh_pthread.h
===================================================================
--- trunk/include/sh_pthread.h	(revision 138)
+++ trunk/include/sh_pthread.h	(revision 139)
@@ -36,5 +36,5 @@
  * ----   Recursive mutex  ----
  */
-#if defined(PTHREAD_MUTEX_RECURSIVE)
+#if defined(HAVE_PTHREAD_MUTEX_RECURSIVE)
 
 /* On GNU C, it's an enum, thus the alternative implementation 
Index: trunk/src/sh_mem.c
===================================================================
--- trunk/src/sh_mem.c	(revision 138)
+++ trunk/src/sh_mem.c	(revision 139)
@@ -19,4 +19,8 @@
 
 #include "config_xor.h"
+
+#if defined(HAVE_PTHREAD_MUTEX_RECURSIVE)
+#define _XOPEN_SOURCE 500
+#endif
 
 #include <stdio.h>
Index: trunk/src/sh_pthread.c
===================================================================
--- trunk/src/sh_pthread.c	(revision 138)
+++ trunk/src/sh_pthread.c	(revision 139)
@@ -15,5 +15,5 @@
 }
 
-
+#if !defined(HAVE_PTHREAD_MUTEX_RECURSIVE)
 /**
  * libxml2 threads.c: set of generic threading related routines 
@@ -73,2 +73,5 @@
 }
 #endif
+
+
+#endif
