Merge branch '1064-fix-pthread-rwlock' into 'master'
Resolve "Adding --enable-pthread-rwlock broke Windows build" Closes #1064 See merge request isc-projects/bind9!2009
This commit is contained in:
@@ -15649,6 +15649,10 @@ $as_echo "#define USE_PTHREAD_RWLOCK 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
|
||||
if test "$enable_pthread_rwlock" = "yes" -a "$enable_developer" != "yes"; then :
|
||||
as_fn_error $? "pthread rwlock is not meant used in production and the developer mode must be enabled" "$LINENO" 5
|
||||
fi
|
||||
|
||||
CRYPTO=OpenSSL
|
||||
|
||||
#
|
||||
|
||||
@@ -747,6 +747,9 @@ AS_IF([test "$enable_pthread_rwlock" = "yes"],
|
||||
AC_DEFINE([USE_PTHREAD_RWLOCK],[1],[Define if you want to use pthread rwlock implementation])
|
||||
])
|
||||
|
||||
AS_IF([test "$enable_pthread_rwlock" = "yes" -a "$enable_developer" != "yes"],
|
||||
[AC_MSG_ERROR([pthread rwlock is not meant used in production and the developer mode must be enabled])])
|
||||
|
||||
CRYPTO=OpenSSL
|
||||
|
||||
#
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#define ISC_RWLOCK_H 1
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <pthread.h>
|
||||
|
||||
/*! \file isc/rwlock.h */
|
||||
|
||||
@@ -33,6 +32,7 @@ typedef enum {
|
||||
} isc_rwlocktype_t;
|
||||
|
||||
#if USE_PTHREAD_RWLOCK
|
||||
#include <pthread.h>
|
||||
|
||||
struct isc_rwlock {
|
||||
pthread_rwlock_t rwlock;
|
||||
|
||||
+6
-5
@@ -53,10 +53,10 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
while (true) {
|
||||
REQUIRE(pthread_rwlock_wrlock(&rwl->rwlock) == 0);
|
||||
/* Unlock if in middle of downgrade operation */
|
||||
if (atomic_load_release(&rwl->downgrade)) {
|
||||
if (atomic_load_acquire(&rwl->downgrade)) {
|
||||
REQUIRE(pthread_rwlock_unlock(&rwl->rwlock)
|
||||
== 0);
|
||||
while (atomic_load(&rwl->downgrade));
|
||||
while (atomic_load_acquire(&rwl->downgrade));
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@@ -78,7 +78,7 @@ isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
break;
|
||||
case isc_rwlocktype_write:
|
||||
ret = pthread_rwlock_trywrlock(&rwl->rwlock);
|
||||
if ((ret == 0) && atomic_load(&rwl->downgrade)) {
|
||||
if ((ret == 0) && atomic_load_acquire(&rwl->downgrade)) {
|
||||
isc_rwlock_unlock(rwl, type);
|
||||
return (ISC_R_LOCKBUSY);
|
||||
}
|
||||
@@ -104,15 +104,16 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
|
||||
isc_result_t
|
||||
isc_rwlock_tryupgrade(isc_rwlock_t *rwl) {
|
||||
UNUSED(rwl);
|
||||
return (ISC_R_LOCKBUSY);
|
||||
}
|
||||
|
||||
void
|
||||
isc_rwlock_downgrade(isc_rwlock_t *rwl) {
|
||||
atomic_store_acquire(&rwl->downgrade, true);
|
||||
atomic_store_release(&rwl->downgrade, true);
|
||||
isc_rwlock_unlock(rwl, isc_rwlocktype_write);
|
||||
isc_rwlock_lock(rwl, isc_rwlocktype_read);
|
||||
atomic_store_acquire(&rwl->downgrade, false);
|
||||
atomic_store_release(&rwl->downgrade, false);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user