From d6a8a0c37b972a8da54e09f7de9aa2974d2e9f67 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Tue, 20 Feb 2007 13:25:29 +0000 Subject: [PATCH] Solaris threads support. git-svn-id: file:///svn/unbound/trunk@130 be551aaa-1e26-0410-a405-d3ace91eadb9 --- configure.ac | 35 +++++++++++++++++++++++--------- doc/Changelog | 1 + util/locks.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 78 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 89fc0fe5c..3370fb9df 100644 --- a/configure.ac +++ b/configure.ac @@ -349,11 +349,10 @@ AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname], AC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT]) # check for thread library. -AC_ARG_WITH(pthreads, - AC_HELP_STRING([--with-pthreads], [use pthreads library, or --without--pthreads to disable threading support.]), [ - ],[ - withval="yes" -]) +AC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads], + [use pthreads library, or --without--pthreads to disable threading support.]), + [ ],[ withval="yes" ]) +ub_have_pthreads=no if test x_$withval != x_no; then sinclude(acx_pthread.m4) ACX_PTHREAD([ @@ -361,16 +360,34 @@ if test x_$withval != x_no; then LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" CC="$PTHREAD_CC" + ub_have_pthreads=yes AC_CHECK_TYPES(pthread_spinlock_t,,,[#include ]) ]) fi +# check solaris thread library +AC_ARG_WITH(solaris-threads, AC_HELP_STRING([--with-solaris-threads], + [use solaris native thread library.]), [ ],[ withval="no" ]) +if test x_$withval != x_no; then + if test x_$ub_have_pthreads != x_no; then + AC_WARN([Have pthreads already, ignoring --with-solaris-threads]) + else + AC_SEARCH_LIBS(thr_create, [thread], + [ + AC_DEFINE(HAVE_SOLARIS_THREADS, 1, [Using Solaris threads]) + + CHECK_COMPILER_FLAG(mt, [CFLAGS="$CFLAGS -mt"], + [CFLAGS="$CFLAGS -D_REENTRANT"]) + ] , [ + AC_ERROR([no solaris threads found.]) + ]) + fi +fi + # check for libevent AC_ARG_WITH(libevent, AC_HELP_STRING([--with-libevent=pathname], - [set path to libevent (will check /usr/local /usr/lib /usr/pkg /usr/sfw /usr)]),[ - ],[ - withval="yes" - ]) + [set path to libevent (will check /usr/local /usr/lib /usr/pkg /usr/sfw /usr)]), + [ ],[ withval="yes" ]) if test x_$withval != x_no; then AC_MSG_CHECKING(for libevent) if test x_$withval = x_ -o x_$withval = x_yes; then diff --git a/doc/Changelog b/doc/Changelog index 2000bd224..fee01c2cf 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,6 @@ 20 February 2007: Wouter - Added locks code and pthread spinlock detection. + - can use no locks, or solaris native thread library. 19 February 2007: Wouter - Created 0.0 svn tag. diff --git a/util/locks.h b/util/locks.h index eab783b24..bb8eaef66 100644 --- a/util/locks.h +++ b/util/locks.h @@ -67,11 +67,13 @@ if( (err=(func)) != 0) \ log_err("%s at %d could not " #func ": %s", \ __FILE__, __LINE__, strerror(err)); \ - } while(0) + } while(0) #ifdef HAVE_PTHREAD #include +/******************* PTHREAD ************************/ + /** we use the pthread rwlock */ typedef pthread_rwlock_t lock_rw_t; /** small front for pthread init func, NULL is default attrs. */ @@ -96,7 +98,7 @@ typedef pthread_mutex_t lock_basic_t; /** unlock acquired lock. */ #define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock)) -#ifdef HAVE_PTHREAD_SPINLOCK_T +#ifndef HAVE_PTHREAD_SPINLOCK_T /** in case spinlocks are not supported, use a mutex. */ typedef pthread_mutex_t lock_quick_t; /** small front for pthread init func, NULL is default attrs. */ @@ -133,9 +135,52 @@ typedef pthread_t ub_thread_t; /** Pass where to store tread_t in thr. Use default NULL attributes. */ #define ub_thread_create(thr, func, arg) LOCKRET(pthread_create(thr, NULL, func, arg)) -#else /* HAVE_PTHREAD */ - -/** In case there is no pthread support, define locks to do nothing */ +#else /* we do not HAVE_PTHREAD */ +#ifdef HAVE_SOLARIS_THREADS + +/******************* SOLARIS THREADS ************************/ +typedef rwlock_t lock_rw_t; +/** create thisprocessonly lock */ +#define lock_rw_init(lock) LOCKRET(rwlock_init(lock, USYNC_THREAD, NULL)) +/** destroy it */ +#define lock_rw_destroy(lock) LOCKRET(rwlock_destroy(lock)) +/** lock read */ +#define lock_rw_rdlock(lock) LOCKRET(rw_rdlock(lock)) +/** lock write */ +#define lock_rw_wrlock(lock) LOCKRET(rw_wrlock(lock)) +/** unlock */ +#define lock_rw_unlock(lock) LOCKRET(rw_unlock(lock)) + +/** use basic mutex */ +typedef mutex_t lock_basic_t; +/** create */ +#define lock_basic_init(lock) LOCKRET(mutex_init(lock, USYNC_THREAD, NULL)) +/** destroy */ +#define lock_basic_destroy(lock) LOCKRET(mutex_destroy(lock)) +/** lock */ +#define lock_basic_lock(lock) LOCKRET(mutex_lock(lock)) +/** unlock */ +#define lock_basic_unlock(lock) LOCKRET(mutex_unlock(lock)) + +/** No spinlocks in solaris threads API. Use a mutex. */ +typedef mutex_t lock_quick_t; +/** create */ +#define lock_quick_init(lock) LOCKRET(mutex_init(lock, USYNC_THREAD, NULL)) +/** destroy */ +#define lock_quick_destroy(lock) LOCKRET(mutex_destroy(lock)) +/** lock */ +#define lock_quick_lock(lock) LOCKRET(mutex_lock(lock)) +/** unlock */ +#define lock_quick_unlock(lock) LOCKRET(mutex_unlock(lock)) + +/** Thread creation, create a default thread. */ +typedef thread_t ub_thread_t; +#define ub_thread_create(thr, func, arg) LOCKRET(thr_create(NULL, NULL, func, arg, NULL, thr)) + +#else /* we do not HAVE_SOLARIS_THREADS and no PTHREADS */ + +/******************* NO THREADS ************************/ +/** In case there is no thread support, define locks to do nothing */ typedef int lock_rw_t; /** does nothing */ #define lock_rw_init(lock) /* nop */ @@ -177,5 +222,6 @@ typedef int ub_thread_t; fatal_exit("%s %d called thread create, but no thread support " \ "has been compiled in.", __FILE__, __LINE__) +#endif /* HAVE_SOLARIS_THREADS */ #endif /* HAVE_PTHREAD */ #endif /* UTIL_LOCKS_H */ -- 2.47.2