mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-08 23:42:06 -04:00
lib/dns/lib.c: use isc_refcount_t
This commit is contained in:
parent
3dece71b91
commit
8a128151f9
1 changed files with 13 additions and 21 deletions
|
|
@ -18,6 +18,7 @@
|
|||
#include <isc/mem.h>
|
||||
#include <isc/mutex.h>
|
||||
#include <isc/once.h>
|
||||
#include <isc/refcount.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/db.h>
|
||||
|
|
@ -43,8 +44,7 @@ static isc_once_t init_once = ISC_ONCE_INIT;
|
|||
static isc_mem_t *dns_g_mctx = NULL;
|
||||
static dns_dbimplementation_t *dbimp = NULL;
|
||||
static bool initialize_done = false;
|
||||
static isc_mutex_t reflock;
|
||||
static unsigned int references = 0;
|
||||
static isc_refcount_t references = 0;
|
||||
|
||||
static void
|
||||
initialize(void) {
|
||||
|
|
@ -64,8 +64,6 @@ initialize(void) {
|
|||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup_db;
|
||||
|
||||
isc_mutex_init(&reflock);
|
||||
|
||||
initialize_done = true;
|
||||
return;
|
||||
|
||||
|
|
@ -93,29 +91,23 @@ dns_lib_init(void) {
|
|||
if (!initialize_done)
|
||||
return (ISC_R_FAILURE);
|
||||
|
||||
LOCK(&reflock);
|
||||
references++;
|
||||
UNLOCK(&reflock);
|
||||
isc_refcount_increment(&references);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
dns_lib_shutdown(void) {
|
||||
bool cleanup_ok = false;
|
||||
if (isc_refcount_decrement(&references) == 1) {
|
||||
dst_lib_destroy();
|
||||
|
||||
LOCK(&reflock);
|
||||
if (--references == 0)
|
||||
cleanup_ok = true;
|
||||
UNLOCK(&reflock);
|
||||
isc_refcount_destroy(&references);
|
||||
|
||||
if (!cleanup_ok)
|
||||
return;
|
||||
|
||||
dst_lib_destroy();
|
||||
|
||||
if (dbimp != NULL)
|
||||
dns_ecdb_unregister(&dbimp);
|
||||
if (dns_g_mctx != NULL)
|
||||
isc_mem_detach(&dns_g_mctx);
|
||||
if (dbimp != NULL) {
|
||||
dns_ecdb_unregister(&dbimp);
|
||||
}
|
||||
if (dns_g_mctx != NULL) {
|
||||
isc_mem_detach(&dns_g_mctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue