Commit 64fbffbb authored by Ondřej Surý's avatar Ondřej Surý

Use simple pthread_rwlock in place of our custom adaptive rwlock

parent 158ab9af
......@@ -309,6 +309,9 @@
/* 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
......
......@@ -15615,12 +15615,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
......
......@@ -733,11 +733,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
......
......@@ -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);
......
......@@ -27,6 +27,78 @@
#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) {
return (ISC_R_LOCKBUSY);
}
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)
......@@ -549,3 +621,5 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
return (ISC_R_SUCCESS);
}
#endif /* HAVE_PTHREAD_RWLOCK_RDLOCK */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment