2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 15:05:23 +00:00

Convert struct dns_view->attributes to atomic_uint to prevent some locking

This commit is contained in:
Ondřej Surý
2019-07-18 14:22:31 +02:00
parent 38270b7900
commit db63c2a700
2 changed files with 14 additions and 20 deletions

View File

@@ -196,9 +196,8 @@ struct dns_view {
/* Locked by themselves. */ /* Locked by themselves. */
isc_refcount_t references; isc_refcount_t references;
isc_refcount_t weakrefs; isc_refcount_t weakrefs;
atomic_uint_fast32_t attributes;
/* Locked by lock. */
unsigned int attributes;
/* Under owner's locking control. */ /* Under owner's locking control. */
ISC_LINK(struct dns_view) link; ISC_LINK(struct dns_view) link;
dns_viewlist_t * viewlist; dns_viewlist_t * viewlist;

View File

@@ -19,6 +19,7 @@
#include <lmdb.h> #include <lmdb.h>
#endif #endif
#include <isc/atomic.h>
#include <isc/file.h> #include <isc/file.h>
#include <isc/hash.h> #include <isc/hash.h>
#include <isc/lex.h> #include <isc/lex.h>
@@ -64,9 +65,9 @@
if (result != ISC_R_SUCCESS) goto cleanup; \ if (result != ISC_R_SUCCESS) goto cleanup; \
} while (0) } while (0)
#define RESSHUTDOWN(v) (((v)->attributes & DNS_VIEWATTR_RESSHUTDOWN) != 0) #define RESSHUTDOWN(v) ((atomic_load(&(v)->attributes) & DNS_VIEWATTR_RESSHUTDOWN) != 0)
#define ADBSHUTDOWN(v) (((v)->attributes & DNS_VIEWATTR_ADBSHUTDOWN) != 0) #define ADBSHUTDOWN(v) ((atomic_load(&(v)->attributes) & DNS_VIEWATTR_ADBSHUTDOWN) != 0)
#define REQSHUTDOWN(v) (((v)->attributes & DNS_VIEWATTR_REQSHUTDOWN) != 0) #define REQSHUTDOWN(v) ((atomic_load(&(v)->attributes) & DNS_VIEWATTR_REQSHUTDOWN) != 0)
#define DNS_VIEW_DELONLYHASH 111 #define DNS_VIEW_DELONLYHASH 111
#define DNS_VIEW_FAILCACHESIZE 1021 #define DNS_VIEW_FAILCACHESIZE 1021
@@ -140,8 +141,9 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
view->task = NULL; view->task = NULL;
isc_refcount_init(&view->references, 1); isc_refcount_init(&view->references, 1);
isc_refcount_init(&view->weakrefs, 1); isc_refcount_init(&view->weakrefs, 1);
view->attributes = (DNS_VIEWATTR_RESSHUTDOWN|DNS_VIEWATTR_ADBSHUTDOWN| atomic_init(&view->attributes, (DNS_VIEWATTR_RESSHUTDOWN |
DNS_VIEWATTR_REQSHUTDOWN); DNS_VIEWATTR_ADBSHUTDOWN |
DNS_VIEWATTR_REQSHUTDOWN));
view->statickeys = NULL; view->statickeys = NULL;
view->dynamickeys = NULL; view->dynamickeys = NULL;
view->matchclients = NULL; view->matchclients = NULL;
@@ -685,10 +687,7 @@ resolver_shutdown(isc_task_t *task, isc_event_t *event) {
isc_event_free(&event); isc_event_free(&event);
LOCK(&view->lock); atomic_fetch_or(&view->attributes, DNS_VIEWATTR_RESSHUTDOWN);
view->attributes |= DNS_VIEWATTR_RESSHUTDOWN;
UNLOCK(&view->lock);
dns_view_weakdetach(&view); dns_view_weakdetach(&view);
} }
@@ -704,9 +703,7 @@ adb_shutdown(isc_task_t *task, isc_event_t *event) {
isc_event_free(&event); isc_event_free(&event);
LOCK(&view->lock); atomic_fetch_or(&view->attributes, DNS_VIEWATTR_ADBSHUTDOWN);
view->attributes |= DNS_VIEWATTR_ADBSHUTDOWN;
UNLOCK(&view->lock);
dns_view_weakdetach(&view); dns_view_weakdetach(&view);
} }
@@ -723,9 +720,7 @@ req_shutdown(isc_task_t *task, isc_event_t *event) {
isc_event_free(&event); isc_event_free(&event);
LOCK(&view->lock); atomic_fetch_or(&view->attributes, DNS_VIEWATTR_REQSHUTDOWN);
view->attributes |= DNS_VIEWATTR_REQSHUTDOWN;
UNLOCK(&view->lock);
dns_view_weakdetach(&view); dns_view_weakdetach(&view);
} }
@@ -775,7 +770,7 @@ dns_view_createresolver(dns_view_t *view,
} }
event = &view->resevent; event = &view->resevent;
dns_resolver_whenshutdown(view->resolver, view->task, &event); dns_resolver_whenshutdown(view->resolver, view->task, &event);
view->attributes &= ~DNS_VIEWATTR_RESSHUTDOWN; atomic_fetch_and(&view->attributes, ~DNS_VIEWATTR_RESSHUTDOWN);
isc_refcount_increment(&view->weakrefs); isc_refcount_increment(&view->weakrefs);
isc_mem_create(&mctx); isc_mem_create(&mctx);
@@ -789,7 +784,7 @@ dns_view_createresolver(dns_view_t *view,
} }
event = &view->adbevent; event = &view->adbevent;
dns_adb_whenshutdown(view->adb, view->task, &event); dns_adb_whenshutdown(view->adb, view->task, &event);
view->attributes &= ~DNS_VIEWATTR_ADBSHUTDOWN; atomic_fetch_and(&view->attributes, ~DNS_VIEWATTR_ADBSHUTDOWN);
isc_refcount_increment(&view->weakrefs); isc_refcount_increment(&view->weakrefs);
result = dns_requestmgr_create(view->mctx, timermgr, socketmgr, result = dns_requestmgr_create(view->mctx, timermgr, socketmgr,
@@ -804,7 +799,7 @@ dns_view_createresolver(dns_view_t *view,
} }
event = &view->reqevent; event = &view->reqevent;
dns_requestmgr_whenshutdown(view->requestmgr, view->task, &event); dns_requestmgr_whenshutdown(view->requestmgr, view->task, &event);
view->attributes &= ~DNS_VIEWATTR_REQSHUTDOWN; atomic_fetch_and(&view->attributes, ~DNS_VIEWATTR_REQSHUTDOWN);
isc_refcount_increment(&view->weakrefs); isc_refcount_increment(&view->weakrefs);
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);