diff --git a/lib/isc/include/isc/quota.h b/lib/isc/include/isc/quota.h index a16e0964ae..079a5c9cc8 100644 --- a/lib/isc/include/isc/quota.h +++ b/lib/isc/include/isc/quota.h @@ -87,6 +87,21 @@ isc_quota_release(isc_quota_t *quota); * Release one unit of quota. */ +isc_result_t +isc_quota_attach(isc_quota_t *quota, isc_quota_t **p); +/* + * Like isc_quota_reserve, and also attaches '*p' to the + * quota if successful. + */ + +void +isc_quota_detach(isc_quota_t **p); +/* + * Like isc_quota_release, and also detaches '*p' from the + * quota. + */ + + ISC_LANG_ENDDECLS #endif /* ISC_QUOTA_H */ diff --git a/lib/isc/quota.c b/lib/isc/quota.c index add4d6eb86..69a6ef1703 100644 --- a/lib/isc/quota.c +++ b/lib/isc/quota.c @@ -55,4 +55,22 @@ isc_quota_release(isc_quota_t *quota) { UNLOCK("a->lock); } +isc_result_t +isc_quota_attach(isc_quota_t *quota, isc_quota_t **p) +{ + isc_result_t result; + INSIST(p != NULL && *p == NULL); + result = isc_quota_reserve(quota); + if (result != ISC_R_SUCCESS) + return (result); + *p = quota; + return (ISC_R_SUCCESS); +} +void +isc_quota_detach(isc_quota_t **p) +{ + INSIST(p != NULL && *p != NULL); + isc_quota_release(*p); + *p = NULL; +}