]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
lib/dns/lib.c: use isc_refcount_t
authorOndřej Surý <ondrej@sury.org>
Mon, 20 May 2019 14:41:36 +0000 (16:41 +0200)
committerWitold Kręcicki <wpk@isc.org>
Tue, 9 Jul 2019 14:09:36 +0000 (16:09 +0200)
lib/dns/lib.c

index 4454fcff5f05c5ab4a76c2a3dd0b64fc324cbdf5..8d51a0a762e21b1abd217e7576eafc759f42a158 100644 (file)
@@ -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;
-
-       LOCK(&reflock);
-       if (--references == 0)
-               cleanup_ok = true;
-       UNLOCK(&reflock);
-
-       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 (isc_refcount_decrement(&references) == 1) {
+               dst_lib_destroy();
+
+               isc_refcount_destroy(&references);
+
+               if (dbimp != NULL) {
+                       dns_ecdb_unregister(&dbimp);
+               }
+               if (dns_g_mctx != NULL) {
+                       isc_mem_detach(&dns_g_mctx);
+               }
+       }
 }