Commit eefb0a07 authored by Brian Wellington's avatar Brian Wellington
Browse files

If there are no writers waiting, always let new readers in. Also change the

hardcoded default read and write quota values to #defines.
parent 4eabcbb8
......@@ -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>
......@@ -26,6 +26,14 @@
#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
......
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