From: Wouter Wijngaards Date: Fri, 7 Sep 2007 13:28:23 +0000 (+0000) Subject: rwlock optional. X-Git-Tag: release-0.5~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0b919360397cd7dea3bd2d657fff14e3cff8e24;p=thirdparty%2Funbound.git rwlock optional. git-svn-id: file:///svn/unbound/trunk@606 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/configure.ac b/configure.ac index ae8d442a8..ec1f728a0 100644 --- a/configure.ac +++ b/configure.ac @@ -407,7 +407,7 @@ if test x_$withval != x_no; then CFLAGS="$CFLAGS $PTHREAD_CFLAGS" CC="$PTHREAD_CC" ub_have_pthreads=yes - AC_CHECK_TYPES(pthread_spinlock_t,,,[#include ]) + AC_CHECK_TYPES([pthread_spinlock_t, pthread_rwlock_t],,,[#include ]) ]) fi diff --git a/util/locks.h b/util/locks.h index 32aafc723..19f8b13bb 100644 --- a/util/locks.h +++ b/util/locks.h @@ -91,6 +91,23 @@ /******************* PTHREAD ************************/ +/** use pthread mutex for basic lock */ +typedef pthread_mutex_t lock_basic_t; +/** small front for pthread init func, NULL is default attrs. */ +#define lock_basic_init(lock) LOCKRET(pthread_mutex_init(lock, NULL)) +#define lock_basic_destroy(lock) LOCKRET(pthread_mutex_destroy(lock)) +#define lock_basic_lock(lock) LOCKRET(pthread_mutex_lock(lock)) +#define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock)) + +#ifndef HAVE_PTHREAD_RWLOCK_T +/** in case rwlocks are not supported, use a mutex. */ +typedef pthread_mutex_t lock_rw_t; +#define lock_rw_init(lock) LOCKRET(pthread_mutex_init(lock, NULL)) +#define lock_rw_destroy(lock) LOCKRET(pthread_mutex_destroy(lock)) +#define lock_rw_rdlock(lock) LOCKRET(pthread_mutex_lock(lock)) +#define lock_rw_wrlock(lock) LOCKRET(pthread_mutex_lock(lock)) +#define lock_rw_unlock(lock) LOCKRET(pthread_mutex_unlock(lock)) +#else /* HAVE_PTHREAD_RWLOCK_T */ /** we use the pthread rwlock */ typedef pthread_rwlock_t lock_rw_t; /** small front for pthread init func, NULL is default attrs. */ @@ -99,14 +116,7 @@ typedef pthread_rwlock_t lock_rw_t; #define lock_rw_rdlock(lock) LOCKRET(pthread_rwlock_rdlock(lock)) #define lock_rw_wrlock(lock) LOCKRET(pthread_rwlock_wrlock(lock)) #define lock_rw_unlock(lock) LOCKRET(pthread_rwlock_unlock(lock)) - -/** use pthread mutex for basic lock */ -typedef pthread_mutex_t lock_basic_t; -/** small front for pthread init func, NULL is default attrs. */ -#define lock_basic_init(lock) LOCKRET(pthread_mutex_init(lock, NULL)) -#define lock_basic_destroy(lock) LOCKRET(pthread_mutex_destroy(lock)) -#define lock_basic_lock(lock) LOCKRET(pthread_mutex_lock(lock)) -#define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock)) +#endif /* HAVE_PTHREAD_RWLOCK_T */ #ifndef HAVE_PTHREAD_SPINLOCK_T /** in case spinlocks are not supported, use a mutex. */