]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
If there are no writers waiting, always let new readers in. Also change the
authorBrian Wellington <source@isc.org>
Sun, 30 Jul 2000 17:57:48 +0000 (17:57 +0000)
committerBrian Wellington <source@isc.org>
Sun, 30 Jul 2000 17:57:48 +0000 (17:57 +0000)
hardcoded default read and write quota values to #defines.

lib/isc/rwlock.c

index a85ded04e3270ae00a68e6eaec4ca1307e797252..0b39d4704b06c1e311d3e2e52c40008e48fb0db8 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: rwlock.c,v 1.17 2000/07/27 09:51:10 tale Exp $ */
+/* $Id: rwlock.c,v 1.18 2000/07/30 17:57:48 bwelling Exp $ */
 
 #include <config.h>
 
 #define RWLOCK_MAGIC           0x52574C6BU     /* RWLk. */
 #define VALID_RWLOCK(rwl)      ISC_MAGIC_VALID(rwl, RWLOCK_MAGIC)
 
+#ifndef RWLOCK_DEFAULT_READ_QUOTA
+#define RWLOCK_DEFAULT_READ_QUOTA 4
+#endif
+
+#ifndef RWLOCK_DEFAULT_WRITE_QUOTA
+#define RWLOCK_DEFAULT_WRITE_QUOTA 4
+#endif
+
 #ifdef ISC_RWLOCK_TRACE
 #include <stdio.h>             /* Required for fprintf/stderr. */
 
@@ -61,10 +69,10 @@ isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
        rwl->readers_waiting = 0;
        rwl->writers_waiting = 0;
        if (read_quota == 0)
-               read_quota = 4;
+               read_quota = RWLOCK_DEFAULT_READ_QUOTA;
        rwl->read_quota = read_quota;
        if (write_quota == 0)
-               write_quota = 4;
+               write_quota = RWLOCK_DEFAULT_WRITE_QUOTA;
        rwl->write_quota = write_quota;
        result = isc_mutex_init(&rwl->lock);
        if (result != ISC_R_SUCCESS) {
@@ -112,8 +120,10 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
                while (!done) {
                        if (!skip &&
                            ((rwl->active == 0 ||
+                             rwl->writers_waiting == 0 ||
                              (rwl->type == isc_rwlocktype_read &&
-                              rwl->granted < rwl->read_quota)))) {
+                              rwl->granted < rwl->read_quota))))
+                       {
                                rwl->type = isc_rwlocktype_read;
                                rwl->active++;
                                rwl->granted++;
@@ -165,6 +175,7 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
        print_lock("preunlock", rwl, type);
 #endif
 
+       INSIST(rwl->active > 0);
        rwl->active--;
        if (rwl->active == 0) {
                if (rwl->type == isc_rwlocktype_read) {
@@ -193,14 +204,6 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
                                rwl->granted = 0;
                        }
                }
-       } else {
-               if (rwl->type == isc_rwlocktype_read &&
-                   rwl->writers_waiting == 0) {
-                       INSIST(rwl->granted > 0);
-                       rwl->granted--;
-                       if (rwl->readers_waiting > 0)
-                               SIGNAL(&rwl->readable);
-               }
        }
 
 #ifdef ISC_RWLOCK_TRACE