Commit 5309987d authored by Ondřej Surý's avatar Ondřej Surý

Merge branch '1119-tsan-lib/dns/view.c-attributes' into 'master'

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

See merge request !2368
parents 38270b79 db63c2a7
Pipeline #22951 passed with stages
in 1 minute and 55 seconds
......@@ -196,9 +196,8 @@ struct dns_view {
/* Locked by themselves. */
isc_refcount_t references;
isc_refcount_t weakrefs;
atomic_uint_fast32_t attributes;
/* Locked by lock. */
unsigned int attributes;
/* Under owner's locking control. */
ISC_LINK(struct dns_view) link;
dns_viewlist_t * viewlist;
......
......@@ -19,6 +19,7 @@
#include <lmdb.h>
#endif
#include <isc/atomic.h>
#include <isc/file.h>
#include <isc/hash.h>
#include <isc/lex.h>
......@@ -64,9 +65,9 @@
if (result != ISC_R_SUCCESS) goto cleanup; \
} while (0)
#define RESSHUTDOWN(v) (((v)->attributes & DNS_VIEWATTR_RESSHUTDOWN) != 0)
#define ADBSHUTDOWN(v) (((v)->attributes & DNS_VIEWATTR_ADBSHUTDOWN) != 0)
#define REQSHUTDOWN(v) (((v)->attributes & DNS_VIEWATTR_REQSHUTDOWN) != 0)
#define RESSHUTDOWN(v) ((atomic_load(&(v)->attributes) & DNS_VIEWATTR_RESSHUTDOWN) != 0)
#define ADBSHUTDOWN(v) ((atomic_load(&(v)->attributes) & DNS_VIEWATTR_ADBSHUTDOWN) != 0)
#define REQSHUTDOWN(v) ((atomic_load(&(v)->attributes) & DNS_VIEWATTR_REQSHUTDOWN) != 0)
#define DNS_VIEW_DELONLYHASH 111
#define DNS_VIEW_FAILCACHESIZE 1021
......@@ -140,8 +141,9 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
view->task = NULL;
isc_refcount_init(&view->references, 1);
isc_refcount_init(&view->weakrefs, 1);
view->attributes = (DNS_VIEWATTR_RESSHUTDOWN|DNS_VIEWATTR_ADBSHUTDOWN|
DNS_VIEWATTR_REQSHUTDOWN);
atomic_init(&view->attributes, (DNS_VIEWATTR_RESSHUTDOWN |
DNS_VIEWATTR_ADBSHUTDOWN |
DNS_VIEWATTR_REQSHUTDOWN));
view->statickeys = NULL;
view->dynamickeys = NULL;
view->matchclients = NULL;
......@@ -685,10 +687,7 @@ resolver_shutdown(isc_task_t *task, isc_event_t *event) {
isc_event_free(&event);
LOCK(&view->lock);
view->attributes |= DNS_VIEWATTR_RESSHUTDOWN;
UNLOCK(&view->lock);
atomic_fetch_or(&view->attributes, DNS_VIEWATTR_RESSHUTDOWN);
dns_view_weakdetach(&view);
}
......@@ -704,9 +703,7 @@ adb_shutdown(isc_task_t *task, isc_event_t *event) {
isc_event_free(&event);
LOCK(&view->lock);
view->attributes |= DNS_VIEWATTR_ADBSHUTDOWN;
UNLOCK(&view->lock);
atomic_fetch_or(&view->attributes, DNS_VIEWATTR_ADBSHUTDOWN);
dns_view_weakdetach(&view);
}
......@@ -723,9 +720,7 @@ req_shutdown(isc_task_t *task, isc_event_t *event) {
isc_event_free(&event);
LOCK(&view->lock);
view->attributes |= DNS_VIEWATTR_REQSHUTDOWN;
UNLOCK(&view->lock);
atomic_fetch_or(&view->attributes, DNS_VIEWATTR_REQSHUTDOWN);
dns_view_weakdetach(&view);
}
......@@ -775,7 +770,7 @@ dns_view_createresolver(dns_view_t *view,
}
event = &view->resevent;
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_mem_create(&mctx);
......@@ -789,7 +784,7 @@ dns_view_createresolver(dns_view_t *view,
}
event = &view->adbevent;
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);
result = dns_requestmgr_create(view->mctx, timermgr, socketmgr,
......@@ -804,7 +799,7 @@ dns_view_createresolver(dns_view_t *view,
}
event = &view->reqevent;
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);
return (ISC_R_SUCCESS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment