]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Solaris threads support.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 20 Feb 2007 13:25:29 +0000 (13:25 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 20 Feb 2007 13:25:29 +0000 (13:25 +0000)
git-svn-id: file:///svn/unbound/trunk@130 be551aaa-1e26-0410-a405-d3ace91eadb9

configure.ac
doc/Changelog
util/locks.h

index 89fc0fe5c435610abd67e3ca8c44e6a73ecea412..3370fb9df0e602d507248b8f1479cc470e057489 100644 (file)
@@ -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 <pthread.h>])
                ])
 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
index 2000bd224140772638d2a8125823aaacf7c82cbb..fee01c2cfac998dff56c0fd80793082a08412e12 100644 (file)
@@ -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.
index eab783b2423146020cda1f1199ed215a333d6ff8..bb8eaef669bece0dd50ae51bdc7c4c430b265a0b 100644 (file)
        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.h>
 
+/******************* 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 */