diff --git a/lib/dns/lib.c b/lib/dns/lib.c index 4454fcff5f..8d51a0a762 100644 --- a/lib/dns/lib.c +++ b/lib/dns/lib.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -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); + } + } }