diff --git a/lib/dns/cache.c b/lib/dns/cache.c index 584fcd4859..c8c0cdc1b4 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -1119,7 +1119,9 @@ cleaner_shutdown_action(isc_task_t *task, isc_event_t *event) { cache->live_tasks--; INSIST(cache->live_tasks == 0); - should_free = (isc_refcount_current(&cache->references) == 0); + if (isc_refcount_current(&cache->references) == 0) { + should_free = true; + } /* * By detaching the timer in the context of its task, diff --git a/lib/dns/master.c b/lib/dns/master.c index cb13122ddc..3a38873c95 100644 --- a/lib/dns/master.c +++ b/lib/dns/master.c @@ -3093,7 +3093,7 @@ load_quantum(isc_task_t *task, isc_event_t *event) { lctx = event->ev_arg; REQUIRE(DNS_LCTX_VALID(lctx)); - if (atomic_load(&lctx->canceled)) { + if (atomic_load_acquire(&lctx->canceled)) { result = ISC_R_CANCELED; } else { result = (lctx->load)(lctx); @@ -3125,7 +3125,7 @@ void dns_loadctx_cancel(dns_loadctx_t *lctx) { REQUIRE(DNS_LCTX_VALID(lctx)); - atomic_store(&lctx->canceled, true); + atomic_store_release(&lctx->canceled, true); } void diff --git a/lib/dns/masterdump.c b/lib/dns/masterdump.c index d4df7b6cb1..4177adff75 100644 --- a/lib/dns/masterdump.c +++ b/lib/dns/masterdump.c @@ -1329,7 +1329,7 @@ void dns_dumpctx_cancel(dns_dumpctx_t *dctx) { REQUIRE(DNS_DCTX_VALID(dctx)); - atomic_store(&dctx->canceled, true); + atomic_store_release(&dctx->canceled, true); } static isc_result_t @@ -1411,7 +1411,7 @@ dump_quantum(isc_task_t *task, isc_event_t *event) { REQUIRE(event != NULL); dctx = event->ev_arg; REQUIRE(DNS_DCTX_VALID(dctx)); - if (atomic_load(&dctx->canceled)) { + if (atomic_load_acquire(&dctx->canceled)) { result = ISC_R_CANCELED; } else { result = dumptostreaminc(dctx); diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 669197f855..f053727922 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -1642,7 +1642,7 @@ fctx_sendevents(fetchctx_t *fctx, isc_result_t result, int line) { (count < fctx->res->spillatmax || fctx->res->spillatmax == 0)) { LOCK(&fctx->res->lock); if (count == fctx->res->spillat && - !atomic_load(&fctx->res->exiting)) { + !atomic_load_acquire(&fctx->res->exiting)) { old_spillat = fctx->res->spillat; fctx->res->spillat += 5; if (fctx->res->spillat > fctx->res->spillatmax && @@ -4279,7 +4279,7 @@ fctx_unlink(fetchctx_t *fctx) { dec_stats(res, dns_resstatscounter_nfetch); - if (atomic_load(&res->buckets[bucketnum].exiting) && + if (atomic_load_acquire(&res->buckets[bucketnum].exiting) && ISC_LIST_EMPTY(res->buckets[bucketnum].fctxs)) { return (true); @@ -7341,7 +7341,7 @@ resquery_response(isc_task_t *task, isc_event_t *event) { rctx_respinit(task, devent, query, fctx, &rctx); - if (atomic_load(&fctx->res->exiting)) { + if (atomic_load_acquire(&fctx->res->exiting)) { result = ISC_R_SHUTTINGDOWN; FCTXTRACE("resolver shutting down"); rctx_done(&rctx, result); @@ -9882,7 +9882,7 @@ spillattimer_countdown(isc_task_t *task, isc_event_t *event) { UNUSED(task); LOCK(&res->lock); - INSIST(!atomic_load(&res->exiting)); + INSIST(!atomic_load_acquire(&res->exiting)); if (res->spillat > res->spillatmin) { res->spillat--; logit = true; @@ -10010,7 +10010,7 @@ dns_resolver_create(dns_view_t *view, isc_mem_setname(res->buckets[i].mctx, name, NULL); isc_task_setname(res->buckets[i].task, name, res); ISC_LIST_INIT(res->buckets[i].fctxs); - atomic_store(&res->buckets[i].exiting, false); + atomic_store_release(&res->buckets[i].exiting, false); buckets_created++; } @@ -10201,7 +10201,7 @@ dns_resolver_prime(dns_resolver_t *res) { LOCK(&res->lock); /* XXXOND: cas needs to be used here */ - if (!atomic_load(&res->exiting) && !res->priming) { + if (!atomic_load_acquire(&res->exiting) && !res->priming) { INSIST(res->primefetch == NULL); res->priming = true; want_priming = true; @@ -10268,11 +10268,11 @@ dns_resolver_attach(dns_resolver_t *source, dns_resolver_t **targetp) { RRTRACE(source, "attach"); - /* XXXOND: There's possibly a race between exiting and references? */ - - REQUIRE(!atomic_load(&source->exiting)); + LOCK(&res->lock); + REQUIRE(!atomic_load_acquire(&source->exiting)); isc_refcount_increment(&source->references); + UNLOCK(&res->lock); *targetp = source; } @@ -10292,7 +10292,7 @@ dns_resolver_whenshutdown(dns_resolver_t *res, isc_task_t *task, LOCK(&res->lock); - if (atomic_load(&res->exiting) && res->activebuckets == 0) { + if (atomic_load_acquire(&res->exiting) && res->activebuckets == 0) { /* * We're already shutdown. Send the event. */ @@ -10365,10 +10365,10 @@ dns_resolver_detach(dns_resolver_t **resp) { *resp = NULL; if (isc_refcount_decrement(&res->references) == 1) { - INSIST(atomic_load(&res->exiting) && res->activebuckets == 0); + INSIST(atomic_load_acquire(&res->exiting)); + INSIST(res->activebuckets == 0); destroy(res); } - } static inline bool diff --git a/lib/isc/quota.c b/lib/isc/quota.c index 4ce36ddf82..fc7871220d 100644 --- a/lib/isc/quota.c +++ b/lib/isc/quota.c @@ -21,27 +21,27 @@ void isc_quota_init(isc_quota_t *quota, unsigned int max) { - atomic_store("a->max, max); - atomic_store("a->used, 0); + atomic_init("a->max, max); + atomic_init("a->used, 0); atomic_store("a->soft, 0); } void isc_quota_destroy(isc_quota_t *quota) { INSIST(atomic_load("a->used) == 0); - atomic_store("a->max, 0); - atomic_store("a->used, 0); - atomic_store("a->soft, 0); + atomic_store_release("a->max, 0); + atomic_store_release("a->used, 0); + atomic_store_release("a->soft, 0); } void isc_quota_soft(isc_quota_t *quota, unsigned int soft) { - atomic_store("a->soft, soft); + atomic_store_release("a->soft, soft); } void isc_quota_max(isc_quota_t *quota, unsigned int max) { - atomic_store("a->max, max); + atomic_store_release("a->max, max); } unsigned int @@ -62,9 +62,9 @@ isc_quota_getused(isc_quota_t *quota) { isc_result_t isc_quota_reserve(isc_quota_t *quota) { isc_result_t result; - uint32_t max = atomic_load("a->max); - uint32_t soft = atomic_load("a->soft); - uint32_t used = atomic_fetch_add("a->used, 1); + uint32_t max = atomic_load_acquire("a->max); + uint32_t soft = atomic_load_acquire("a->soft); + uint32_t used = atomic_fetch_add_relaxed("a->used, 1); if (max == 0 || used < max) { if (soft == 0 || used < soft) { result = ISC_R_SUCCESS; @@ -72,7 +72,7 @@ isc_quota_reserve(isc_quota_t *quota) { result = ISC_R_SOFTQUOTA; } } else { - INSIST(atomic_fetch_sub("a->used, 1) > 0); + INSIST(atomic_fetch_sub_release("a->used, 1) > 0); result = ISC_R_QUOTA; } return (result); @@ -80,7 +80,7 @@ isc_quota_reserve(isc_quota_t *quota) { void isc_quota_release(isc_quota_t *quota) { - INSIST(atomic_fetch_sub("a->used, 1) > 0); + INSIST(atomic_fetch_sub_release("a->used, 1) > 0); } static isc_result_t @@ -93,7 +93,7 @@ doattach(isc_quota_t *quota, isc_quota_t **p, bool force) { *p = quota; } else if (result == ISC_R_QUOTA && force) { /* attach anyway */ - atomic_fetch_add("a->used, 1); + atomic_fetch_add_relaxed("a->used, 1); *p = quota; result = ISC_R_SUCCESS; }