]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use simple pthread_rwlock in place of our custom adaptive rwlock
authorOndřej Surý <ondrej@sury.org>
Thu, 16 Aug 2018 13:03:42 +0000 (15:03 +0200)
committerOndřej Surý <ondrej@sury.org>
Wed, 19 Dec 2018 13:30:56 +0000 (14:30 +0100)
config.h.in
configure
configure.ac
lib/isc/include/isc/rwlock.h
lib/isc/rwlock.c

index 81c5ce8653b460929d5543af2b4cc6547e3f4ae4..108f3359de0c7b1db9597cfb31252d4390402a2c 100644 (file)
 /* Have PTHREAD_PRIO_INHERIT. */
 #undef HAVE_PTHREAD_PRIO_INHERIT
 
+/* Define to 1 if you have the `pthread_rwlock_rdlock' function. */
+#undef HAVE_PTHREAD_RWLOCK_RDLOCK
+
 /* Define to 1 if you have the `pthread_setaffinity_np' function. */
 #undef HAVE_PTHREAD_SETAFFINITY_NP
 
index 6328aece5ccf6e8b65364e6e30ab55cd944c2a92..81eb64a16b9d8b28ffe3a67169eab43b0fbdd576 100755 (executable)
--- a/configure
+++ b/configure
@@ -15309,12 +15309,17 @@ $as_echo "no" >&6; }
 esac
 
 
-#
-# If PIC is disabled, shared libraries must also be
-#
-if test "$pic_mode" = "no"; then :
-  enable_shared="no"
+for ac_func in pthread_rwlock_rdlock
+do :
+  ac_fn_c_check_func "$LINENO" "pthread_rwlock_rdlock" "ac_cv_func_pthread_rwlock_rdlock"
+if test "x$ac_cv_func_pthread_rwlock_rdlock" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_PTHREAD_RWLOCK_RDLOCK 1
+_ACEOF
+
 fi
+done
+
 
 CRYPTO=OpenSSL
 
index df4e281490e878f60b599230ce85186013e4d346..6fe0c7ef1436c3d10f63e62fe4efe81de63c7b3c 100644 (file)
@@ -705,11 +705,7 @@ case $use_libtool in
 esac
 AC_SUBST(INSTALL_LIBRARY)
 
-#
-# If PIC is disabled, shared libraries must also be
-#
-AS_IF([test "$pic_mode" = "no"],
-      [enable_shared="no"])
+AC_CHECK_FUNCS([pthread_rwlock_rdlock])
 
 CRYPTO=OpenSSL
 
index ed1ff66312403ac59224f42e64fe8ab80c612c75..50d06d72d007c782b1b479d37ba64470a9131aff 100644 (file)
@@ -14,6 +14,7 @@
 #define ISC_RWLOCK_H 1
 
 #include <inttypes.h>
+#include <pthread.h>
 
 /*! \file isc/rwlock.h */
 
@@ -31,6 +32,14 @@ typedef enum {
        isc_rwlocktype_write
 } isc_rwlocktype_t;
 
+#if HAVE_PTHREAD_RWLOCK_RDLOCK
+
+struct isc_rwlock {
+       pthread_rwlock_t        rwlock;
+};
+
+#else /* HAVE_PTHREAD_RWLOCK_RDLOCK */
+
 struct isc_rwlock {
        /* Unlocked. */
        unsigned int            magic;
@@ -68,6 +77,8 @@ struct isc_rwlock {
 
 };
 
+#endif /* HAVE_PTHREAD_RWLOCK_RDLOCK */
+
 isc_result_t
 isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
                unsigned int write_quota);
index a914ba4ceea4fc13da2cecda4524823c634939c2..79c344853568c8cd8ec48f1482a5f1999f2aa523 100644 (file)
 #include <isc/rwlock.h>
 #include <isc/util.h>
 
+#if HAVE_PTHREAD_RWLOCK_RDLOCK
+
+#include <errno.h>
+#include <pthread.h>
+
+isc_result_t
+isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
+               unsigned int write_quota)
+{
+       UNUSED(read_quota);
+       UNUSED(write_quota);
+       REQUIRE(pthread_rwlock_init(&rwl->rwlock, NULL) == 0);
+       return (ISC_R_SUCCESS);
+}
+
+isc_result_t
+isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
+       switch (type) {
+       case isc_rwlocktype_read: REQUIRE(pthread_rwlock_rdlock(&rwl->rwlock) == 0); break;
+       case isc_rwlocktype_write: REQUIRE(pthread_rwlock_wrlock(&rwl->rwlock) == 0); break;
+       default: INSIST(0);
+       }
+       return (ISC_R_SUCCESS);
+}
+
+isc_result_t
+isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
+       int ret = 0;
+       switch (type) {
+       case isc_rwlocktype_read:
+               ret = pthread_rwlock_tryrdlock(&rwl->rwlock);
+               break;
+       case isc_rwlocktype_write:
+               ret = pthread_rwlock_trywrlock(&rwl->rwlock);
+               break;
+       default: INSIST(0);
+       }
+
+       switch (ret) {
+       case 0: return (ISC_R_SUCCESS);
+       case EBUSY: return (ISC_R_LOCKBUSY);
+       case EAGAIN: return (ISC_R_LOCKBUSY);
+       default: INSIST(0); ISC_UNREACHABLE();
+       }
+}
+
+
+isc_result_t
+isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
+       UNUSED(type);
+       REQUIRE(pthread_rwlock_unlock(&rwl->rwlock) == 0);
+       return (ISC_R_SUCCESS);
+}
+
+isc_result_t
+isc_rwlock_tryupgrade(isc_rwlock_t *rwl) {
+       isc_rwlock_unlock(rwl, isc_rwlocktype_read);
+       return (isc_rwlock_trylock(rwl, isc_rwlocktype_write));
+}
+
+void
+isc_rwlock_downgrade(isc_rwlock_t *rwl) {
+       isc_rwlock_unlock(rwl, isc_rwlocktype_write);
+       isc_rwlock_lock(rwl, isc_rwlocktype_read);
+}
+
+void
+isc_rwlock_destroy(isc_rwlock_t *rwl) {
+       pthread_rwlock_destroy(&rwl->rwlock);
+}
+
+#else
+
 #define RWLOCK_MAGIC           ISC_MAGIC('R', 'W', 'L', 'k')
 #define VALID_RWLOCK(rwl)      ISC_MAGIC_VALID(rwl, RWLOCK_MAGIC)
 
@@ -558,3 +631,5 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
 
        return (ISC_R_SUCCESS);
 }
+
+#endif /* HAVE_PTHREAD_RWLOCK_RDLOCK */