* 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. */
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) {
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++;
print_lock("preunlock", rwl, type);
#endif
+ INSIST(rwl->active > 0);
rwl->active--;
if (rwl->active == 0) {
if (rwl->type == isc_rwlocktype_read) {
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