rwlock.c revision a3002fd5a23b06733c6a98fd34a417099fe51cc4
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence/*
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * Copyright (C) 1998 Internet Software Consortium.
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence *
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * Permission to use, copy, modify, and distribute this software for any
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * purpose with or without fee is hereby granted, provided that the above
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * copyright notice and this permission notice appear in all copies.
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence *
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * SOFTWARE.
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence */
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <config.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#include <stdio.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#include <isc/assertions.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#include <isc/error.h>
6b7257f756eb0530cdf54df9a7fab8d51a5001c3David Lawrence#include <isc/boolean.h>
6b7257f756eb0530cdf54df9a7fab8d51a5001c3David Lawrence#include <isc/rwlock.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#include "util.h"
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#define RWLOCK_MAGIC 0x52574C6BU /* RWLk. */
f96b41064bcd427d8125a096fd646c1f068d8ed7David Lawrence#define VALID_RWLOCK(rwl) ((rwl) != NULL && \
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (rwl)->magic == RWLOCK_MAGIC)
f96b41064bcd427d8125a096fd646c1f068d8ed7David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#ifdef ISC_RWLOCK_TRACE
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrencestatic void
3db78e0855a8dfc162180880cd70d9c1a03d9301David Lawrenceprint_lock(char *operation, isc_rwlock_t *rwl, isc_rwlocktype_t type) {
3db78e0855a8dfc162180880cd70d9c1a03d9301David Lawrence printf("%s(%s): ", operation,
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence (type == isc_rwlocktype_read ? "read" : "write"));
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence printf("%s, %u active, %u granted",
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence (rwl->type == isc_rwlocktype_read ? "reading" : "writing"),
3db78e0855a8dfc162180880cd70d9c1a03d9301David Lawrence rwl->active, rwl->granted);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence printf(", %u rwaiting, %u wwaiting\n",
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->readers_waiting,
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->writers_waiting);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence}
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#endif
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrenceisc_result_t
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrenceisc_rwlock_init(isc_rwlock_t *rwl,
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence unsigned int read_quota,
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence unsigned int write_quota)
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence{
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence isc_result_t result;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence REQUIRE(rwl != NULL);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence /*
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * In case there's trouble initializing, we zero magic now. If all
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence * goes well, we'll set it to RWLOCK_MAGIC.
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence */
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->magic = 0;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->type = isc_rwlocktype_read;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->active = 0;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->granted = 0;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->readers_waiting = 0;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->writers_waiting = 0;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (read_quota == 0)
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence read_quota = 4;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->read_quota = read_quota;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (write_quota == 0)
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence write_quota = 4;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->write_quota = write_quota;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence result = isc_mutex_init(&rwl->lock);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (result != ISC_R_SUCCESS) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence UNEXPECTED_ERROR(__FILE__, __LINE__,
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence "isc_mutex_init() failed: %s",
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence isc_result_totext(result));
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence return (ISC_R_UNEXPECTED);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence result = isc_condition_init(&rwl->readable);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (result != ISC_R_SUCCESS) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence UNEXPECTED_ERROR(__FILE__, __LINE__,
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence "isc_condition_init(readable) failed: %s",
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence isc_result_totext(result));
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence return (ISC_R_UNEXPECTED);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence result = isc_condition_init(&rwl->writeable);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (result != ISC_R_SUCCESS) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence UNEXPECTED_ERROR(__FILE__, __LINE__,
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence "isc_condition_init(writeable) failed: %s",
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence isc_result_totext(result));
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence return (ISC_R_UNEXPECTED);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->magic = RWLOCK_MAGIC;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence return (ISC_R_SUCCESS);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence}
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrenceisc_result_t
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrenceisc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence isc_boolean_t skip = ISC_FALSE;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence isc_boolean_t done = ISC_FALSE;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence REQUIRE(VALID_RWLOCK(rwl));
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence LOCK(&rwl->lock);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#ifdef ISC_RWLOCK_TRACE
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence print_lock("prelock", rwl, type);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#endif
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (type == isc_rwlocktype_read) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (rwl->readers_waiting != 0)
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence skip = ISC_TRUE;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence while (!done) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (!skip &&
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence ((rwl->active == 0 ||
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence (rwl->type == isc_rwlocktype_read &&
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->granted < rwl->read_quota)))) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->type = isc_rwlocktype_read;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->active++;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->granted++;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence done = ISC_TRUE;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence } else {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence skip = ISC_FALSE;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->readers_waiting++;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence WAIT(&rwl->readable, &rwl->lock);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->readers_waiting--;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence } else {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (rwl->writers_waiting != 0)
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence skip = ISC_TRUE;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence while (!done) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (!skip && rwl->active == 0) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->type = isc_rwlocktype_write;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->active = 1;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->granted++;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence done = ISC_TRUE;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence } else {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence skip = ISC_FALSE;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->writers_waiting++;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence WAIT(&rwl->writeable, &rwl->lock);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->writers_waiting--;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#ifdef ISC_RWLOCK_TRACE
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence print_lock("postlock", rwl, type);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#endif
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence UNLOCK(&rwl->lock);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence return (ISC_R_SUCCESS);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence}
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrenceisc_result_t
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrenceisc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence REQUIRE(VALID_RWLOCK(rwl));
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence LOCK(&rwl->lock);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence REQUIRE(rwl->type == type);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#ifdef ISC_RWLOCK_TRACE
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence print_lock("preunlock", rwl, type);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#endif
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->active--;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (rwl->active == 0) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (rwl->type == isc_rwlocktype_read) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->granted = 0;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (rwl->writers_waiting > 0) {
6e033f89d4f1fcf266e07d91fcabf474af4939a1David Lawrence rwl->type = isc_rwlocktype_write;
6e033f89d4f1fcf266e07d91fcabf474af4939a1David Lawrence SIGNAL(&rwl->writeable);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence } else if (rwl->readers_waiting > 0) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence /* Does this case ever happen? */
6e033f89d4f1fcf266e07d91fcabf474af4939a1David Lawrence BROADCAST(&rwl->readable);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence } else {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (rwl->readers_waiting > 0) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (rwl->writers_waiting > 0 &&
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->granted < rwl->write_quota) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence SIGNAL(&rwl->writeable);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence } else {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->granted = 0;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->type = isc_rwlocktype_read;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence BROADCAST(&rwl->readable);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence } else if (rwl->writers_waiting > 0) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->granted = 0;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence SIGNAL(&rwl->writeable);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence } else {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->granted = 0;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence } else {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence if (rwl->type == isc_rwlocktype_read &&
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->writers_waiting == 0 &&
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->readers_waiting > 0) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence INSIST(rwl->granted > 0);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->granted--;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence SIGNAL(&rwl->readable);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence }
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#ifdef ISC_RWLOCK_TRACE
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence print_lock("postunlock", rwl, type);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#endif
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
3db78e0855a8dfc162180880cd70d9c1a03d9301David Lawrence UNLOCK(&rwl->lock);
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence return (ISC_R_SUCCESS);
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence}
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrencevoid
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrenceisc_rwlock_destroy(isc_rwlock_t *rwl) {
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence REQUIRE(VALID_RWLOCK(rwl));
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence LOCK(&rwl->lock);
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence REQUIRE(rwl->active == 0 &&
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence rwl->readers_waiting == 0 &&
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence rwl->writers_waiting == 0);
94b166ffa58ef0ff263563c0550d0b30eb9f7772David Lawrence UNLOCK(&rwl->lock);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence rwl->magic = 0;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence (void)isc_condition_destroy(&rwl->readable);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence (void)isc_condition_destroy(&rwl->writeable);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence (void)isc_mutex_destroy(&rwl->lock);
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence}
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence