Use acquire/release semantics as appropriate

This commit is contained in:
Ondřej Surý
2019-05-13 12:12:42 +07:00
parent c820513491
commit a0ace46001
5 changed files with 32 additions and 30 deletions
+3 -1
View File
@@ -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,
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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);
+12 -12
View File
@@ -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
+13 -13
View File
@@ -21,27 +21,27 @@
void
isc_quota_init(isc_quota_t *quota, unsigned int max) {
atomic_store(&quota->max, max);
atomic_store(&quota->used, 0);
atomic_init(&quota->max, max);
atomic_init(&quota->used, 0);
atomic_store(&quota->soft, 0);
}
void
isc_quota_destroy(isc_quota_t *quota) {
INSIST(atomic_load(&quota->used) == 0);
atomic_store(&quota->max, 0);
atomic_store(&quota->used, 0);
atomic_store(&quota->soft, 0);
atomic_store_release(&quota->max, 0);
atomic_store_release(&quota->used, 0);
atomic_store_release(&quota->soft, 0);
}
void
isc_quota_soft(isc_quota_t *quota, unsigned int soft) {
atomic_store(&quota->soft, soft);
atomic_store_release(&quota->soft, soft);
}
void
isc_quota_max(isc_quota_t *quota, unsigned int max) {
atomic_store(&quota->max, max);
atomic_store_release(&quota->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(&quota->max);
uint32_t soft = atomic_load(&quota->soft);
uint32_t used = atomic_fetch_add(&quota->used, 1);
uint32_t max = atomic_load_acquire(&quota->max);
uint32_t soft = atomic_load_acquire(&quota->soft);
uint32_t used = atomic_fetch_add_relaxed(&quota->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(&quota->used, 1) > 0);
INSIST(atomic_fetch_sub_release(&quota->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(&quota->used, 1) > 0);
INSIST(atomic_fetch_sub_release(&quota->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(&quota->used, 1);
atomic_fetch_add_relaxed(&quota->used, 1);
*p = quota;
result = ISC_R_SUCCESS;
}