rwlock.c revision f5ad7569cbaa87d85ebf126e1c7753aa196247d6
/*
* Copyright (C) 1998-2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rwlock.c,v 1.23 2000/08/24 23:26:13 bwelling Exp $ */
#include <config.h>
#include <stddef.h>
#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
static void
"rwlock %p thread %lu %s(%s): %s, %u active, %u granted, "
}
#endif
unsigned int write_quota)
{
/*
* In case there's trouble initializing, we zero magic now. If all
* goes well, we'll set it to RWLOCK_MAGIC.
*/
rwl->readers_waiting = 0;
rwl->writers_waiting = 0;
if (read_quota == 0)
if (write_quota == 0)
if (result != ISC_R_SUCCESS) {
"isc_mutex_init() failed: %s",
return (ISC_R_UNEXPECTED);
}
if (result != ISC_R_SUCCESS) {
"isc_condition_init(readable) failed: %s",
return (ISC_R_UNEXPECTED);
}
if (result != ISC_R_SUCCESS) {
"isc_condition_init(writeable) failed: %s",
return (ISC_R_UNEXPECTED);
}
return (ISC_R_SUCCESS);
}
#ifdef ISC_RWLOCK_TRACE
#endif
if (type == isc_rwlocktype_read) {
if (rwl->readers_waiting != 0)
while (!done) {
if (!skip &&
(rwl->writers_waiting == 0 ||
{
} else {
rwl->readers_waiting++;
rwl->readers_waiting--;
}
}
} else {
if (rwl->writers_waiting != 0)
while (!done) {
} else {
rwl->writers_waiting++;
rwl->writers_waiting--;
}
}
}
#ifdef ISC_RWLOCK_TRACE
#endif
return (ISC_R_SUCCESS);
}
#ifdef ISC_RWLOCK_TRACE
#endif
if (rwl->writers_waiting > 0) {
} else if (rwl->readers_waiting > 0) {
/* Does this case ever happen? */
}
} else {
if (rwl->readers_waiting > 0) {
if (rwl->writers_waiting > 0 &&
} else {
}
} else if (rwl->writers_waiting > 0) {
} else {
}
}
}
#ifdef ISC_RWLOCK_TRACE
#endif
return (ISC_R_SUCCESS);
}
void
rwl->readers_waiting == 0 &&
rwl->writers_waiting == 0);
}