summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2008-02-07 13:11:39 +0000
committerBenny Prijono <bennylp@teluu.com>2008-02-07 13:11:39 +0000
commit56886ef4b648760667743506f4f7bed9830798e8 (patch)
tree33d43a16fe1cf5c26afae53de0dc0bf8e8478bba /pjlib
parenta50cf4e4adc531db5edd98ec99bb358b397c8557 (diff)
Ticket #470, #471, and #472: Compile error when semaphore.h is not present, Compilation error if pthread_mutexattr_set_type() is not present, and Problem with setting up FD_SETSIZE
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1783 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/include/pj/compat/os_auto.h.in14
-rw-r--r--pjlib/include/pj/config.h40
-rw-r--r--pjlib/include/pj/sock_select.h2
-rw-r--r--pjlib/src/pj/os_core_unix.c24
-rw-r--r--pjlib/src/pj/sock_select.c7
5 files changed, 69 insertions, 18 deletions
diff --git a/pjlib/include/pj/compat/os_auto.h.in b/pjlib/include/pj/compat/os_auto.h.in
index 49cc0fdb..32952c8f 100644
--- a/pjlib/include/pj/compat/os_auto.h.in
+++ b/pjlib/include/pj/compat/os_auto.h.in
@@ -54,6 +54,7 @@
#undef PJ_HAS_NETINET_IP_H
#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
#undef PJ_HAS_STDDEF_H
@@ -79,6 +80,19 @@
#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.
* Default: 0
*/
diff --git a/pjlib/include/pj/config.h b/pjlib/include/pj/config.h
index d620d4b7..fc08ed74 100644
--- a/pjlib/include/pj/config.h
+++ b/pjlib/include/pj/config.h
@@ -485,13 +485,6 @@
* underlying I/O queue impelementation, but still, developers should be
* 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
# if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
@@ -538,16 +531,41 @@
/**
+ * 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
+#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
+
/**
* Has semaphore functionality?
*
diff --git a/pjlib/include/pj/sock_select.h b/pjlib/include/pj/sock_select.h
index 8ce7a65b..ff5459b6 100644
--- a/pjlib/include/pj/sock_select.h
+++ b/pjlib/include/pj/sock_select.h
@@ -54,7 +54,7 @@ PJ_BEGIN_DECL
*/
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;
diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c
index 5a246df5..1fe5253b 100644
--- a/pjlib/src/pj/os_core_unix.c
+++ b/pjlib/src/pj/os_core_unix.c
@@ -34,7 +34,7 @@
#include <pj/except.h>
#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
@@ -948,21 +948,29 @@ static pj_status_t init_mutex(pj_mutex_t *mutex, const char *name, int type)
return PJ_RETURN_OS_ERROR(rc);
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
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
#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;
#else
@@ -1239,7 +1247,11 @@ PJ_DEF(pj_bool_t) pj_mutex_is_locked(pj_mutex_t *mutex)
* RTEMS). Otherwise use POSIX rwlock.
*/
#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
{
diff --git a/pjlib/src/pj/sock_select.c b/pjlib/src/pj/sock_select.c
index 566050ef..b3743b93 100644
--- a/pjlib/src/pj/sock_select.c
+++ b/pjlib/src/pj/sock_select.c
@@ -35,6 +35,13 @@
# 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
+
#define PART_FDSET(ps) ((fd_set*)&ps->data[1])
#define PART_FDSET_OR_NULL(ps) (ps ? PART_FDSET(ps) : NULL)
#define PART_COUNT(ps) (ps->data[0])