diff --git a/lib/isc/include/isc/rwlock.h b/lib/isc/include/isc/rwlock.h index 155d62b20a..0313c050c2 100644 --- a/lib/isc/include/isc/rwlock.h +++ b/lib/isc/include/isc/rwlock.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rwlock.h,v 1.17 2001/01/09 21:57:30 bwelling Exp $ */ +/* $Id: rwlock.h,v 1.18 2001/03/08 00:55:15 tale Exp $ */ #ifndef ISC_RWLOCK_H #define ISC_RWLOCK_H 1 @@ -28,7 +28,8 @@ ISC_LANG_BEGINDECLS typedef enum { - isc_rwlocktype_read = 0, + isc_rwlocktype_none = 0, + isc_rwlocktype_read, isc_rwlocktype_write } isc_rwlocktype_t; @@ -73,6 +74,9 @@ isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota, isc_result_t isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type); +isc_result_t +isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type); + isc_result_t isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type); diff --git a/lib/isc/rwlock.c b/lib/isc/rwlock.c index 754c9b6646..b2b0cdcb80 100644 --- a/lib/isc/rwlock.c +++ b/lib/isc/rwlock.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rwlock.c,v 1.28 2001/02/07 20:03:23 gson Exp $ */ +/* $Id: rwlock.c,v 1.29 2001/03/08 00:55:13 tale Exp $ */ #include @@ -125,8 +125,8 @@ isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota, return (ISC_R_SUCCESS); } -isc_result_t -isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { +static isc_result_t +doit(isc_rwlock_t *rwl, isc_rwlocktype_t type, isc_boolean_t nonblock) { isc_boolean_t skip = ISC_FALSE; isc_boolean_t done = ISC_FALSE; @@ -153,6 +153,8 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { rwl->active++; rwl->granted++; done = ISC_TRUE; + } else if (nonblock) { + return (ISC_R_LOCKBUSY); } else { skip = ISC_FALSE; rwl->readers_waiting++; @@ -169,6 +171,8 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { rwl->active = 1; rwl->granted++; done = ISC_TRUE; + } else if (nonblock) { + return (ISC_R_LOCKBUSY); } else { skip = ISC_FALSE; rwl->writers_waiting++; @@ -188,6 +192,16 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { return (ISC_R_SUCCESS); } +isc_result_t +isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { + return (doit(rwl, type, ISC_FALSE)); +} + +isc_result_t +isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { + return (doit(rwl, type, ISC_TRUE)); +} + isc_result_t isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { @@ -296,6 +310,11 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { return (ISC_R_SUCCESS); } +isc_result_t +isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { + return (isc_rwlock_lock(rwl, type))g; +} + isc_result_t isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { REQUIRE(VALID_RWLOCK(rwl));