Index: /pjproject/trunk/aconfigure
===================================================================
--- /pjproject/trunk/aconfigure	(revision 1782)
+++ /pjproject/trunk/aconfigure	(revision 1783)
@@ -1,5 +1,5 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for pjproject 0.7.
+# Generated by GNU Autoconf 2.61 for pjproject 0.8.
 #
 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -573,6 +573,6 @@
 PACKAGE_NAME='pjproject'
 PACKAGE_TARNAME='pjproject'
-PACKAGE_VERSION='0.7'
-PACKAGE_STRING='pjproject 0.7'
+PACKAGE_VERSION='0.8'
+PACKAGE_STRING='pjproject 0.8'
 PACKAGE_BUGREPORT=''
 
@@ -1213,5 +1213,5 @@
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures pjproject 0.7 to adapt to many kinds of systems.
+\`configure' configures pjproject 0.8 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1279,5 +1279,5 @@
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of pjproject 0.7:";;
+     short | recursive ) echo "Configuration of pjproject 0.8:";;
    esac
   cat <<\_ACEOF
@@ -1377,5 +1377,5 @@
 if $ac_init_version; then
   cat <<\_ACEOF
-pjproject configure 0.7
+pjproject configure 0.8
 generated by GNU Autoconf 2.61
 
@@ -1391,5 +1391,5 @@
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by pjproject $as_me 0.7, which was
+It was created by pjproject $as_me 0.8, which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
@@ -6574,4 +6574,137 @@
 
 
+if test "${ac_cv_header_semaphore_h+set}" = set; then
+  { echo "$as_me:$LINENO: checking for semaphore.h" >&5
+echo $ECHO_N "checking for semaphore.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_semaphore_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_semaphore_h" >&5
+echo "${ECHO_T}$ac_cv_header_semaphore_h" >&6; }
+else
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking semaphore.h usability" >&5
+echo $ECHO_N "checking semaphore.h usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <semaphore.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking semaphore.h presence" >&5
+echo $ECHO_N "checking semaphore.h presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <semaphore.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: semaphore.h: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: semaphore.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: semaphore.h: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: semaphore.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: semaphore.h: present but cannot be compiled" >&5
+echo "$as_me: WARNING: semaphore.h: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: semaphore.h:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: semaphore.h:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: semaphore.h: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: semaphore.h: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: semaphore.h:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: semaphore.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: semaphore.h: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: semaphore.h: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: semaphore.h: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: semaphore.h: in the future, the compiler will take precedence" >&2;}
+
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for semaphore.h" >&5
+echo $ECHO_N "checking for semaphore.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_semaphore_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_header_semaphore_h=$ac_header_preproc
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_semaphore_h" >&5
+echo "${ECHO_T}$ac_cv_header_semaphore_h" >&6; }
+
+fi
+if test $ac_cv_header_semaphore_h = yes; then
+  cat >>confdefs.h <<\_ACEOF
+#define PJ_HAS_SEMAPHORE_H 1
+_ACEOF
+
+fi
+
+
 if test "${ac_cv_header_setjmp_h+set}" = set; then
   { echo "$as_me:$LINENO: checking for setjmp.h" >&5
@@ -9556,4 +9689,5 @@
 _ACEOF
 
+		   ac_rwmutex="yes"
   		   { echo "$as_me:$LINENO: result: yes" >&5
 echo "${ECHO_T}yes" >&6; }
@@ -9566,5 +9700,165 @@
 _ACEOF
 
+		   ac_rwmutex="no"
 		   { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test "$ac_rwmutex" = "no"; then
+    { echo "$as_me:$LINENO: checking if pthread_rwlock_t is available with _POSIX_READER_WRITER_LOCKS" >&5
+echo $ECHO_N "checking if pthread_rwlock_t is available with _POSIX_READER_WRITER_LOCKS... $ECHO_C" >&6; }
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#define _POSIX_READER_WRITER_LOCKS
+					 #include <pthread.h>
+int
+main ()
+{
+pthread_rwlock_t *x;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  cat >>confdefs.h <<\_ACEOF
+#define PJ_EMULATE_RWMUTEX 0
+_ACEOF
+
+		       CFLAGS="$CFLAGS -D_POSIX_THREADS -D_POSIX_READER_WRITER_LOCKS"
+		       { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	cat >>confdefs.h <<\_ACEOF
+#define PJ_EMULATE_RWMUTEX 1
+_ACEOF
+
+		       { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+{ echo "$as_me:$LINENO: checking if pthread_mutexattr_settype() is available" >&5
+echo $ECHO_N "checking if pthread_mutexattr_settype() is available... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <pthread.h>
+int
+main ()
+{
+pthread_mutexattr_settype(0,PTHREAD_MUTEX_FAST_NP);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  cat >>confdefs.h <<\_ACEOF
+#define PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE 1
+_ACEOF
+
+  		   { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+{ echo "$as_me:$LINENO: checking if pthread_mutexattr_t has recursive member" >&5
+echo $ECHO_N "checking if pthread_mutexattr_t has recursive member... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <pthread.h>
+int
+main ()
+{
+pthread_mutexattr_t attr;
+				     attr.recursive=1;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  cat >>confdefs.h <<\_ACEOF
+#define PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE 1
+_ACEOF
+
+  		   { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6; }
 fi
@@ -11193,5 +11487,5 @@
 # values after options handling.
 ac_log="
-This file was extended by pjproject $as_me 0.7, which was
+This file was extended by pjproject $as_me 0.8, which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
@@ -11242,5 +11536,5 @@
 cat >>$CONFIG_STATUS <<_ACEOF
 ac_cs_version="\\
-pjproject config.status 0.7
+pjproject config.status 0.8
 configured by $0, generated by GNU Autoconf 2.61,
   with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
Index: /pjproject/trunk/aconfigure.ac
===================================================================
--- /pjproject/trunk/aconfigure.ac	(revision 1782)
+++ /pjproject/trunk/aconfigure.ac	(revision 1783)
@@ -1,3 +1,3 @@
-AC_INIT(pjproject,0.7)
+AC_INIT(pjproject,0.8)
 
 host_orig="$host"
@@ -147,4 +147,5 @@
 AC_CHECK_HEADER(net/if.h,[AC_DEFINE(PJ_HAS_NET_IF_H,1)])
 AC_CHECK_HEADER(ifaddrs.h,[AC_DEFINE(PJ_HAS_IFADDRS_H,1)])
+AC_CHECK_HEADER(semaphore.h,[AC_DEFINE(PJ_HAS_SEMAPHORE_H,1)])
 AC_CHECK_HEADER(setjmp.h,[AC_DEFINE(PJ_HAS_SETJMP_H,1)])
 AC_CHECK_HEADER(stdarg.h,[AC_DEFINE(PJ_HAS_STDARG_H,1)])
@@ -269,7 +270,40 @@
 		    		   [pthread_rwlock_t *x;])],
 		  [AC_DEFINE(PJ_EMULATE_RWMUTEX,0)
+		   ac_rwmutex="yes"
   		   AC_MSG_RESULT(yes)],
 		  [AC_DEFINE(PJ_EMULATE_RWMUTEX,1)
+		   ac_rwmutex="no"
 		   AC_MSG_RESULT(no)])
+
+dnl # If rwmutex is not detected, check again but this time
+dnl # with _POSIX_READER_WRITER_LOCKS defined (newlib needs this)
+if test "$ac_rwmutex" = "no"; then
+    AC_MSG_CHECKING([if pthread_rwlock_t is available with _POSIX_READER_WRITER_LOCKS])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#define _POSIX_READER_WRITER_LOCKS
+					 #include <pthread.h>]],
+				       [pthread_rwlock_t *x;])],
+		      [AC_DEFINE(PJ_EMULATE_RWMUTEX,0)
+		       CFLAGS="$CFLAGS -D_POSIX_THREADS -D_POSIX_READER_WRITER_LOCKS"
+		       AC_MSG_RESULT(yes)],
+		      [AC_DEFINE(PJ_EMULATE_RWMUTEX,1)
+		       AC_MSG_RESULT(no)])
+fi
+
+dnl # Do we have pthread_mutexattr_settype()?
+AC_MSG_CHECKING([if pthread_mutexattr_settype() is available])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
+		    		   [pthread_mutexattr_settype(0,PTHREAD_MUTEX_FAST_NP);])],
+		  [AC_DEFINE(PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE,1)
+  		   AC_MSG_RESULT(yes)],
+		  [AC_MSG_RESULT(no)])
+
+dnl # Does pthread_mutexattr_t has "recursive" member?
+AC_MSG_CHECKING([if pthread_mutexattr_t has recursive member])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
+		    		   [[pthread_mutexattr_t attr;
+				     attr.recursive=1;]])],
+		  [AC_DEFINE(PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE,1)
+  		   AC_MSG_RESULT(yes)],
+		  [AC_MSG_RESULT(no)])
 
 AC_SUBST(ac_os_objs)
Index: /pjproject/trunk/pjlib/include/pj/compat/os_auto.h.in
===================================================================
--- /pjproject/trunk/pjlib/include/pj/compat/os_auto.h.in	(revision 1782)
+++ /pjproject/trunk/pjlib/include/pj/compat/os_auto.h.in	(revision 1783)
@@ -55,4 +55,5 @@
 #undef PJ_HAS_NET_IF_H
 #undef PJ_HAS_IFADDRS_H
+#undef PJ_HAS_SEMAPHORE_H
 #undef PJ_HAS_SETJMP_H
 #undef PJ_HAS_STDARG_H
@@ -79,4 +80,17 @@
 #undef PJ_SOCK_HAS_INET_NTOP
 #undef PJ_SOCK_HAS_GETADDRINFO
+
+/* On these OSes, semaphore feature depends on semaphore.h */
+#if defined(PJ_HAS_SEMAPHORE_H) && PJ_HAS_SEMAPHORE_H!=0
+#   define PJ_HAS_SEMAPHORE	1
+#else
+#   define PJ_HAS_SEMAPHORE	0
+#endif
+
+/* Do we have pthread_mutexattr_settype()? */
+#undef PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE
+
+/* Does pthread_mutexattr_t has "recursive" member?  */
+#undef PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE
 
 /* Set 1 if native sockaddr_in has sin_len member. 
Index: /pjproject/trunk/pjlib/include/pj/config.h
===================================================================
--- /pjproject/trunk/pjlib/include/pj/config.h	(revision 1782)
+++ /pjproject/trunk/pjlib/include/pj/config.h	(revision 1783)
@@ -486,11 +486,4 @@
  * aware of this constant, to make sure that the program will not break when
  * the underlying implementation changes.
- *
- * For implementation based on select(), the value here will be used as the
- * maximum number of socket handles passed to select() (i.e. FD_SETSIZE will 
- * be set to this value).
- *
- * Default: if FD_SETSIZE is defined and the value is greather than 256,
- *          then it will be used.  Otherwise 256 (64 for WinCE).
  */
 #ifndef PJ_IOQUEUE_MAX_HANDLES
@@ -539,13 +532,38 @@
 
 /**
+ * Determine if FD_SETSIZE is changeable/set-able. If so, then we will
+ * set it to PJ_IOQUEUE_MAX_HANDLES.
+ */
+/* This is awful, as we should actually check for __GLIBC__ rather than
+ * __GNUC__. But alas! Libc headers are not included yet at this stage.
+ */
+#ifdef __GNUC__
+#   define PJ_FD_SETSIZE_SETABLE	0
+#else
+#   define PJ_FD_SETSIZE_SETABLE	1
+#endif
+
+/**
  * Overrides FD_SETSIZE so it is consistent throughout the library.
- * OS specific configuration header (compat/os_*) might have declared
- * FD_SETSIZE, thus we only set if it hasn't been declared.
+ * We only do this if we detected that FD_SETSIZE is changeable.
  *
  * Default: #PJ_IOQUEUE_MAX_HANDLES
  */
-#ifndef FD_SETSIZE
-#  define FD_SETSIZE		    PJ_IOQUEUE_MAX_HANDLES
-#endif
+#if PJ_FD_SETSIZE_SETABLE
+    /* Only override FD_SETSIZE if the value has not been set */
+#   ifndef FD_SETSIZE
+#	define FD_SETSIZE		PJ_IOQUEUE_MAX_HANDLES
+#   endif
+#else
+    /* When FD_SETSIZE is not changeable, check if PJ_IOQUEUE_MAX_HANDLES
+     * is lower than FD_SETSIZE value.
+     */
+#   ifdef FD_SETSIZE
+#	if PJ_IOQUEUE_MAX_HANDLES > FD_SETSIZE
+#	    error "PJ_IOQUEUE_MAX_HANDLES is greater than FD_SETSIZE"
+#	endif
+#   endif
+#endif
+
 
 /**
Index: /pjproject/trunk/pjlib/include/pj/sock_select.h
===================================================================
--- /pjproject/trunk/pjlib/include/pj/sock_select.h	(revision 1782)
+++ /pjproject/trunk/pjlib/include/pj/sock_select.h	(revision 1783)
@@ -55,5 +55,5 @@
 typedef struct pj_fd_set_t
 {
-    pj_sock_t	data[FD_SETSIZE + 4];   /**< Opaque buffer for fd_set */
+    pj_sock_t data[PJ_IOQUEUE_MAX_HANDLES+ 4]; /**< Opaque buffer for fd_set */
 } pj_fd_set_t;
 
Index: /pjproject/trunk/pjlib/src/pj/os_core_unix.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/os_core_unix.c	(revision 1782)
+++ /pjproject/trunk/pjlib/src/pj/os_core_unix.c	(revision 1783)
@@ -35,5 +35,5 @@
 #include <pj/errno.h>
 
-#if defined(PJ_HAS_SEMAPHORE) && PJ_HAS_SEMAPHORE != 0
+#if defined(PJ_HAS_SEMAPHORE_H) && PJ_HAS_SEMAPHORE_H != 0
 #  include <semaphore.h>
 #endif
@@ -949,7 +949,9 @@
 
     if (type == PJ_MUTEX_SIMPLE) {
-#if defined(PJ_LINUX) && PJ_LINUX!=0
+#if (defined(PJ_LINUX) && PJ_LINUX!=0) || \
+    defined(PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE)
 	rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP);
-#elif defined(PJ_RTEMS) && PJ_RTEMS!=0
+#elif (defined(PJ_RTEMS) && PJ_RTEMS!=0) || \
+       defined(PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE)
 	/* Nothing to do, default is simple */
 #else
@@ -957,11 +959,17 @@
 #endif
     } else {
-#if defined(PJ_LINUX) && PJ_LINUX!=0
+#if (defined(PJ_LINUX) && PJ_LINUX!=0) || \
+     defined(PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE)
 	rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
-#elif defined(PJ_RTEMS) && PJ_RTEMS!=0
+#elif (defined(PJ_RTEMS) && PJ_RTEMS!=0) || \
+       defined(PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE)
 	// Phil Torre <ptorre@zetron.com>:
 	// The RTEMS implementation of POSIX mutexes doesn't include 
 	// pthread_mutexattr_settype(), so what follows is a hack
 	// until I get RTEMS patched to support the set/get functions.
+	//
+	// More info:
+	//   newlib's pthread also lacks pthread_mutexattr_settype(),
+	//   but it seems to have mutexattr.recursive.
 	PJ_TODO(FIX_RTEMS_RECURSIVE_MUTEX_TYPE)
 	attr.recursive = 1;
@@ -1240,5 +1248,9 @@
  */
 #if defined(PJ_EMULATE_RWMUTEX) && PJ_EMULATE_RWMUTEX!=0
-#  include "os_rwmutex.c"
+    /* We need semaphore functionality to emulate rwmutex */
+#   if !defined(PJ_HAS_SEMAPHORE) || PJ_HAS_SEMAPHORE==0
+#	error "Semaphore support needs to be enabled to emulate rwmutex"
+#   endif
+#   include "os_rwmutex.c"
 #else
 struct pj_rwmutex_t
Index: /pjproject/trunk/pjlib/src/pj/sock_select.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/sock_select.c	(revision 1782)
+++ /pjproject/trunk/pjlib/src/pj/sock_select.c	(revision 1783)
@@ -34,4 +34,11 @@
 #   pragma warning(disable: 4018)    // Signed/unsigned mismatch in FD_*
 #   pragma warning(disable: 4389)    // Signed/unsigned mismatch in FD_*
+#endif
+
+/* Now that we have access to OS'es <sys/select>, lets check again that
+ * PJ_IOQUEUE_MAX_HANDLES is not greater than FD_SETSIZE
+ */
+#if PJ_IOQUEUE_MAX_HANDLES > FD_SETSIZE
+#   error "PJ_IOQUEUE_MAX_HANDLES cannot be greater than FD_SETSIZE"
 #endif
 
