2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 13:08:06 +00:00

added non-blocking locking, isc_rwlock_trylock()

This commit is contained in:
David Lawrence 2001-03-08 00:55:15 +00:00
parent 668f06c071
commit a82fd2c01b
2 changed files with 28 additions and 5 deletions

View File

@ -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);

View File

@ -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 <config.h>
@ -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));