mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
Use simple pthread_rwlock in place of our custom adaptive rwlock
This commit is contained in:
parent
158ab9afd4
commit
64fbffbbaa
@ -309,6 +309,9 @@
|
|||||||
/* Have PTHREAD_PRIO_INHERIT. */
|
/* Have PTHREAD_PRIO_INHERIT. */
|
||||||
#undef 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. */
|
/* Define to 1 if you have the `pthread_setaffinity_np' function. */
|
||||||
#undef HAVE_PTHREAD_SETAFFINITY_NP
|
#undef HAVE_PTHREAD_SETAFFINITY_NP
|
||||||
|
|
||||||
|
15
configure
vendored
15
configure
vendored
@ -15615,12 +15615,17 @@ $as_echo "no" >&6; }
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
#
|
for ac_func in pthread_rwlock_rdlock
|
||||||
# If PIC is disabled, shared libraries must also be
|
do :
|
||||||
#
|
ac_fn_c_check_func "$LINENO" "pthread_rwlock_rdlock" "ac_cv_func_pthread_rwlock_rdlock"
|
||||||
if test "$pic_mode" = "no"; then :
|
if test "x$ac_cv_func_pthread_rwlock_rdlock" = xyes; then :
|
||||||
enable_shared="no"
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_PTHREAD_RWLOCK_RDLOCK 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
CRYPTO=OpenSSL
|
CRYPTO=OpenSSL
|
||||||
|
|
||||||
|
@ -733,11 +733,7 @@ case $use_libtool in
|
|||||||
esac
|
esac
|
||||||
AC_SUBST(INSTALL_LIBRARY)
|
AC_SUBST(INSTALL_LIBRARY)
|
||||||
|
|
||||||
#
|
AC_CHECK_FUNCS([pthread_rwlock_rdlock])
|
||||||
# If PIC is disabled, shared libraries must also be
|
|
||||||
#
|
|
||||||
AS_IF([test "$pic_mode" = "no"],
|
|
||||||
[enable_shared="no"])
|
|
||||||
|
|
||||||
CRYPTO=OpenSSL
|
CRYPTO=OpenSSL
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#define ISC_RWLOCK_H 1
|
#define ISC_RWLOCK_H 1
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
/*! \file isc/rwlock.h */
|
/*! \file isc/rwlock.h */
|
||||||
|
|
||||||
@ -31,6 +32,14 @@ typedef enum {
|
|||||||
isc_rwlocktype_write
|
isc_rwlocktype_write
|
||||||
} isc_rwlocktype_t;
|
} isc_rwlocktype_t;
|
||||||
|
|
||||||
|
#if HAVE_PTHREAD_RWLOCK_RDLOCK
|
||||||
|
|
||||||
|
struct isc_rwlock {
|
||||||
|
pthread_rwlock_t rwlock;
|
||||||
|
};
|
||||||
|
|
||||||
|
#else /* HAVE_PTHREAD_RWLOCK_RDLOCK */
|
||||||
|
|
||||||
struct isc_rwlock {
|
struct isc_rwlock {
|
||||||
/* Unlocked. */
|
/* Unlocked. */
|
||||||
unsigned int magic;
|
unsigned int magic;
|
||||||
@ -68,6 +77,8 @@ struct isc_rwlock {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /* HAVE_PTHREAD_RWLOCK_RDLOCK */
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
|
isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
|
||||||
unsigned int write_quota);
|
unsigned int write_quota);
|
||||||
|
@ -27,6 +27,78 @@
|
|||||||
#include <isc/rwlock.h>
|
#include <isc/rwlock.h>
|
||||||
#include <isc/util.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 RWLOCK_MAGIC ISC_MAGIC('R', 'W', 'L', 'k')
|
||||||
#define VALID_RWLOCK(rwl) ISC_MAGIC_VALID(rwl, RWLOCK_MAGIC)
|
#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);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_PTHREAD_RWLOCK_RDLOCK */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user