mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
added non-blocking locking, isc_rwlock_trylock()
This commit is contained in:
parent
668f06c071
commit
a82fd2c01b
@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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
|
#ifndef ISC_RWLOCK_H
|
||||||
#define ISC_RWLOCK_H 1
|
#define ISC_RWLOCK_H 1
|
||||||
@ -28,7 +28,8 @@
|
|||||||
ISC_LANG_BEGINDECLS
|
ISC_LANG_BEGINDECLS
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
isc_rwlocktype_read = 0,
|
isc_rwlocktype_none = 0,
|
||||||
|
isc_rwlocktype_read,
|
||||||
isc_rwlocktype_write
|
isc_rwlocktype_write
|
||||||
} isc_rwlocktype_t;
|
} isc_rwlocktype_t;
|
||||||
|
|
||||||
@ -73,6 +74,9 @@ isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
|
|||||||
isc_result_t
|
isc_result_t
|
||||||
isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type);
|
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_result_t
|
||||||
isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type);
|
isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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>
|
#include <config.h>
|
||||||
|
|
||||||
@ -125,8 +125,8 @@ isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
|
|||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_result_t
|
static isc_result_t
|
||||||
isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
doit(isc_rwlock_t *rwl, isc_rwlocktype_t type, isc_boolean_t nonblock) {
|
||||||
isc_boolean_t skip = ISC_FALSE;
|
isc_boolean_t skip = ISC_FALSE;
|
||||||
isc_boolean_t done = 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->active++;
|
||||||
rwl->granted++;
|
rwl->granted++;
|
||||||
done = ISC_TRUE;
|
done = ISC_TRUE;
|
||||||
|
} else if (nonblock) {
|
||||||
|
return (ISC_R_LOCKBUSY);
|
||||||
} else {
|
} else {
|
||||||
skip = ISC_FALSE;
|
skip = ISC_FALSE;
|
||||||
rwl->readers_waiting++;
|
rwl->readers_waiting++;
|
||||||
@ -169,6 +171,8 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
|||||||
rwl->active = 1;
|
rwl->active = 1;
|
||||||
rwl->granted++;
|
rwl->granted++;
|
||||||
done = ISC_TRUE;
|
done = ISC_TRUE;
|
||||||
|
} else if (nonblock) {
|
||||||
|
return (ISC_R_LOCKBUSY);
|
||||||
} else {
|
} else {
|
||||||
skip = ISC_FALSE;
|
skip = ISC_FALSE;
|
||||||
rwl->writers_waiting++;
|
rwl->writers_waiting++;
|
||||||
@ -188,6 +192,16 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
|||||||
return (ISC_R_SUCCESS);
|
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_result_t
|
||||||
isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
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);
|
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_result_t
|
||||||
isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||||
REQUIRE(VALID_RWLOCK(rwl));
|
REQUIRE(VALID_RWLOCK(rwl));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user