isc_stats_t *stats;
- isc_event_t cevent;
- bool cevent_out;
atomic_bool exiting;
- isc_eventlist_t whenshutdown;
uint32_t quota;
uint32_t atr_freq;
ev->ev_destroy = event_freefind;
ev->ev_destroy_arg = find;
- DP(DEF_LEVEL, "sending event %p to task %p for find %p",
+ DP(DEF_LEVEL,
+ "cfan: sending event %p "
+ "to task %p for find %p",
ev, task, find);
isc_task_sendanddetach(&task, (isc_event_t **)&ev);
adb->magic = 0;
- isc_task_detach(&adb->task);
-
+ RWLOCK(&adb->names_lock, isc_rwlocktype_write);
isc_ht_iter_create(adb->namebuckets, &it);
for (result = isc_ht_iter_first(it); result == ISC_R_SUCCESS;
result = isc_ht_iter_delcurrent_next(it))
}
isc_ht_iter_destroy(&it);
isc_ht_destroy(&adb->namebuckets);
+ RWUNLOCK(&adb->names_lock, isc_rwlocktype_write);
+ isc_rwlock_destroy(&adb->names_lock);
+ RWLOCK(&adb->entries_lock, isc_rwlocktype_write);
isc_ht_iter_create(adb->entrybuckets, &it);
for (result = isc_ht_iter_first(it); result == ISC_R_SUCCESS;
result = isc_ht_iter_delcurrent_next(it))
}
isc_ht_iter_destroy(&it);
isc_ht_destroy(&adb->entrybuckets);
-
- isc_rwlock_destroy(&adb->names_lock);
+ RWUNLOCK(&adb->entries_lock, isc_rwlocktype_write);
isc_rwlock_destroy(&adb->entries_lock);
+
isc_mutex_destroy(&adb->lock);
+ isc_task_detach(&adb->task);
isc_stats_detach(&adb->stats);
+ dns_view_weakdetach(&adb->view);
isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t));
}
adb = isc_mem_get(mem, sizeof(dns_adb_t));
*adb = (dns_adb_t){
- .view = view,
.taskmgr = taskmgr,
};
* that must be NULL for the error return to work properly.
*/
isc_refcount_init(&adb->references, 1);
- ISC_EVENT_INIT(&adb->cevent, sizeof(adb->cevent), 0, NULL, 0, NULL,
- NULL, NULL, NULL, NULL);
- ISC_LIST_INIT(adb->whenshutdown);
- atomic_init(&adb->exiting, false);
-
+ dns_view_weakattach(view, &adb->view);
isc_mem_attach(mem, &adb->mctx);
isc_ht_init(&adb->namebuckets, adb->mctx, 1, ISC_HT_CASE_INSENSITIVE);
isc_rwlock_destroy(&adb->names_lock);
isc_ht_destroy(&adb->namebuckets);
+ dns_view_weakdetach(&adb->view);
isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t));
return (result);
}
}
-void
-dns_adb_whenshutdown(dns_adb_t *adb, isc_task_t *task, isc_event_t **eventp) {
- isc_event_t *event = NULL;
-
- /*
- * Send '*eventp' to 'task' when 'adb' has shutdown.
- */
-
- REQUIRE(DNS_ADB_VALID(adb));
- REQUIRE(eventp != NULL);
-
- event = *eventp;
- *eventp = NULL;
-
- if (atomic_load(&adb->exiting)) {
- /*
- * We're already shutdown. Send the event.
- */
- event->ev_sender = adb;
- isc_task_send(task, &event);
- } else {
- LOCK(&adb->lock);
- isc_task_attach(task, &(isc_task_t *){ NULL });
- event->ev_sender = task;
- ISC_LIST_APPEND(adb->whenshutdown, event, ev_link);
- UNLOCK(&adb->lock);
- }
-}
-
void
dns_adb_shutdown(dns_adb_t *adb) {
- isc_event_t *event = NULL;
-
if (!atomic_compare_exchange_strong(&adb->exiting, &(bool){ false },
true)) {
return;
shutdown_names(adb);
shutdown_entries(adb);
-
- LOCK(&adb->lock);
- for (event = ISC_LIST_HEAD(adb->whenshutdown); event != NULL;
- event = ISC_LIST_HEAD(adb->whenshutdown))
- {
- isc_task_t *task = event->ev_sender;
- event->ev_sender = adb;
- ISC_LIST_UNLINK(adb->whenshutdown, event, ev_link);
- isc_task_sendanddetach(&task, &event);
- }
- UNLOCK(&adb->lock);
}
/*
name = ev->ev_arg;
REQUIRE(DNS_ADBNAME_VALID(name));
- adb = name->adb;
+ dns_adb_attach(name->adb, &adb);
REQUIRE(DNS_ADB_VALID(adb));
INSIST(address_type != 0 && fetch != NULL);
- dns_resolver_destroyfetch(&fetch->fetch);
- dev->fetch = NULL;
-
ev_status = DNS_EVENT_ADBNOMOREADDRESSES;
/*
* potentially good data.
*/
if (NAME_DEAD(name)) {
- free_adbfetch(adb, &fetch);
- isc_event_free(&ev);
- expire_name(&name, DNS_EVENT_ADBCANCELED);
- UNLOCK(&nbucket->lock);
- return;
+ ev_status = DNS_EVENT_ADBCANCELED;
+ goto out;
}
isc_stdtime_get(&now);
}
out:
+ dns_resolver_destroyfetch(&fetch->fetch);
free_adbfetch(adb, &fetch);
isc_event_free(&ev);
-
- clean_finds_at_name(name, ev_status, address_type);
-
+ if (ev_status == DNS_EVENT_ADBCANCELED) {
+ expire_name(&name, ev_status);
+ } else {
+ clean_finds_at_name(name, ev_status, address_type);
+ }
UNLOCK(&nbucket->lock);
+ dns_adb_detach(&adb);
}
static isc_result_t
static void
resolver_shutdown(isc_task_t *task, isc_event_t *event);
static void
-adb_shutdown(isc_task_t *task, isc_event_t *event);
-static void
req_shutdown(isc_task_t *task, isc_event_t *event);
isc_result_t
ISC_EVENT_INIT(&view->resevent, sizeof(view->resevent), 0, NULL,
DNS_EVENT_VIEWRESSHUTDOWN, resolver_shutdown, view, NULL,
NULL, NULL);
- ISC_EVENT_INIT(&view->adbevent, sizeof(view->adbevent), 0, NULL,
- DNS_EVENT_VIEWADBSHUTDOWN, adb_shutdown, view, NULL,
- NULL, NULL);
ISC_EVENT_INIT(&view->reqevent, sizeof(view->reqevent), 0, NULL,
DNS_EVENT_VIEWREQSHUTDOWN, req_shutdown, view, NULL,
NULL, NULL);
}
if (view->adb != NULL) {
dns_adb_shutdown(view->adb);
+ dns_adb_detach(&view->adb);
}
if (view->requestmgr != NULL) {
dns_requestmgr_shutdown(view->requestmgr);
dns_view_weakdetach(&view);
}
-static void
-adb_shutdown(isc_task_t *task, isc_event_t *event) {
- dns_view_t *view = event->ev_arg;
-
- REQUIRE(event->ev_type == DNS_EVENT_VIEWADBSHUTDOWN);
- REQUIRE(DNS_VIEW_VALID(view));
- REQUIRE(view->task == task);
-
- UNUSED(task);
-
- isc_event_free(&event);
-
- dns_view_weakdetach(&view);
-}
-
static void
req_shutdown(isc_task_t *task, isc_event_t *event) {
dns_view_t *view = event->ev_arg;
isc_task_detach(&view->task);
return (result);
}
+
+ dns_view_weakattach(view, &(dns_view_t *){ NULL });
event = &view->resevent;
dns_resolver_whenshutdown(view->resolver, view->task, &event);
- isc_refcount_increment(&view->weakrefs);
isc_mem_create(&mctx);
isc_mem_setname(mctx, "ADB");
-
result = dns_adb_create(mctx, view, taskmgr, &view->adb);
isc_mem_detach(&mctx);
if (result != ISC_R_SUCCESS) {
dns_resolver_shutdown(view->resolver);
return (result);
}
- event = &view->adbevent;
- dns_adb_whenshutdown(view->adb, view->task, &event);
- isc_refcount_increment(&view->weakrefs);
result = dns_requestmgr_create(
view->mctx, dns_resolver_taskmgr(view->resolver),
dispatchv6, &view->requestmgr);
if (result != ISC_R_SUCCESS) {
dns_adb_shutdown(view->adb);
+ dns_adb_detach(&view->adb);
dns_resolver_shutdown(view->resolver);
return (result);
}
+
+ dns_view_weakattach(view, &(dns_view_t *){ NULL });
event = &view->reqevent;
dns_requestmgr_whenshutdown(view->requestmgr, view->task, &event);
- isc_refcount_increment(&view->weakrefs);
return (ISC_R_SUCCESS);
}