Commit 3c7f3525 authored by Brian Wellington's avatar Brian Wellington
Browse files

single-threaded versions.

parent 9ce78174
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rwlock.h,v 1.13 2000/08/01 01:30:42 tale Exp $ */
/* $Id: rwlock.h,v 1.14 2000/08/29 00:33:36 bwelling Exp $ */
#ifndef ISC_RWLOCK_H
#define ISC_RWLOCK_H 1
......@@ -31,6 +31,7 @@ typedef enum {
isc_rwlocktype_write
} isc_rwlocktype_t;
#ifdef ISC_PLATFORM_USETHREADS
struct isc_rwlock {
/* Unlocked. */
unsigned int magic;
......@@ -46,6 +47,14 @@ struct isc_rwlock {
unsigned int read_quota;
unsigned int write_quota;
};
#else /* ISC_PLATFORM_USETHREADS */
struct isc_rwlock {
unsigned int magic;
isc_rwlocktype_t type;
unsigned int active;
};
#endif /* ISC_PLATFORM_USETHREADS */
isc_result_t
isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
......
......@@ -15,19 +15,22 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rwlock.c,v 1.24 2000/08/26 01:31:50 bwelling Exp $ */
/* $Id: rwlock.c,v 1.25 2000/08/29 00:33:35 bwelling Exp $ */
#include <config.h>
#include <stddef.h>
#include <isc/magic.h>
#include <isc/platform.h>
#include <isc/rwlock.h>
#include <isc/util.h>
#define RWLOCK_MAGIC 0x52574C6BU /* RWLk. */
#define VALID_RWLOCK(rwl) ISC_MAGIC_VALID(rwl, RWLOCK_MAGIC)
#ifdef ISC_PLATFORM_USETHREADS
#ifndef RWLOCK_DEFAULT_READ_QUOTA
#define RWLOCK_DEFAULT_READ_QUOTA 4
#endif
......@@ -233,3 +236,59 @@ isc_rwlock_destroy(isc_rwlock_t *rwl) {
(void)isc_condition_destroy(&rwl->writeable);
DESTROYLOCK(&rwl->lock);
}
#else /* ISC_PLATFORM_USETHREADS */
isc_result_t
isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
unsigned int write_quota)
{
REQUIRE(rwl != NULL);
UNUSED(read_quota);
UNUSED(write_quota);
rwl->type = isc_rwlocktype_read;
rwl->active = 0;
rwl->magic = RWLOCK_MAGIC;
return (ISC_R_SUCCESS);
}
isc_result_t
isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
REQUIRE(VALID_RWLOCK(rwl));
if (type == isc_rwlocktype_read) {
if (rwl->type != isc_rwlocktype_read && rwl->active != 0)
return (ISC_R_LOCKBUSY);
rwl->type = isc_rwlocktype_read;
rwl->active++;
} else {
if (rwl->active != 0)
return (ISC_R_LOCKBUSY);
rwl->type = isc_rwlocktype_write;
rwl->active = 1;
}
return (ISC_R_SUCCESS);
}
isc_result_t
isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
REQUIRE(VALID_RWLOCK(rwl));
REQUIRE(rwl->type == type);
INSIST(rwl->active > 0);
rwl->active--;
return (ISC_R_SUCCESS);
}
void
isc_rwlock_destroy(isc_rwlock_t *rwl) {
REQUIRE(rwl != NULL);
REQUIRE(rwl->active == 0);
rwl->magic = 0;
}
#endif /* ISC_PLATFORM_USETHREADS */
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